You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
DataFusion should support casting strings such as "4e7" to decimal #10315
I'm working on this issue and need help here -
I added test case to debug, at the moment string to decimal conversion is using parse_string_to_decimal_native, I did not find support for e notation in this, but there is a function parse_decimal that does support e-notation.I changed the code to use parse_decimal and it works fine for cases with 4e+7 and looks like there is a bug in the parse_decimal when i provide 4e7 without + or -, for example this test case -
#[test]fntest_cast_with_options_utf8_to_decimal(){let array = StringArray::from(vec!["4e7"]);let result = cast_with_options(&array,&DataType::Decimal128(10,2),&CastOptions{safe:false,format_options:FormatOptions::default(),},).unwrap();let output_array = result.as_any().downcast_ref::<Decimal128Array>();assert_eq!(output_array.unwrap().value(0),40000000);}
returns 4000000000 so it expands till the precision value.
This works now: arrow-cast's string-to-decimal cast switched to parse_decimal, which handles exponents. I checked with arrow 60.1 (the version on main): '4e7', '4E7', '1.5e-2' and '-2.5e3' all cast to Decimal128(10, 2) and Decimal128(38, 2) as expected (40000000.00, 0.02, -2500.00). Closing as completed.
Activity
Omega359 commentedon May 1, 2024
I suspect this issue is actually in arrow_cast - the error message seems to come from https://github.com/apache/arrow-rs/blob/ada986c7ec8f8fe4f94235c8aaeba4995392ee72/arrow-cast/src/cast.rs#L2753
tustvold commentedon May 1, 2024
I believe this will be supported in the next arrow release
himadripal commentedon Dec 18, 2024
I'm working on this issue and need help here -
I added test case to debug, at the moment string to decimal conversion is using parse_string_to_decimal_native, I did not find support for
enotation in this, but there is a function parse_decimal that does support e-notation.I changed the code to use parse_decimal and it works fine for cases with 4e+7 and looks like there is a bug in the parse_decimal when i provide 4e7 without + or -, for example this test case -should we replace parse_string_to_decimal_native with parse_decimal and fix this bug there?
andygrove commentedon Dec 18, 2024
At first glance,
parse_decimallooks more mature and more efficient thanparse_string_to_decimal_native.For example,
parse_string_to_decimal_nativehas some expensive operations that are avoided inparse_decimal:It does seem to make sense to do what you suggest and use
parse_decimaland fix the bug there.andygrove commentedon Nov 16, 2026
This works now: arrow-cast's string-to-decimal cast switched to
parse_decimal, which handles exponents. I checked with arrow 60.1 (the version on main):'4e7','4E7','1.5e-2'and'-2.5e3'all cast toDecimal128(10, 2)andDecimal128(38, 2)as expected (40000000.00, 0.02, -2500.00). Closing as completed.