Skip to content

Commit a5f200f

Browse files
authored
Merge pull request #3 from ccri/table-from-struct
Table from struct
2 parents 54d4f5b + c8cd286 commit a5f200f

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

js/perf/index.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,10 @@ function createDataFrameDirectCountTest(table, column, test, value) {
144144
let numBatches = batches.length;
145145
for (let batchIndex = -1; ++batchIndex < numBatches;) {
146146
// load batches
147-
const { numRows, columns } = batches[batchIndex];
148-
const vector = columns[colidx];
147+
const batch = batches[batchIndex];
148+
const vector = batch.getChildAt(colidx);
149149
// yield all indices
150-
for (let index = -1; ++index < numRows;) {
150+
for (let index = -1; ++index < batch.length;) {
151151
sum += (vector.get(index) >= value);
152152
}
153153
}
@@ -159,10 +159,10 @@ function createDataFrameDirectCountTest(table, column, test, value) {
159159
let numBatches = batches.length;
160160
for (let batchIndex = -1; ++batchIndex < numBatches;) {
161161
// load batches
162-
const { numRows, columns } = batches[batchIndex];
163-
const vector = columns[colidx];
162+
const batch = batches[batchIndex];
163+
const vector = batch.getChildAt(colidx);
164164
// yield all indices
165-
for (let index = -1; ++index < numRows;) {
165+
for (let index = -1; ++index < batch.length;) {
166166
sum += (vector.get(index) === value);
167167
}
168168
}
@@ -173,7 +173,7 @@ function createDataFrameDirectCountTest(table, column, test, value) {
173173

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

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

205205
return {
206206
async: true,
207-
name: `name: '${column}', length: ${table.numRows}, type: ${table.columns[colidx].type}, test: ${test}, value: ${value}\n`,
207+
name: `name: '${column}', length: ${table.numRows}, type: ${table.getColumnAt(colidx).type}, test: ${test}, value: ${value}\n`,
208208
fn() {
209209
df.count();
210210
}

js/src/table.ts

+9-1
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)