Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions js/perf/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,10 @@ function createDataFrameDirectCountTest(table, column, test, value) {
let numBatches = batches.length;
for (let batchIndex = -1; ++batchIndex < numBatches;) {
// load batches
const { numRows, columns } = batches[batchIndex];
const vector = columns[colidx];
const batch = batches[batchIndex];
const vector = batch.getChildAt(colidx);
// yield all indices
for (let index = -1; ++index < numRows;) {
for (let index = -1; ++index < batch.length;) {
sum += (vector.get(index) >= value);
}
}
Expand All @@ -159,10 +159,10 @@ function createDataFrameDirectCountTest(table, column, test, value) {
let numBatches = batches.length;
for (let batchIndex = -1; ++batchIndex < numBatches;) {
// load batches
const { numRows, columns } = batches[batchIndex];
const vector = columns[colidx];
const batch = batches[batchIndex];
const vector = batch.getChildAt(colidx);
// yield all indices
for (let index = -1; ++index < numRows;) {
for (let index = -1; ++index < batch.length;) {
sum += (vector.get(index) === value);
}
}
Expand All @@ -173,7 +173,7 @@ function createDataFrameDirectCountTest(table, column, test, value) {

return {
async: true,
name: `name: '${column}', length: ${table.numRows}, type: ${table.columns[colidx].type}, test: ${test}, value: ${value}\n`,
name: `name: '${column}', length: ${table.numRows}, type: ${table.getColumnAt(colidx).type}, test: ${test}, value: ${value}\n`,
fn: op
};
}
Expand All @@ -183,7 +183,7 @@ function createDataFrameCountByTest(table, column) {

return {
async: true,
name: `name: '${column}', length: ${table.numRows}, type: ${table.columns[colidx].type}\n`,
name: `name: '${column}', length: ${table.numRows}, type: ${table.getColumnAt(colidx).type}\n`,
fn() {
table.countBy(column);
}
Expand All @@ -204,7 +204,7 @@ function createDataFrameFilterCountTest(table, column, test, value) {

return {
async: true,
name: `name: '${column}', length: ${table.numRows}, type: ${table.columns[colidx].type}, test: ${test}, value: ${value}\n`,
name: `name: '${column}', length: ${table.numRows}, type: ${table.getColumnAt(colidx).type}, test: ${test}, value: ${value}\n`,
fn() {
df.count();
}
Expand Down
10 changes: 9 additions & 1 deletion js/src/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import { Col, Predicate } from './predicate';
import { Schema, Field, Struct } from './type';
import { read, readAsync } from './ipc/reader/arrow';
import { isPromise, isAsyncIterable } from './util/compat';
import { Vector, DictionaryVector, IntVector } from './vector';
import { Vector, DictionaryVector, IntVector, StructVector } from './vector';
import { ChunkedView } from './vector/chunked';

export type NextFunc = (idx: number, cols: RecordBatch) => void;

Expand Down Expand Up @@ -61,6 +62,13 @@ export class Table implements DataFrame {
}
return Table.empty();
}
static fromStruct(struct: StructVector) {
const schema = new Schema(struct.type.children);
const chunks = struct.view instanceof ChunkedView ?
(struct.view.childVectors as StructVector[]) :
[struct];
return new Table(chunks.map((chunk)=>new RecordBatch(schema, chunk.length, chunk.view.childData)));
}

public readonly schema: Schema;
public readonly length: number;
Expand Down