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

Handle precision overflow when casting from integer to decimal #3996

Merged
merged 4 commits into from
Apr 1, 2023

Conversation

viirya
Copy link
Member

@viirya viirya commented Apr 1, 2023

Which issue does this PR close?

Closes #3995.

Rationale for this change

Although cast kernel checks if division or multiplication overflows in such cast operation, it doesn't check precision overflow. This is somehow related to decimal operation convention in arrow-rs, that is let user handle invalid values in decimal arrays. But for cast kernel, because it provides CastOptions which defines null behavior for invalid case, the behavior of not checking precision overflow becomes a bit inconsistent.

What changes are included in this PR?

Are there any user-facing changes?

@github-actions github-actions bot added the arrow Changes to the arrow crate label Apr 1, 2023
@viirya viirya changed the title Handle overflow precision when casting from integer to decimal Handle precision overflow when casting from integer to decimal Apr 1, 2023
&DataType::Decimal128(7, 3),
&CastOptions { safe: false },
);
assert!(casted_array.is_err());
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps could check the error

@@ -358,13 +358,29 @@ where

let array = if scale < 0 {
match cast_options.safe {
true => array.unary_opt::<_, D>(|v| v.as_().div_checked(scale_factor).ok()),
false => array.try_unary::<_, D, _>(|v| v.as_().div_checked(scale_factor))?,
true => array.unary_opt::<_, D>(|v| {
Copy link
Contributor

Choose a reason for hiding this comment

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

thanks for taking this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrow Changes to the arrow crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handle overflow precision when casting from integer to decimal
3 participants