Skip to content

fix: normalize negative-scale BigDecimal parameters before Arrow encoding - #202

Merged
KaviarasuSakthivadivel merged 4 commits into
mainfrom
fix/negative-scale-decimal-arrow-param
Sep 30, 2026
Merged

KaviarasuSakthivadivel merged 4 commits into
mainfrom
fix/negative-scale-decimal-arrow-param

Conversation

@KaviarasuSakthivadivel

Copy link
Copy Markdown
Contributor

BigDecimal.stripTrailingZeros() can yield a negative scale (e.g. new BigDecimal("12345670").stripTrailingZeros() -> scale=-1, precision=7). That negative scale was carried straight into the Arrow Decimal type advertised for the bound parameter, which Hyper rejects before evaluating any SQL ("Invalid scale -1, scale must be between 0 and the precision"). Rescale any such value to scale >= 0 in ArrowUtils.toArrowByteArray before building the schema/vectors.

@codecov

codecov Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.11%. Comparing base (80ee690) to head (4eff1b5).

Additional details and impacted files
@@             Coverage Diff              @@
##               main     #202      +/-   ##
============================================
+ Coverage     80.99%   81.11%   +0.12%     
- Complexity     1726     1735       +9     
============================================
  Files           123      123              
  Lines          5051     5063      +12     
  Branches        524      526       +2     
============================================
+ Hits           4091     4107      +16     
+ Misses          728      726       -2     
+ Partials        232      230       -2     
Components Coverage Δ
JDBC Core 81.14% <100.00%> (+0.15%) ⬆️
JDBC Main 57.42% <ø> (ø)
JDBC HTTP 90.71% <ø> (ø)
JDBC Utilities 65.25% <ø> (ø)
Spark Datasource ∅ <ø> (∅)
Files with missing lines Coverage Δ
...force/datacloud/jdbc/protocol/data/ArrowUtils.java 82.97% <100.00%> (+11.55%) ⬆️

... and 1 file with indirect coverage changes

Impacted file tree graph

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@KaviarasuSakthivadivel
KaviarasuSakthivadivel force-pushed the fix/negative-scale-decimal-arrow-param branch 2 times, most recently from cc1bc0d to 902982f Compare September 25, 2026 21:08
…ding

BigDecimal.stripTrailingZeros() can yield a negative scale (e.g.
new BigDecimal("12345670").stripTrailingZeros() -> scale=-1, precision=7).
That negative scale was carried straight into the Arrow Decimal type
advertised for the bound parameter, which Hyper rejects before
evaluating any SQL ("Invalid scale -1, scale must be between 0 and the
precision"). Rescale any such value to scale >= 0 in
ArrowUtils.toArrowByteArray before building the schema/vectors.
… branches

Closes the Codecov patch-coverage gap on ArrowUtils.java by exercising the
branches the initial regression test didn't reach: a null binding, a
non-BigDecimal-valued binding, and an already-non-negative-scale BigDecimal,
all of which must pass through toArrowByteArray unchanged.
- Explain why a null ParameterBinding is reachable (ParameterAccumulator
  pads skipped positional parameters with null) so the null-check in
  normalizeDecimalScale isn't mistaken for defensive-only code.
- Strengthen the regression test with an exact assertEquals against
  "12345670", since BigDecimal#compareTo ignores scale.
BigDecimal.precision() can be smaller than scale() for small-magnitude
values with leading zeros after the decimal point (e.g. new
BigDecimal("0.001") -> precision=1, scale=3), violating Hyper's
"0 <= scale <= precision" DECIMAL invariant in the opposite direction
from the negative-scale case already handled. Generalize
normalizeDecimalScale to widen precision to max(precision, scale)
whenever needed, covering both violation directions in one place.
@KaviarasuSakthivadivel
KaviarasuSakthivadivel force-pushed the fix/negative-scale-decimal-arrow-param branch from 902982f to 4eff1b5 Compare September 29, 2026 23:36
@KaviarasuSakthivadivel
KaviarasuSakthivadivel merged commit e257047 into main Sep 30, 2026
15 checks passed
@KaviarasuSakthivadivel
KaviarasuSakthivadivel deleted the fix/negative-scale-decimal-arrow-param branch September 30, 2026 17:18
KaviarasuSakthivadivel pushed a commit that referenced this pull request Sep 30, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.1.1](v1.1.0...v1.1.1)
(2026-09-30)


### Bug Fixes

* normalize negative-scale BigDecimal parameters before Arrow encoding
([#202](#202))
([e257047](e257047))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.

2 participants