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;