Skip to content

Preserve exact DECIMAL map keys on both backends - #657

Open
vuanhphung wants to merge 6 commits into
mainfrom
vuanhphung/decimal-map-keys
Open

vuanhphung wants to merge 6 commits into
mainfrom
vuanhphung/decimal-map-keys

Conversation

@vuanhphung

@vuanhphung vuanhphung commented Dec 2, 2026 •

Copy link
Copy Markdown
Collaborator

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's MapRow.toJSON(), which turns each key into a string through the BigNum's unscaled toString(). This PR reads the original keys through the map's iterator and formats DECIMAL keys exactly at the declared scale with bigNumDecimalToString. The unscaled value is built directly from the Decimal128's four 32-bit words (decimal128ToBigInt). Arrow's own bigNumToBigInt returns 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 either preserveBigNumericPrecision setting. 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 main and 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 on main and passes unexpectedly (XPASS) on this branch. For 100k DECIMAL(10,2)-keyed maps, median fetchAll() is 635 → 658 ms on Thrift and 401 → 412 ms on SEA. With five keys per map it is faster than main: 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

Driver State Notes
JDBC Supported databricks/databricks-jdbc#1854: BigDecimal.toPlainString() (ComplexDataTypeParser.java:442 @6fe99f2)
Python Supported Native decimal.Decimal keys (result_set.py:97 @543777a)
Go Supported decimalfmt.ExactString for map keys (columnValues.go:583 @eefbf7b)
Node.js Not supported → Supported (this PR) Exact plain fixed-point keys in Arrow modes, both backends
Kernel Not applicable Preserves Decimal128 in IPC (napi/src/result.rs:67 @3b691d2)

Security Scan fails on the same cross-spawn/ws advisories as main.

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.

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>
@vuanhphung
vuanhphung marked this pull request as ready for review December 2, 2026 21:03

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔀 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>
@vuanhphung

Copy link
Copy Markdown
Collaborator Author

Removed the extra Unreleased-list blank line in b556574. Changelog formatting passes; no code changed.


This comment was generated with GitHub MCP.

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).

✅ No issues identified.

Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).

✅ No issues identified.

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>

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔀 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's scale <= 0 branch, 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 decimal128ToBigInt has no doc comment, while the neighbouring bigNumDecimalToString and decimalToNumber do. 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)

This branch was previously deployed

1 inactive deployment
azure-prod — 49e81267 Deployed Dec 3, 2026 by vuanhphung via e2e-test (24.22.1, 24_22_1) #2299
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[coverage] COMPLEX-240901: Nested Decimal Values Keep Exact Magnitude And Declared Scale In Array Map And Struct

1 participant