Skip to content

Various ScalarValue numeric method fixes & refactors (especially decimal)#23631

Open
Jefffrey wants to merge 6 commits into
apache:mainfrom
Jefffrey:fix-scalar-val-num-ops
Open

Various ScalarValue numeric method fixes & refactors (especially decimal)#23631
Jefffrey wants to merge 6 commits into
apache:mainfrom
Jefffrey:fix-scalar-val-num-ops

Conversation

@Jefffrey

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

N/A

Rationale for this change

I noticed there were some subtle errors with how decimals were handled in scalar values, and also opportunity to remove power calls in favour of precomputed constant tables. Also filling out some other missing support.

What changes are included in this PR?

I recommend looking at the commits as they are self contained with detailed messages for each.

Are these changes tested?

Yes

Are there any user-facing changes?

No

Jefffrey added 6 commits July 16, 2026 19:32
Since we already have access to these constant lookup tables, its more
efficient to index into them rather than calculating via `checked_pow()`
at runtime.
There's a side-effect of some tests failing so I removed them. I think
this is fine since it doesn't make sense to have a `ScalarValue` method
where we request a value of a certain type but can get a different value
type out.
Seems like this was just a simple omission
For one/negative one, if the scale equals the precision then all values
are to the right of the decimal point meaning we actually cannot
represent a value of 1, so this could have caused some subtle errors.

Similar for ten, we need at least 2 digits left of the decimal point,
that is (p - s) >= 2, to represent a ten value.
Using macros here to generate these tables instead of manually
enumerating the values into the code itself; for i256 its a bit
complicated since it doesn't have native support so can't use direct
multiplication as it doesn't have const support.

Used Codex in this case, but added a unit test to ensure the constant
values generated are correct.
I noticed we didn't have support for `Float16`, `Decimal32` and
`Decimal64` here; instead of just adding them here, I figured it would
be easier to plumb in the `ScalarValue` code to reduce duplication and
ensure there's less opportunities for subtle omissions like this.
@github-actions github-actions Bot added optimizer Optimizer rules common Related to common crate labels Jul 16, 2026
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.47826% with 19 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@67907a6). Learn more about missing BASE report.

Files with missing lines Patch % Lines
datafusion/common/src/scalar/mod.rs 80.80% 19 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #23631   +/-   ##
=======================================
  Coverage        ?   80.66%           
=======================================
  Files           ?     1087           
  Lines           ?   366086           
  Branches        ?   366086           
=======================================
  Hits            ?   295308           
  Misses          ?    53185           
  Partials        ?    17593           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Jefffrey

Copy link
Copy Markdown
Contributor Author

msrv failure related to

@Jefffrey Jefffrey marked this pull request as ready for review July 16, 2026 11:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

common Related to common crate optimizer Optimizer rules

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants