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

Support casting from String to Decimal #3281

Merged
merged 6 commits into from
Dec 12, 2022

Conversation

viirya
Copy link
Member

@viirya viirya commented Dec 6, 2022

Which issue does this PR close?

Closes #3280.

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 Dec 6, 2022
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 @viirya -- I reviewed the code and tests and they looked good to me 👍

I had a few suggested additional test cases but otherwise looks great 🏅

);
assert_eq!(
Decimal128Type::format_decimal(
parse_string_to_decimal_native::<Decimal128Type>("0.12345", 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.

I recommend test coverage for the following cases (apologies if they are already covered but I didn't see them):

  1. trim, eg, ". 0.123"
  2. Multiple leading zeros: "000.123"
  3. Multiple trailing zeros: "12.234000"
  4. empty string ""
  5. whitespace string " "
  6. Invalid "4.4.5"

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks. Added more test coverage including these cases and Nulls.

#[test]
fn test_cast_large_utf8_to_decimal() {
let str_array = LargeStringArray::from(vec![
"123.45", "1.2345", "0.12345", "0.1267", "1.263", "12345.0", "12345",
Copy link
Contributor

Choose a reason for hiding this comment

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

I recommend a test for an input array that has Nulls in it as well

}

#[test]
fn test_cast_utf8_to_decimal128_overflow() {
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@viirya viirya force-pushed the cast_string_to_decimal branch from 73b1e9e to bd99688 Compare December 10, 2022 20:28
@alamb
Copy link
Contributor

alamb commented Dec 12, 2022

Thanks @viirya

cc @liukun4515

@alamb alamb merged commit 2ad0705 into apache:master Dec 12, 2022
);
assert_eq!(
Decimal128Type::format_decimal(
parse_string_to_decimal_native::<Decimal128Type>(".1265", 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.

👍 rounding the result

let d = decimal_number.div_wrapping(div);
let r = decimal_number.mod_wrapping(div);

// Round result
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@ursabot
Copy link

ursabot commented Dec 13, 2022

Benchmark runs are scheduled for baseline = a973d39 and contender = 2ad0705. 2ad0705 is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
Conbench compare runs links:
[Skipped ⚠️ Benchmarking of arrow-rs-commits is not supported on ec2-t3-xlarge-us-east-2] ec2-t3-xlarge-us-east-2
[Skipped ⚠️ Benchmarking of arrow-rs-commits is not supported on test-mac-arm] test-mac-arm
[Skipped ⚠️ Benchmarking of arrow-rs-commits is not supported on ursa-i9-9960x] ursa-i9-9960x
[Skipped ⚠️ Benchmarking of arrow-rs-commits is not supported on ursa-thinkcentre-m75q] ursa-thinkcentre-m75q
Buildkite builds:
Supported benchmarks:
ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
test-mac-arm: Supported benchmark langs: C++, Python, R
ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java

mcheshkov pushed a commit to cube-js/arrow-rs that referenced this pull request Aug 21, 2024
Can drop this after rebase on commit 2ad0705 "Support casting from String to Decimal (apache#3281)", first released in 30.0.0
mcheshkov pushed a commit to cube-js/arrow-rs that referenced this pull request Aug 21, 2024
Can drop this after rebase on commit 2ad0705 "Support casting from String to Decimal (apache#3281)", first released in 30.0.0
mcheshkov pushed a commit to cube-js/arrow-rs that referenced this pull request Aug 21, 2024
Can drop this after rebase on commit 2ad0705 "Support casting from String to Decimal (apache#3281)", first released in 30.0.0
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.

Support casting from String to Decimal
4 participants