Skip to content

Commit

Permalink
Merge pull request #3 from ccri/table-from-struct
Browse files Browse the repository at this point in the history
Table from struct
  • Loading branch information
trxcllnt committed Jan 25, 2018
2 parents 54d4f5b + c8cd286 commit a5f200f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
18 changes: 9 additions & 9 deletions js/perf/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -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);
}
}
Expand All @@ -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
};
}
Expand All @@ -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);
}
Expand All @@ -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();
}
Expand Down
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 a5f200f

Please sign in to comment.