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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

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.28%. Comparing base (7a3b3ec) to head (66d926d).

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.26%   72.28%   +0.01%     
==========================================
  Files         128      128              
  Lines       40329    40363      +34     
  Branches    40329    40363      +34     
==========================================
+ Hits        29143    29175      +32     
+ Misses       9334     9332       -2     
- Partials     1852     1856       +4     

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

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