diff --git a/js/perf/index.js b/js/perf/index.js index d276b7db9c236..98f6dfb4000d0 100644 --- a/js/perf/index.js +++ b/js/perf/index.js @@ -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); } } @@ -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); } } @@ -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 }; } @@ -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); } @@ -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(); } diff --git a/js/src/table.ts b/js/src/table.ts index fb324ab438b38..33899c21665b7 100644 --- a/js/src/table.ts +++ b/js/src/table.ts @@ -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; @@ -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;