Skip to content

Commit

Permalink
Merge pull request #4 from trxcllnt/js-cpp-refactor
Browse files Browse the repository at this point in the history
fix closure es5/umd toString() iterator
  • Loading branch information
TheNeuralBit authored Jan 29, 2018
2 parents dbe7f81 + fe300df commit 16b9ccb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 21 deletions.
10 changes: 4 additions & 6 deletions js/src/Arrow.externs.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ Table.empty = function() {};
/** @type {?} */
Table.prototype.schema;
/** @type {?} */
Table.prototype.columns;
/** @type {?} */
Table.prototype.length;
/** @type {?} */
Table.prototype.numCols;
Expand All @@ -58,15 +56,13 @@ Table.prototype.select;
/** @type {?} */
Table.prototype.rowsToString;
/** @type {?} */
Table.prototype.lengths;
Table.prototype.batchesUnion;
/** @type {?} */
Table.prototype.batches;
/** @type {?} */
Table.prototype.countBy;
/** @type {?} */
Table.prototype.scan;
/** @type {?} */
Table.prototype.get;

var CountByResult = function() {};
/** @type {?} */
Expand Down Expand Up @@ -124,7 +120,7 @@ RecordBatch.from = function() {};
/** @type {?} */
RecordBatch.prototype.numCols;
/** @type {?} */
RecordBatch.prototype.numRows;
RecordBatch.prototype.length;
/** @type {?} */
RecordBatch.prototype.schema;
/** @type {?} */
Expand Down Expand Up @@ -311,6 +307,8 @@ Schema.prototype.version;
Schema.prototype.metadata;
/** @type {?} */
Schema.prototype.dictionaries;
/** @type {?} */
Schema.prototype.select;
var Field = function() {};
/** @type {?} */
Field.prototype.name;
Expand Down
12 changes: 6 additions & 6 deletions js/src/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,15 +296,15 @@ export class TableToStringIterator implements IterableIterator<string> {
pipe(stream: NodeJS.WritableStream) {
let res: IteratorResult<string>;
let write = () => {
if (stream.writable) {
if (stream['writable']) {
do {
if ((res = this.next()).done) { break; }
} while (stream.write(res.value + '\n', 'utf8'));
} while (stream['write'](res.value + '\n', 'utf8'));
}
if (!res || !res.done) {
stream.once('drain', write);
} else if (!(stream as any).isTTY) {
stream.end('\n');
stream['once']('drain', write);
} else if (!(stream as any)['isTTY']) {
stream['end']('\n');
}
};
write();
Expand All @@ -324,7 +324,7 @@ function* tableRowsToString(table: Table, separator = ' | ') {
}
}
yield header.map((x, j) => leftPad(x, ' ', maxColumnWidths[j])).join(separator);
for (let i = -1, n = table.length; ++i < n;) {
for (let i = -1; ++i < table.length;) {
yield [i, ...table.get(i)]
.map((x) => stringify(x))
.map((x, j) => leftPad(x, ' ', maxColumnWidths[j]))
Expand Down
18 changes: 9 additions & 9 deletions js/test/unit/table-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ const test_data = [
[Math.fround( 0.2), 1, 'b'],
[Math.fround( 0.1), -1, 'c'],
]}
]
];

describe(`Table`, () => {
test(`can create an empty table`, () => {
Expand Down Expand Up @@ -313,21 +313,21 @@ describe(`Table`, () => {
{
name: `filter on f32 >= 0`,
filtered: table.filter(col('f32').gteq(0)),
expected: values.filter((row)=>row[F32] >= 0)
expected: values.filter((row) => row[F32] >= 0)
}, {
name: `filter on i32 <= 0 returns the correct length`,
filtered: table.filter(col('i32').lteq(0)),
expected: values.filter((row)=>row[I32] <= 0)
expected: values.filter((row) => row[I32] <= 0)
}, {
name: `filter method combines predicates (f32 >= 0 && i32 <= 0)`,
filtered: table.filter(col('i32').lteq(0)).filter(col('f32').gteq(0)),
expected: values.filter((row)=>row[I32] <= 0 && row[F32] >= 0)
expected: values.filter((row) => row[I32] <= 0 && row[F32] >= 0)
}, {
name: `filter on dictionary == 'a'`,
filtered: table.filter(col('dictionary').eq('a')),
expected: values.filter((row)=>row[DICT] === 'a')
expected: values.filter((row) => row[DICT] === 'a')
}
]
];
for (let this_test of filter_tests) {
describe(`filter on f32 >= 0`, () => {
const filtered = this_test.filtered;
Expand All @@ -341,7 +341,7 @@ describe(`Table`, () => {
const columns = batch.schema.fields.map((_, i) => batch.getChildAt(i)!);
expect(columns.map((c) => c.get(idx))).toEqual(expected[expected_idx++]);
});
})
});
});
}
test(`countBy on dictionary returns the correct counts`, () => {
Expand All @@ -358,7 +358,7 @@ describe(`Table`, () => {
test(`countBy on dictionary with filter returns the correct counts`, () => {
let expected: {[key: string]: number} = {'a': 0, 'b': 0, 'c': 0};
for (let row of values) {
if(row[I32] === 1) { expected[row[DICT]] += 1; }
if (row[I32] === 1) { expected[row[DICT]] += 1; }
}

expect(table.filter(col('i32').eq(1)).countBy('dictionary').toJSON()).toEqual(expected);
Expand All @@ -383,7 +383,7 @@ describe(`Table`, () => {
});
test(`table.toString()`, () => {
let selected = table.select('i32', 'dictionary');
let headers = [`"row_id"`, `"i32: Int32"`, `"dictionary: Dictionary<Utf8, Int8>"`]
let headers = [`"row_id"`, `"i32: Int32"`, `"dictionary: Dictionary<Utf8, Int8>"`];
let expected = [headers.join(' | '), ...values.map((row, idx) => {
return [`${idx}`, `${row[I32]}`, `"${row[DICT]}"`].map((str, col) => {
return leftPad(str, ' ', headers[col].length);
Expand Down

0 comments on commit 16b9ccb

Please sign in to comment.