Skip to content

Commit c8cd286

Browse files
author
Brian Hulette
committed
Add Table.fromStruct
1 parent a00415e commit c8cd286

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

js/src/table.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ import { Col, Predicate } from './predicate';
2020
import { Schema, Field, Struct } from './type';
2121
import { read, readAsync } from './ipc/reader/arrow';
2222
import { isPromise, isAsyncIterable } from './util/compat';
23-
import { Vector, DictionaryVector, IntVector } from './vector';
23+
import { Vector, DictionaryVector, IntVector, StructVector } from './vector';
24+
import { ChunkedView } from './vector/chunked';
2425

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

@@ -61,6 +62,13 @@ export class Table implements DataFrame {
6162
}
6263
return Table.empty();
6364
}
65+
static fromStruct(struct: StructVector) {
66+
const schema = new Schema(struct.type.children);
67+
const chunks = struct.view instanceof ChunkedView ?
68+
(struct.view.childVectors as StructVector[]) :
69+
[struct];
70+
return new Table(chunks.map((chunk)=>new RecordBatch(schema, chunk.length, chunk.view.childData)));
71+
}
6472

6573
public readonly schema: Schema;
6674
public readonly length: number;

0 commit comments

Comments
 (0)