@@ -55,7 +55,7 @@ const jsonAndArrowPaths = toArray(zip(
5555. filter ( ( [ p1 , p2 ] ) => p1 !== undefined && p2 !== undefined ) as [ string , string ] [ ] ;
5656
5757expect . extend ( {
58- toEqualVector ( v1 : any , v2 : any ) {
58+ toEqualVector ( [ v1 , format1 , columnName ] : [ any , string , string ] , [ v2 , format2 ] : [ any , string ] ) {
5959
6060 const format = ( x : any , y : any , msg = ' ' ) => `${
6161 this . utils . printExpected ( x ) } ${
@@ -102,7 +102,7 @@ expect.extend({
102102 return {
103103 pass : allFailures . every ( ( { failures } ) => failures . length === 0 ) ,
104104 message : ( ) => [
105- `${ v1 . name } : (${ format ( 'json' , 'arrow' , ' !== ' ) } )\n` ,
105+ `${ columnName } : (${ format ( format1 , format2 , ' !== ' ) } )\n` ,
106106 ...allFailures . map ( ( { failures, title } ) =>
107107 ! failures . length ? `` : [ `${ title } :` , ...failures ] . join ( `\n` ) )
108108 ] . join ( '\n' )
@@ -119,8 +119,10 @@ describe(`Integration`, () => {
119119 describe ( path . join ( dir , name ) , ( ) => {
120120 testReaderIntegration ( json , arrowBuffer ) ;
121121 testTableFromBuffersIntegration ( json , arrowBuffer ) ;
122- testTableToBuffersIntegration ( 'file' ) ( json , arrowBuffer ) ;
123- testTableToBuffersIntegration ( 'stream' ) ( json , arrowBuffer ) ;
122+ testTableToBuffersIntegration ( 'json' , 'file' ) ( json , arrowBuffer ) ;
123+ testTableToBuffersIntegration ( 'json' , 'stream' ) ( json , arrowBuffer ) ;
124+ testTableToBuffersIntegration ( 'binary' , 'file' ) ( json , arrowBuffer ) ;
125+ testTableToBuffersIntegration ( 'binary' , 'stream' ) ( json , arrowBuffer ) ;
124126 } ) ;
125127 }
126128} ) ;
@@ -134,8 +136,11 @@ function testReaderIntegration(jsonData: any, arrowBuffer: Uint8Array) {
134136 expect ( jsonRecordBatch . length ) . toEqual ( binaryRecordBatch . length ) ;
135137 expect ( jsonRecordBatch . numCols ) . toEqual ( binaryRecordBatch . numCols ) ;
136138 for ( let i = - 1 , n = jsonRecordBatch . numCols ; ++ i < n ; ) {
137- ( jsonRecordBatch . getChildAt ( i ) as any ) . name = jsonRecordBatch . schema . fields [ i ] . name ;
138- ( expect ( jsonRecordBatch . getChildAt ( i ) ) as any ) . toEqualVector ( binaryRecordBatch . getChildAt ( i ) ) ;
139+ const v1 = jsonRecordBatch . getChildAt ( i ) ;
140+ const v2 = binaryRecordBatch . getChildAt ( i ) ;
141+ const name = jsonRecordBatch . schema . fields [ i ] . name ;
142+ ( expect ( [ v1 , `json` , name ] ) as any )
143+ . toEqualVector ( [ v2 , `binary` ] ) ;
139144 }
140145 }
141146 } ) ;
@@ -149,25 +154,31 @@ function testTableFromBuffersIntegration(jsonData: any, arrowBuffer: Uint8Array)
149154 expect ( jsonTable . length ) . toEqual ( binaryTable . length ) ;
150155 expect ( jsonTable . numCols ) . toEqual ( binaryTable . numCols ) ;
151156 for ( let i = - 1 , n = jsonTable . numCols ; ++ i < n ; ) {
152- ( jsonTable . getColumnAt ( i ) as any ) . name = jsonTable . schema . fields [ i ] . name ;
153- ( expect ( jsonTable . getColumnAt ( i ) ) as any ) . toEqualVector ( binaryTable . getColumnAt ( i ) ) ;
157+ const v1 = jsonTable . getColumnAt ( i ) ;
158+ const v2 = binaryTable . getColumnAt ( i ) ;
159+ const name = jsonTable . schema . fields [ i ] . name ;
160+ ( expect ( [ v1 , `json` , name ] ) as any )
161+ . toEqualVector ( [ v2 , `binary` ] ) ;
154162 }
155163 } ) ;
156164}
157165
158- function testTableToBuffersIntegration ( arrowFormat : 'stream' | 'file' ) {
166+ function testTableToBuffersIntegration ( srcFormat : 'json' | 'binary' , arrowFormat : 'stream' | 'file' ) {
159167 return function testTableToBuffersIntegration ( jsonData : any , arrowBuffer : Uint8Array ) {
160- test ( `serializing json to binary reports the same values as the original binary arrow table ` , ( ) => {
168+ test ( `serializing ${ srcFormat } to a ${ arrowFormat } reports the same values as the alternate format ` , ( ) => {
161169 expect . hasAssertions ( ) ;
162- const fromJSON = Table . from ( jsonData ) ;
163- const serialized = fromJSON . serialize ( 'binary' , arrowFormat === 'stream' ) ;
164- const jsonTable = Table . from ( serialized ) ;
165- const binaryTable = Table . from ( arrowBuffer ) ;
166- expect ( jsonTable . length ) . toEqual ( binaryTable . length ) ;
167- expect ( jsonTable . numCols ) . toEqual ( binaryTable . numCols ) ;
168- for ( let i = - 1 , n = jsonTable . numCols ; ++ i < n ; ) {
169- ( jsonTable . getColumnAt ( i ) as any ) . name = jsonTable . schema . fields [ i ] . name ;
170- ( expect ( jsonTable . getColumnAt ( i ) ) as any ) . toEqualVector ( binaryTable . getColumnAt ( i ) ) ;
170+ const refFormat = srcFormat === 'json' ? `binary` : `json` ;
171+ const refTable = Table . from ( refFormat === `json` ? jsonData : arrowBuffer ) ;
172+ const srcTable = Table . from ( srcFormat === `json` ? jsonData : arrowBuffer ) ;
173+ const dstTable = Table . from ( srcTable . serialize ( `binary` , arrowFormat === `stream` ) ) ;
174+ expect ( dstTable . length ) . toEqual ( refTable . length ) ;
175+ expect ( dstTable . numCols ) . toEqual ( refTable . numCols ) ;
176+ for ( let i = - 1 , n = dstTable . numCols ; ++ i < n ; ) {
177+ const v1 = dstTable . getColumnAt ( i ) ;
178+ const v2 = refTable . getColumnAt ( i ) ;
179+ const name = dstTable . schema . fields [ i ] . name ;
180+ ( expect ( [ v1 , srcFormat , name ] ) as any )
181+ . toEqualVector ( [ v2 , refFormat ] ) ;
171182 }
172183 } ) ;
173184 }
0 commit comments