@@ -73,6 +73,39 @@ function decimal(value: string): Uint32Array {
7373
7474describe ( 'Arrow row materialization' , ( ) => {
7575 for ( const rowMode of [ 'object' , 'array' ] as const ) {
76+ it ( `avoids decimal string conversion for safe signed values (${ rowMode } )` , ( ) => {
77+ const unscaled = [ '0' , '1' , '-1' , '4294967297' , '-4294967297' , '9007199254740991' , '-9007199254740991' ] ;
78+ const columns : Column [ ] = [
79+ {
80+ field : new arrow . Field ( 'amount' , new arrow . Decimal ( 2 , 18 , 128 ) ) ,
81+ thriftType : TTypeId . DECIMAL_TYPE ,
82+ values : unscaled . map ( decimal ) ,
83+ expected : unscaled . map ( ( value ) => Number ( value ) / 100 ) ,
84+ } ,
85+ ] ;
86+ const batch = arrow . tableFromIPC ( ipc ( columns ) ) . batches [ 0 ] ;
87+ const vector = batch . getChildAt ( 0 ) ! ;
88+ const values = unscaled . map ( ( value , index ) => vector . get ( index ) ) ;
89+ const byteLengthReads = values . map ( ( value ) => {
90+ const read = sinon . stub ( ) . returns ( value . byteLength ) ;
91+ Object . defineProperty ( value , 'byteLength' , { get : read } ) ;
92+ return read ;
93+ } ) ;
94+ const sandbox = sinon . createSandbox ( ) ;
95+ try {
96+ sandbox . stub ( vector , 'get' ) . callsFake ( ( index ) => values [ index ] ) ;
97+ sandbox . stub ( batch , 'getChildAt' ) . returns ( vector ) ;
98+ const converter = converterFor ( columns , rowMode ) ;
99+ deepStrictEqual (
100+ ( converter as any ) . getRows ( batch , values . length ) ,
101+ columns [ 0 ] . expected . map ( ( amount ) => ( rowMode === 'array' ? [ amount ] : { amount } ) ) ,
102+ ) ;
103+ byteLengthReads . forEach ( ( read ) => sinon . assert . notCalled ( read ) ) ;
104+ } finally {
105+ sandbox . restore ( ) ;
106+ }
107+ } ) ;
108+
76109 it ( `preserves Decimal128 rounding, signs and scales (${ rowMode } )` , async ( ) => {
77110 const unscaled = [
78111 '0' ,
0 commit comments