Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: decimal stat rounding overflow #2975

Merged
merged 1 commit into from
Nov 21, 2024

Conversation

gruuya
Copy link
Contributor

@gruuya gruuya commented Nov 4, 2024

Description

Try to detect the situation where floating point conversion rounds the integer value beyond the valid Decimal(scale, precision) range, and rollback to next smaller value towards 0.0.

Related Issue(s)

Closes #2974

Documentation

None

@github-actions github-actions bot added the binding/rust Issues for the Rust crate label Nov 4, 2024
Copy link

github-actions bot commented Nov 4, 2024

ACTION NEEDED

delta-rs follows the Conventional Commits specification for release automation.

The PR title and description are used as the merge commit message. Please update your PR title and description to match the specification.

@gruuya gruuya changed the title Fix Decimal stat rounding overflow fix: decimal stat rounding overflow Nov 4, 2024
Comment on lines +349 to +352
if (val.trunc() as i128).to_string().len() > (precision - scale) as usize {
// For normal values with integer parts that get rounded to a number beyond
// the precision - scale range take the next smaller (by magnitude) value
val = f64::from_bits(val.to_bits() - 1);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure how performant this is, but the result won't be consistent/parse-able without it.

The actual "round-down" could be done with next_down once it's stable/delta-rs uses nightly.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@rtyler would you be ok with having delta-rs use nightly features?

Copy link

codecov bot commented Nov 4, 2024

Codecov Report

Attention: Patch coverage is 97.14286% with 1 line in your changes missing coverage. Please review.

Project coverage is 72.47%. Comparing base (0434435) to head (3012da5).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
crates/core/src/writer/stats.rs 97.14% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2975   +/-   ##
=======================================
  Coverage   72.47%   72.47%           
=======================================
  Files         128      128           
  Lines       40823    40857   +34     
  Branches    40823    40857   +34     
=======================================
+ Hits        29585    29613   +28     
- Misses       9355     9356    +1     
- Partials     1883     1888    +5     

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


🚨 Try these New Features:

@ion-elgreco ion-elgreco added this pull request to the merge queue Nov 21, 2024
Merged via the queue into delta-io:main with commit eff5735 Nov 21, 2024
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
binding/rust Issues for the Rust crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Parse Decimal overflow
2 participants