Skip to content

Commit c509bb2

Browse files
roelentlessjheer
authored andcommitted
Fix bug in IPC stream decoding when an empty batch is part of the stream
1 parent add15cd commit c509bb2

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

src/decode/message.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ export function decodeMessage(buf, index) {
7575
}
7676
// @ts-ignore
7777
content.body = body;
78+
} else if (type !== MessageHeader.Schema) {
79+
// table-from-ipc.js buffer accessor requires body to exist, even for empty batches
80+
// @ts-ignore
81+
content.body = new Uint8Array(0);
7882
}
7983
}
8084

test/data/file-with-3-batches.bin

1.51 KB
Binary file not shown.

test/empty-batch-test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { readFileSync } from 'node:fs';
2+
import { tableFromIPC } from '../src/index.js';
3+
import assert from 'node:assert';
4+
5+
describe('Empty batch handling', () => {
6+
it('should decode IPC stream with empty RecordBatch', () => {
7+
const data = readFileSync('test/data/file-with-3-batches.bin');
8+
const table = tableFromIPC(data);
9+
10+
assert.strictEqual(table.numRows, 5, 'Expected 5 total rows (3 + 0 + 2)');
11+
assert.strictEqual(table.numCols, 2, 'Expected 2 columns');
12+
});
13+
});
14+

0 commit comments

Comments
 (0)