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: parse string of scientific notation to decimal when the scale is 0 #5740

Merged
merged 2 commits into from
May 13, 2024

Conversation

yjshen
Copy link
Member

@yjshen yjshen commented May 9, 2024

Which issue does this PR close?

Closes #5739.

Rationale for this change

Unable to parse scientific notation string when the scale is 0.

parse_decimal::<Decimal128Type>("1.234e16", 20, 0).unwrap()
called `Result::unwrap()` on an `Err` value: ParseError("can't parse the string value 1.234e16 to decimal")

What changes are included in this PR?

Bug fix and also tests.

Are there any user-facing changes?

No.

@github-actions github-actions bot added the arrow Changes to the arrow crate label May 9, 2024
@yjshen yjshen changed the title fix: parse string to decimal when scale is 0 fix: parse string of scientific notation to decimal when the scale is 0 May 9, 2024
@alamb
Copy link
Contributor

alamb commented May 11, 2024

INtegration CI failure due to #5719

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Looks good to me -- thanks @yjshen

@@ -860,7 +860,7 @@ pub fn parse_decimal<T: DecimalType>(
"can't parse the string value {s} to decimal"
)));
}
if fractionals == scale {
if fractionals == scale && scale != 0 {
Copy link
Contributor

@tustvold tustvold May 13, 2024

Choose a reason for hiding this comment

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

It took me quite a while to work out what was going on here, the issue appears to be that parse_e_notation uses a non-zero fractionals to skip over the decimal point.

I think this can now overflow, but I think that is a broader issue with the e parsing logic. I will file a ticket

@tustvold tustvold merged commit 326231e into apache:master May 13, 2024
25 of 26 checks passed
@tustvold
Copy link
Contributor

I thought it was a pre-existing issue, but actually the existing code handles this correctly.

This PR therefore introduces an overflow bug - #5762

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.

Unable to parse scientific notation string to decimal when scale is 0
3 participants