-
Notifications
You must be signed in to change notification settings - Fork 867
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
Conversation
There was a problem hiding this 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(), |
There was a problem hiding this comment.
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):
- trim, eg,
". 0.123"
- Multiple leading zeros:
"000.123"
- Multiple trailing zeros:
"12.234000"
- empty string
""
- whitespace string
" "
- Invalid
"4.4.5"
There was a problem hiding this comment.
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.
arrow-cast/src/cast.rs
Outdated
#[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", |
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
73b1e9e
to
bd99688
Compare
Thanks @viirya cc @liukun4515 |
); | ||
assert_eq!( | ||
Decimal128Type::format_decimal( | ||
parse_string_to_decimal_native::<Decimal128Type>(".1265", 2).unwrap(), |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
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. |
Can drop this after rebase on commit 2ad0705 "Support casting from String to Decimal (apache#3281)", first released in 30.0.0
Can drop this after rebase on commit 2ad0705 "Support casting from String to Decimal (apache#3281)", first released in 30.0.0
Can drop this after rebase on commit 2ad0705 "Support casting from String to Decimal (apache#3281)", first released in 30.0.0
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?