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

Test : move tests for parse_string_decimal_native to parse_decimal #7177

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

Conversation

himadripal
Copy link
Contributor

@himadripal himadripal commented Feb 22, 2025

Which issue does this PR close?

Few important consideration -

  • Existing string to decimal conversion uses parse_string_to_decimal_native
  • parse_string_to_decimal_native does not have support for e-notation
  • parse_string_to_decimal_native does rounding at scale, not truncate
  • parse_decimal an existing method has e-notation support and use elsewhere
  • Fix: Support for e notation using existing parse_decimal in string to decimal conversion #6905 added rounding support in parse_decimal
  • moved string to decimal conversion to use parse_decimal to get support for e-notation.

This PR is a first one to break up #6905 , this one only moves the existing parse_string_to_decimal_native tests to use parse_decimal. You can observe I changed the tests because parse_decimal does not have rounding support as is. Next PR, I'll introduce that change and change these tests again.

Closes #.

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 Feb 22, 2025
38,
3,
),
"0.127"
"0.126"
Copy link
Contributor Author

@himadripal himadripal Feb 22, 2025

Choose a reason for hiding this comment

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

parse_decimal does not support rounding yet. it does truncate instead

38,
2,
),
"0.12"
);
assert_eq!(
Decimal128Type::format_decimal(
parse_string_to_decimal_native::<Decimal128Type>(".1265", 2).unwrap(),
parse_decimal::<Decimal128Type>(".1265", 38, 2).unwrap(),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

parse_decimal does not support rounding yet. it does truncate instead

38,
2,
),
"0.13"
"0.12"
Copy link
Contributor Author

@himadripal himadripal Feb 22, 2025

Choose a reason for hiding this comment

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

parse_decimal does not support rounding yet. it does truncate instead, fix is in this PR #7179. This change is put back in the PR #7179

12300000_i128
);

// `parse_decimal` does not handle scale=0 correctly. will enable it as part of code change PR.
// assert_eq!(parse_decimal::<Decimal128Type>("123.45", 38, 0)?, 123_i128);
Copy link
Contributor Author

@himadripal himadripal Feb 22, 2025

Choose a reason for hiding this comment

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

parse_decimal does not behave correctly when scale=0 when there are decimal digits in the original string. fix is in this PR #7179

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.

Thank you @himadripal -- i took a brief look and have a few questions

I am sorry for the delay in reviewing and the extra review, but I don't want to introduce another regression / need to do another release

12345000_i128
);

assert_eq!(
parse_string_to_decimal_native::<Decimal128Type>("123.4567891", 0)?,
//scale = 0 is not handled correctly in parse_decimal, next PR will fix it and enable this.
Copy link
Contributor

Choose a reason for hiding this comment

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

Doens't this comment out existing tests? Why would you reduce test coverage?

Copy link
Contributor Author

@himadripal himadripal Feb 26, 2025

Choose a reason for hiding this comment

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

So, this is commented as parse_decimal do not have handling of scale 0 well, Fix for scale 0 in parse_decimal is here #7179 and this test is enabled back there - all of these changes are all together in #6905

Copy link
Contributor

Choose a reason for hiding this comment

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

But my point is that this PR actually changes what is tested (it isn't just a migration / refactor).
I expect a refactor to change how the code is structured but not change the coverage

This comment was marked as outdated.

This comment was marked as outdated.

Copy link
Contributor Author

@himadripal himadripal Feb 27, 2025

Choose a reason for hiding this comment

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

Now, we can close this PR, as I added additional test in #7179 to check the values generated by parse_string_to_decimal_native and parse_decimal are same. So no change in existing test or coverage.

@@ -8416,92 +8417,92 @@ mod tests {
fn test_parse_string_to_decimal() {
assert_eq!(
Decimal128Type::format_decimal(
parse_string_to_decimal_native::<Decimal128Type>("123.45", 2).unwrap(),
parse_decimal::<Decimal128Type>("123.45", 38, 2).unwrap(),
Copy link
Contributor

Choose a reason for hiding this comment

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

This test is now testing a different function. I am not familar with the difference betwen parse_string_to_decimal and parse_decima

Copy link
Contributor Author

@himadripal himadripal Feb 26, 2025

Choose a reason for hiding this comment

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

Idea is to move from parse_string_to_decimal_native and to use parse_decimal while doing string to decimal casting here. Main reason is that parse_decimal has support for e-notation and is also being used in readers like (i.e arrow-csv, arrow-json and also performant, some discussion here

Copy link
Contributor

Choose a reason for hiding this comment

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

so is your plan to remove the parse_string_to_decimal function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, to be consistent, readers and cast will be using same function.

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.

2 participants