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 negative decimal string #5128

Merged
merged 6 commits into from
Nov 28, 2023
Merged

Conversation

viirya
Copy link
Member

@viirya viirya commented Nov 27, 2023

Which issue does this PR close?

Closes #5127.

Rationale for this change

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 Nov 27, 2023
@@ -8304,6 +8331,8 @@ mod tests {
Some(""),
Some(" "),
None,
Some("-1.23499999"),
Some("-1.23599999"),
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps worth testing -0.001 or similar?

Copy link
Member

Choose a reason for hiding this comment

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

-+123.45 should be failed, but pass.

Copy link
Member

Choose a reason for hiding this comment

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

The result for -123 is wrong, which ignores the minus sign.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added the test case (and others).

let decimals = if parts.len() == 2 { parts[1] } else { "" };

let (decimals, negative) = if parts.len() == 2 {
(parts[1], integers.starts_with('-'))
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this after the trim_start_matches above? I think this will parse 000-1.343

Copy link
Member Author

Choose a reason for hiding this comment

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

Yea

};

let integers = if negative {
integers.trim_start_matches('-')
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be trim_start_matches or just a single strip_prefix?

};

if negative {
format!("{}", integers.sub_wrapping(adjusted))
Copy link
Contributor

Choose a reason for hiding this comment

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

Not related to this PR, but I wonder if we need to format to a string and then convert back

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, I forgot why we did the conversion at first. Maybe we can get rid of it. As it is not part of this PR, I will do it later.

arrow-cast/src/cast.rs Outdated Show resolved Hide resolved
arrow-cast/src/cast.rs Outdated Show resolved Hide resolved
viirya and others added 2 commits November 28, 2023 00:55
Co-authored-by: Raphael Taylor-Davies <[email protected]>
Co-authored-by: Raphael Taylor-Davies <[email protected]>
Comment on lines +8353 to +8355
Some("1.-23499999"),
Some("-1.-23499999"),
Some("--1.23499999"),
Copy link
Member

@Weijun-H Weijun-H Nov 28, 2023

Choose a reason for hiding this comment

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

Why results of these cases are null instead of error?

Copy link
Member Author

Choose a reason for hiding this comment

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

When CastOptions.safe is true (default), cast failure returns NULL.

@tustvold tustvold merged commit 8a0b5cb into apache:master Nov 28, 2023
26 checks passed
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.

cast Utf8 to decimal failure
3 participants