-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[VARIANT] Validate precision in VariantDecimalXX structs and add missing tests #7776
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
Conversation
| @@ -1,5 +1,3 @@ | |||
| use std::ops::Deref; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure how this ended up here...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can blame the IDE perhaps
| #[derive(Debug, Clone, Copy, PartialEq)] | ||
| pub struct ShortString<'a>(pub(crate) &'a str); | ||
|
|
||
| /// Represents a 4-byte decimal value in the Variant format. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved to decimal.rs
| const MAX_PRECISION: u32 = 9; | ||
| const MAX_UNSCALED_VALUE: u32 = 10_u32.pow(Self::MAX_PRECISION) - 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hoisted up and renamed the existing constant, and used it to define the other constant
| "Scale {} of a 4-byte decimal cannot exceed the max precision {}", | ||
| scale, | ||
| Self::MAX_PRECISION, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the error message to reference the constant instead of a magic number
| // Validate that the integer value fits within the precision | ||
| if integer.unsigned_abs() > Self::MAX_UNSCALED_VALUE { | ||
| return Err(ArrowError::InvalidArgumentError(format!( | ||
| "{} is too large to store in a 4-byte decimal with max precision {}", | ||
| integer, | ||
| Self::MAX_PRECISION | ||
| ))); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The newly added validation
alamb
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love it
Which issue does this PR close?
VariantBuilder#7697Rationale for this change
As a follow-up to #7738, we should verify that the unscaled integer value fits in the max precision (scale factor was already validated).
What changes are included in this PR?
Add the missing checking, and add missing unit tests for both precision and scale.
Also move the
VariantDecimalXXstructs to their own mod.Are these changes tested?
Yes, see above.
Are there any user-facing changes?
No. Public re-rexport of the moved structs.