Uh oh!
There was an error while loading. Please reload this page.
Various ScalarValue numeric method fixes & refactors (especially decimal) - #23631
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:
|
Jefffrey
commented
Jul 16, 2026
msrv failure related to |
| // | ||
| // This is mainly a shortcut for not needing to manually list out each value | ||
| // anyway. | ||
| let mut values = [i256::ONE; _]; |
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
There was a problem hiding this comment.
this would be very helpful indeed 🙏
Uh oh!
There was an error while loading. Please reload this page.
AdamGS
left a comment
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
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
alamb
commented
Jul 26, 2026
Uh oh!
There was an error while loading. Please reload this page.
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
…cimal) (apache#23631) ## Which issue does this PR close? <!-- We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closesapache#123` indicates that this PR will close issue apache#123. --> N/A ## Rationale for this change <!-- Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed. Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes. --> 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? <!-- There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR. --> I recommend looking at the commits as they are self contained with detailed messages for each. ## Are these changes tested? <!-- We typically require tests for all PRs in order to: 1. Prevent the code from being accidentally broken by subsequent changes 2. Serve as another way to document the expected behavior of the code If tests are not included in your PR, please explain why (for example, are they covered by existing tests)? --> Yes ## Are there any user-facing changes? <!-- If there are user-facing changes then we may require documentation to be updated before approving the PR. --> No <!-- If there are any breaking changes to public APIs, please add the `api change` label. -->
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