Skip to content

Commit

Permalink
Add Table.fromStruct
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Hulette committed Jan 24, 2018
1 parent a00415e commit c8cd286
Showing 1 changed file with 9 additions and 1 deletion.
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

0 comments on commit c8cd286

Please sign in to comment.