1616// under the License.
1717
1818import '../../../jest-extensions.js' ;
19- import { readFileSync } from 'node:fs' ;
20- import path from 'node:path' ;
2119import {
2220 makeData ,
2321 RecordBatch ,
@@ -27,14 +25,28 @@ import {
2725 tableFromIPC ,
2826} from 'apache-arrow' ;
2927
30- const testDataDir = path . resolve ( process . cwd ( ) , 'test/data' ) ;
28+ /** Helper to create a zero-column IPC stream buffer with the given number of rows. */
29+ function createZeroColumnIPCBuffer ( numRows : number ) : Uint8Array {
30+ const schema = new Schema ( [ ] ) ;
31+ const data = makeData ( {
32+ type : new Struct ( [ ] ) ,
33+ length : numRows ,
34+ nullCount : 0 ,
35+ children : [ ] ,
36+ } ) ;
37+ const batch = new RecordBatch ( schema , data ) ;
38+ const writer = new RecordBatchStreamWriter ( ) ;
39+ writer . write ( batch ) ;
40+ writer . finish ( ) ;
41+ return writer . toUint8Array ( true ) ;
42+ }
3143
3244describe ( 'Zero-column RecordBatch numRows preservation' , ( ) => {
3345
34- describe ( 'PyArrow interop ' , ( ) => {
46+ describe ( 'IPC round-trip ' , ( ) => {
3547
36- test ( 'should read PyArrow zero-column stream and preserve numRows' , ( ) => {
37- const buffer = readFileSync ( path . resolve ( testDataDir , 'zero_column_batch.arrow' ) ) ;
48+ test ( 'should read zero-column stream and preserve numRows' , ( ) => {
49+ const buffer = createZeroColumnIPCBuffer ( 100 ) ;
3850 const table = tableFromIPC ( buffer ) ;
3951
4052 expect ( table . numRows ) . toBe ( 100 ) ;
@@ -44,33 +56,6 @@ describe('Zero-column RecordBatch numRows preservation', () => {
4456 } ) ;
4557 } ) ;
4658
47- describe ( 'JS round-trip' , ( ) => {
48-
49- test ( 'zero-column batch should round-trip through IPC stream writer' , ( ) => {
50- const schema = new Schema ( [ ] ) ;
51- const data = makeData ( {
52- type : new Struct ( [ ] ) ,
53- length : 100 ,
54- nullCount : 0 ,
55- children : [ ] ,
56- } ) ;
57- const batch = new RecordBatch ( schema , data ) ;
58- expect ( batch . numRows ) . toBe ( 100 ) ;
59- expect ( batch . numCols ) . toBe ( 0 ) ;
60-
61- const writer = new RecordBatchStreamWriter ( ) ;
62- writer . write ( batch ) ;
63- writer . finish ( ) ;
64- const buffer = writer . toUint8Array ( true ) ;
65-
66- const table = tableFromIPC ( buffer ) ;
67- expect ( table . numRows ) . toBe ( 100 ) ;
68- expect ( table . numCols ) . toBe ( 0 ) ;
69- expect ( table . batches ) . toHaveLength ( 1 ) ;
70- expect ( table . batches [ 0 ] . numRows ) . toBe ( 100 ) ;
71- } ) ;
72- } ) ;
73-
7459 describe ( 'Direct constructor' , ( ) => {
7560
7661 test ( 'RecordBatch constructor preserves length for zero-column data' , ( ) => {
0 commit comments