Repository navigation
Preserve exact wide negative DECIMAL values - #658
Conversation
Signed-off-by: Vu Anh Phung <vu.phung@databricks.com> Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: Vu Anh Phung <vu.phung@databricks.com> Co-authored-by: Isaac <no-reply@databricks.com>
aakash-saravanan-db
left a comment
There was a problem hiding this comment.
The shared BigInt normalization is the right fix for Arrow's runtime string/bigint mismatch: it covers scalar and recursive conversion on both backends without changing default number mode.
Approving the production change. Both inline test comments are blocking and must be addressed before merge.
This review was generated with GitHub MCP.
| return null; | ||
| } | ||
| const integer = BigInt(value); | ||
| if (scale <= 0) { |
There was a problem hiding this comment.
Blocking before merge: this new oracle treats every scale <= 0 as an unscaled integer. With unscaled 1 and scale -2, the value is 100, but the new precision-mode expectation is "1"; the same test correctly expects 100 in default mode.
The production limitation predates this PR, but we should avoid adding an assertion that certifies the wrong value. Please keep negative-scale coverage for default mode and restrict the new precision-exactness assertions to nonnegative scales. Negative-scale support can be tracked separately; this PR does not need a production change for it.
There was a problem hiding this comment.
Done in aed9cb3: precision-mode exactness now covers only non-negative scales, and every default-mode negative-scale case stays. Negative-scale support in precision mode is left for a separate change. Databricks SQL rejects CAST(... AS DECIMAL(10,-2)), and ROUND(..., -2) returns scale 0, so it's only reachable from hand-built Arrow data.
| }); | ||
| } | ||
|
|
||
| for (const rowMode of ['object', 'array'] as const) { |
There was a problem hiding this comment.
Blocking before merge: please extend the existing fixtures to cover this regression and consolidate the duplicated setup.
The existing matches legacy precise DECIMAL in scalars and containers test already covers scalars, structs, lists, map values, NULL and both row modes. Replacing its small negative (-12500) with a wide negative and updating the expected literals catches this bug; that extension fails against the old formatter and passes here. The expanded scale/sign matrix already covers the top-level boundaries. This lets us remove this separate nested block while retaining the regression coverage and adding wide-negative map-value coverage.
Likewise, please add the wide-negative scalar and nested case to tests/e2e/utils/rowMaterialization.ts and reuse its backend/mode cases instead of the separate negative-decimals.test.ts connection/session scaffolding. Preserve the mode-specific default-number rounding expectations. Assert nested exactness for kernel and Thrift native-Arrow mode; Thrift's internal non-native mode parses complex values as JSON, so it should not acquire an assertion blessing lossy output as an exact result.
Please retain the direct real-Arrow formatter test, which usefully exercises the runtime type mismatch.
There was a problem hiding this comment.
Done in aed9cb3: the wide negative now extends matches legacy precise DECIMAL in scalars and containers (and the dictionary case). The separate nested block and negative-decimals.test.ts are gone. rowMaterialization.ts now covers a wide-negative scalar plus nested struct, list and map values, with exactness asserted only for kernel and native-Arrow Thrift. Default-number rounding is unchanged in each mode, and the direct real-Arrow formatter test stays.
Exclude negative scales from precision-exact assertions and extend shared unit and live fixtures instead of duplicating conversion and session setup. Signed-off-by: Vu Anh Phung <vu.phung@databricks.com> Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
|
Thanks for your contribution! To satisfy the DCO policy in our contributing guide every commit message must include a sign-off message. One or more of your commits is missing this message. You can reword previous commit messages with an interactive rebase ( |
Signed-off-by: Vu Anh Phung <vu.phung@databricks.com> Co-authored-by: Isaac <no-reply@databricks.com>
9535617 to
da94610
Compare
With
preserveBigNumericPrecision: true, negative DECIMAL values whose unscaled value exceeds 2^53 are corrupted on both backends, both as top-level columns and nested.-123456789012345678.91comes back as"-123456789012345670.00", and wider values come back as broken exponent strings. apache-arrow'sbigNumToBigIntreturns a decimal string for Decimal128 even though it is typedbigint(still true in 21.2.0), andbigNumDecimalToStringnegated that string as a lossy JS number. This PR converts the input to abigintonce, inbigNumDecimalToString. The default number mode is unchanged.The existing real-Arrow unit fixtures (scalars, structs, lists, map values, NULL, both row modes) and the shared row-materialization e2e fixture now include wide negatives, and they fail on
mainand pass here on both backends. Precision-mode exactness is asserted for scales 0/2/18/38. Negative scales aren't covered in that mode: they predate this PR, and Databricks SQL rejects negative-scale DECIMALs. driver-test's skippedDecimalTestsDECIMAL(38, 37) — max scalealready tracks this bug. It fails onmainand passes on this branch on both backends, and can be re-enabled after merge. A 100k-row mixed-sign DECIMAL(38,2) fetch shows no slowdown: median Thrift 425 → 405 ms, kernel 359 → 354 ms, on a shared warehouse.Cross-driver state
BigDecimalis exact (DatabricksResultSet.java:748@8898712); nested values are exact withEnableComplexDatatypeSupport=1(default off)decimal.Decimal(utils.py:1043@543777a)internal/decimalfmt/decimalfmt.go:52@eefbf7bpreserveBigNumericPrecision(default off) is now exact for wide negativesnapi/src/result.rs:88@3b691d2); formatting happens in the JS driver#657 wraps its DECIMAL map keys in
BigInt(...)for the same reason. Once both merge, that wrapper is redundant but harmless. Security Scan fails on the samecross-spawn/wsadvisories asmain.Adversarial review: converged in round 1 with no high findings.
This pull request and its description were written by Isaac.