diff --git a/js/src/table.ts b/js/src/table.ts index 1c874ee26ef82..193c947a22db7 100644 --- a/js/src/table.ts +++ b/js/src/table.ts @@ -101,7 +101,9 @@ export class Table implements DataFrame { } this.schema = schema; this.batches = batches; - this.batchesUnion = batches.reduce((union, batch) => union.concat(batch)); + this.batchesUnion = batches.length == 0 ? + new RecordBatch(schema, 0, []) : + batches.reduce((union, batch) => union.concat(batch)); this.length = this.batchesUnion.length; this.numCols = this.batchesUnion.numCols; } diff --git a/js/test/unit/table-tests.ts b/js/test/unit/table-tests.ts index cdddcd58d3c16..9b71c79f265d5 100644 --- a/js/test/unit/table-tests.ts +++ b/js/test/unit/table-tests.ts @@ -24,6 +24,10 @@ const { } = Arrow; describe(`Table`, () => { + test(`can create an empty table`, () => { + expect(Table.empty().length).toEqual(0) + }); + describe(`single record batch`, () => { const table = Table.from({ 'schema': {