Skip to content

Commit 20681dc

Browse files
vuanhphungIsaac
andcommitted
Pin signed decimal fast-path selection in tests
Signed-off-by: Vu Anh Phung <vu.phung@databricks.com> Co-authored-by: Isaac <no-reply@databricks.com>
1 parent fbe5057 commit 20681dc

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

‎tests/unit/result/ArrowRowMaterialization.test.ts‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,39 @@ function decimal(value: string): Uint32Array {
7373

7474
describe('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

Comments
 (0)