Various ScalarValue numeric method fixes & refactors (especially decimal)#23631
Open
Jefffrey wants to merge 10 commits into
Open
Various ScalarValue numeric method fixes & refactors (especially decimal)#23631Jefffrey wants to merge 10 commits into
ScalarValue numeric method fixes & refactors (especially decimal)#23631Jefffrey wants to merge 10 commits into
Conversation
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.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #23631 +/- ##
==========================================
+ Coverage 80.73% 80.74% +0.01%
==========================================
Files 1089 1090 +1
Lines 368948 368937 -11
Branches 368948 368937 -11
==========================================
+ Hits 297857 297889 +32
+ Misses 53334 53289 -45
- Partials 17757 17759 +2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
Author
|
msrv failure related to |
Jefffrey
marked this pull request as ready for review
July 16, 2026 11:24
AdamGS
reviewed
Jul 17, 2026
| // | ||
| // This is mainly a shortcut for not needing to manually list out each value | ||
| // anyway. | ||
| let mut values = [i256::ONE; _]; |
Contributor
There was a problem hiding this comment.
I think this is basically const mul? I also ran into that recently elsewhere, so figured I'll make a PR - apache/arrow-rs#10363
Contributor
Author
There was a problem hiding this comment.
this would be very helpful indeed 🙏
AdamGS
reviewed
Jul 17, 2026
AdamGS
approved these changes
Jul 17, 2026
AdamGS
left a comment
Contributor
There was a problem hiding this comment.
I think a bunch of this code is mine so I figured I'll review it 😅
It all makes sense, just two small comments
jayhan94
pushed a commit
to jayhan94/datafusion
that referenced
this pull request
Jul 23, 2026
see previous bump - apache#18403 honestly my main motivation was i was using a feature from `1.89.0` apparently for apache#23631 and realized we hadn't bumped this in a while if we prefer to be more conservative with msrv bumps (i.e. only bump if a dependency requires it or we see a really useful feature/lib function in newer versions) then i'm fine with leaving it and altering my PR above, but in the past we usually kept up to date with bumping our msrv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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