Repository navigation
Preserve exact DECIMAL map keys on both backends - #657
vuanhphung wants to merge 6 commits into
Conversation
Format Decimal128 keys at their declared scale before Arrow MapRow coerces them to strings, regardless of numeric-value precision mode. Signed-off-by: Vu Anh Phung <vu.phung@databricks.com> Co-authored-by: Isaac <no-reply@databricks.com>
Convert Arrow 13's string-valued Decimal128 result to bigint only at the map-key call site. Cover wide negative keys and adjacent entries without changing decimal value conversion. 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>
There was a problem hiding this comment.
🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).
Verdict: 1 Nit
Looks good: no blocking issues. The DECIMAL key branch in convertArrowTypes covers both the fast path and the legacy getObjectRows path. Unit tests run it against real Arrow IPC for both precision settings and include wide negatives. Non-decimal keys still go through MapRow.toJSON() as before.
Other findings
- ⚪ Nit — The new CHANGELOG bullet is followed by a blank line, while the other Unreleased bullets are packed with no blank lines between them. Remove the blank line so the list formatting matches. It's cosmetic only. (Found by Claude Opus 5.5 · confirmed by the judge)
Signed-off-by: Vu Anh Phung <vu.phung@databricks.com> Co-authored-by: Isaac <no-reply@databricks.com>
|
Removed the extra Unreleased-list blank line in b556574. Changelog formatting passes; no code changed. This comment was generated with GitHub MCP. |
Signed-off-by: Vu Anh Phung <vu.phung@databricks.com> Co-authored-by: Isaac <no-reply@databricks.com>
Resolve the main changes by merging (no force-push). Signed-off-by: Vu Anh Phung <vu.phung@databricks.com> Co-authored-by: Isaac <no-reply@databricks.com>
There was a problem hiding this comment.
🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).
Verdict: 2 Nit
Looks good, only nits. I checked the MapRow key path, the sign handling in the 128-bit word conversion, and the key order (scale-0 keys keep their old order); I found no correctness issues. Unit and e2e tests cover both backends and both precision modes.
Other findings
- ⚪ Nit — Keys with a negative scale still go through
bigNumDecimalToString'sscale <= 0branch, which returns the unscaled integer. This is unchanged from before and Spark only allows negative scales under a legacy flag, so it can be follow-up work. (Found by Claude Opus 5.5 · the judge disputed it but couldn't back that up, so it's kept) - ⚪ Nit — The newly exported
decimal128ToBigInthas no doc comment, while the neighbouringbigNumDecimalToStringanddecimalToNumberdo. Add a short JSDoc describing the four little-endian 32-bit words, the signed 128-bit result, and the fallback for other word counts. (Found by Claude Opus 5.5 · confirmed by the judge)
On both backends, a DECIMAL map key is spelled from its unscaled integer. The DECIMAL(10,2) key 1.50 reads as
"150", so a lookup with"1.50"misses the entry. The cause is apache-arrow'sMapRow.toJSON(), which turns each key into a string through the BigNum's unscaledtoString(). This PR reads the original keys through the map's iterator and formats DECIMAL keys exactly at the declared scale withbigNumDecimalToString. The unscaled value is built directly from the Decimal128's four 32-bit words (decimal128ToBigInt). Arrow's ownbigNumToBigIntreturns a string for these values, so the old route was slow, and unless the string is converted, wide negative keys round or merge into one entry. The fix applies with eitherpreserveBigNumericPrecisionsetting. Other key types, values, and Thrift modes that return complex types as JSON text are unchanged. Positive-scale DECIMAL keys now enumerate in server order instead of ascending numeric order. Scale-0 keys keep their old order, and the CHANGELOG notes this.New real-Arrow unit tests fail on
mainand pass here. They cover scales 2 and 7, wide negatives, near-equal keys, key order, and a fixed-seed comparison of the word helper against Arrow's conversion. So do the live e2e tests for Thrift and the kernel (tests/e2e/kernel/). On both backends, the COMPLEX-240901 tripwire from databricks/databricks-driver-test#2410 is an expected failure onmainand passes unexpectedly (XPASS) on this branch. For 100k DECIMAL(10,2)-keyed maps, medianfetchAll()is 635 → 658 ms on Thrift and 401 → 412 ms on SEA. With five keys per map it is faster thanmain: 1807 → 1691 ms and 1061 → 993 ms. The warehouse was shared. Queries without maps don't run the new code. Other maps pay one key-type check per row, about 2% on integer-keyed maps.Cross-driver state
BigDecimal.toPlainString()(ComplexDataTypeParser.java:442@6fe99f2)decimal.Decimalkeys (result_set.py:97@543777a)decimalfmt.ExactStringfor map keys (columnValues.go:583@eefbf7b)napi/src/result.rs:67@3b691d2)Security Scan fails on the same
cross-spawn/wsadvisories asmain.Adversarial review: 1 high fixed (wide negative keys) in 2 rounds; the review follow-ups converged in 1 round. Existing bugs in other key types and in the value path are tracked separately; #658 fixes the value path.
Fixes #655
This pull request and its description were written by Isaac.