Skip to content

Commit 65806c0

Browse files
vuanhphungIsaac
andcommitted
Prove the decimal fast-path test reads through its stubs
Assert the stubbed vector.get feeds getRows, and add unsafe values that must take the BigInt fallback, so the byteLength checks cannot pass vacuously if getRows stops reading through the stubs. Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
1 parent db6cd83 commit 65806c0

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,14 @@ 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'];
76+
it(`skips BigInt conversion only for safe-integer decimals (${rowMode})`, () => {
77+
const safe = ['0', '1', '-1', '4294967297', '-4294967297', '9007199254740991', '-9007199254740991'];
78+
// The BigInt fallback reads `byteLength`; these must take it.
79+
const unsafe = ['9007199254740993', '-9007199254740993', '18446744073709551616'];
80+
const unscaled = [...safe, ...unsafe];
7881
const columns: Column[] = [
7982
{
80-
field: new arrow.Field('amount', new arrow.Decimal(2, 18, 128)),
83+
field: new arrow.Field('amount', new arrow.Decimal(2, 38, 128)),
8184
thriftType: TTypeId.DECIMAL_TYPE,
8285
values: unscaled.map(decimal),
8386
expected: unscaled.map((value) => Number(value) / 100),
@@ -93,14 +96,17 @@ describe('Arrow row materialization', () => {
9396
});
9497
const sandbox = sinon.createSandbox();
9598
try {
96-
sandbox.stub(vector, 'get').callsFake((index) => values[index]);
99+
const get = sandbox.stub(vector, 'get').callsFake((index) => values[index]);
97100
sandbox.stub(batch, 'getChildAt').returns(vector);
98101
const converter = converterFor(columns, rowMode);
99102
deepStrictEqual(
100103
(converter as any).getRows(batch, values.length),
101104
columns[0].expected.map((amount) => (rowMode === 'array' ? [amount] : { amount })),
102105
);
103-
byteLengthReads.forEach((read) => sinon.assert.notCalled(read));
106+
// The stubbed values must be the ones converted, or the byteLength checks prove nothing.
107+
sinon.assert.callCount(get, values.length);
108+
byteLengthReads.slice(0, safe.length).forEach((read) => sinon.assert.notCalled(read));
109+
byteLengthReads.slice(safe.length).forEach((read) => sinon.assert.called(read));
104110
} finally {
105111
sandbox.restore();
106112
}

0 commit comments

Comments
 (0)