Skip to content

Commit 16b9ccb

Browse files
authored
Merge pull request #4 from trxcllnt/js-cpp-refactor
fix closure es5/umd toString() iterator
2 parents dbe7f81 + fe300df commit 16b9ccb

File tree

3 files changed

+19
-21
lines changed

3 files changed

+19
-21
lines changed

js/src/Arrow.externs.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ Table.empty = function() {};
3838
/** @type {?} */
3939
Table.prototype.schema;
4040
/** @type {?} */
41-
Table.prototype.columns;
42-
/** @type {?} */
4341
Table.prototype.length;
4442
/** @type {?} */
4543
Table.prototype.numCols;
@@ -58,15 +56,13 @@ Table.prototype.select;
5856
/** @type {?} */
5957
Table.prototype.rowsToString;
6058
/** @type {?} */
61-
Table.prototype.lengths;
59+
Table.prototype.batchesUnion;
6260
/** @type {?} */
6361
Table.prototype.batches;
6462
/** @type {?} */
6563
Table.prototype.countBy;
6664
/** @type {?} */
6765
Table.prototype.scan;
68-
/** @type {?} */
69-
Table.prototype.get;
7066

7167
var CountByResult = function() {};
7268
/** @type {?} */
@@ -124,7 +120,7 @@ RecordBatch.from = function() {};
124120
/** @type {?} */
125121
RecordBatch.prototype.numCols;
126122
/** @type {?} */
127-
RecordBatch.prototype.numRows;
123+
RecordBatch.prototype.length;
128124
/** @type {?} */
129125
RecordBatch.prototype.schema;
130126
/** @type {?} */
@@ -311,6 +307,8 @@ Schema.prototype.version;
311307
Schema.prototype.metadata;
312308
/** @type {?} */
313309
Schema.prototype.dictionaries;
310+
/** @type {?} */
311+
Schema.prototype.select;
314312
var Field = function() {};
315313
/** @type {?} */
316314
Field.prototype.name;

js/src/table.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -296,15 +296,15 @@ export class TableToStringIterator implements IterableIterator<string> {
296296
pipe(stream: NodeJS.WritableStream) {
297297
let res: IteratorResult<string>;
298298
let write = () => {
299-
if (stream.writable) {
299+
if (stream['writable']) {
300300
do {
301301
if ((res = this.next()).done) { break; }
302-
} while (stream.write(res.value + '\n', 'utf8'));
302+
} while (stream['write'](res.value + '\n', 'utf8'));
303303
}
304304
if (!res || !res.done) {
305-
stream.once('drain', write);
306-
} else if (!(stream as any).isTTY) {
307-
stream.end('\n');
305+
stream['once']('drain', write);
306+
} else if (!(stream as any)['isTTY']) {
307+
stream['end']('\n');
308308
}
309309
};
310310
write();
@@ -324,7 +324,7 @@ function* tableRowsToString(table: Table, separator = ' | ') {
324324
}
325325
}
326326
yield header.map((x, j) => leftPad(x, ' ', maxColumnWidths[j])).join(separator);
327-
for (let i = -1, n = table.length; ++i < n;) {
327+
for (let i = -1; ++i < table.length;) {
328328
yield [i, ...table.get(i)]
329329
.map((x) => stringify(x))
330330
.map((x, j) => leftPad(x, ' ', maxColumnWidths[j]))

js/test/unit/table-tests.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ const test_data = [
268268
[Math.fround( 0.2), 1, 'b'],
269269
[Math.fround( 0.1), -1, 'c'],
270270
]}
271-
]
271+
];
272272

273273
describe(`Table`, () => {
274274
test(`can create an empty table`, () => {
@@ -313,21 +313,21 @@ describe(`Table`, () => {
313313
{
314314
name: `filter on f32 >= 0`,
315315
filtered: table.filter(col('f32').gteq(0)),
316-
expected: values.filter((row)=>row[F32] >= 0)
316+
expected: values.filter((row) => row[F32] >= 0)
317317
}, {
318318
name: `filter on i32 <= 0 returns the correct length`,
319319
filtered: table.filter(col('i32').lteq(0)),
320-
expected: values.filter((row)=>row[I32] <= 0)
320+
expected: values.filter((row) => row[I32] <= 0)
321321
}, {
322322
name: `filter method combines predicates (f32 >= 0 && i32 <= 0)`,
323323
filtered: table.filter(col('i32').lteq(0)).filter(col('f32').gteq(0)),
324-
expected: values.filter((row)=>row[I32] <= 0 && row[F32] >= 0)
324+
expected: values.filter((row) => row[I32] <= 0 && row[F32] >= 0)
325325
}, {
326326
name: `filter on dictionary == 'a'`,
327327
filtered: table.filter(col('dictionary').eq('a')),
328-
expected: values.filter((row)=>row[DICT] === 'a')
328+
expected: values.filter((row) => row[DICT] === 'a')
329329
}
330-
]
330+
];
331331
for (let this_test of filter_tests) {
332332
describe(`filter on f32 >= 0`, () => {
333333
const filtered = this_test.filtered;
@@ -341,7 +341,7 @@ describe(`Table`, () => {
341341
const columns = batch.schema.fields.map((_, i) => batch.getChildAt(i)!);
342342
expect(columns.map((c) => c.get(idx))).toEqual(expected[expected_idx++]);
343343
});
344-
})
344+
});
345345
});
346346
}
347347
test(`countBy on dictionary returns the correct counts`, () => {
@@ -358,7 +358,7 @@ describe(`Table`, () => {
358358
test(`countBy on dictionary with filter returns the correct counts`, () => {
359359
let expected: {[key: string]: number} = {'a': 0, 'b': 0, 'c': 0};
360360
for (let row of values) {
361-
if(row[I32] === 1) { expected[row[DICT]] += 1; }
361+
if (row[I32] === 1) { expected[row[DICT]] += 1; }
362362
}
363363

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

0 commit comments

Comments
 (0)