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
It should return null or throw an error as in this example
select cast(12345.6789asdecimal(6,2));
Arrowerror: Invalid argument error: 1234568 is too large to store in a Decimal128 of precision 6. Max is 999999
Additional context
while trying to enable decimal support in comet, Spark returns null in this cast but DataFusion returns a lowered precision value loosing the value of the decimal.
However here the cast changes value fundamentally, losing digits before the decimal dot, which is not OK.
The original value was ≈12345, the cast result is ≈1234.
I experimented with some test code in arrow-rs and see that there are validity checks when casting f64 to decimal but not when casting decimal to decimal.
Casting to decimal with smaller precision works when it should not:
let result = cast_with_options(&array,&output_type,&options).unwrap();println!("{:?}", result);// PrimitiveArray<Decimal128(6, 2)>// [// 123456789,// ]
Casting from f64 to decimal fails as expected:
let array = Float64Array::from(vec![1234567.89]);let result = cast_with_options(&array,&output_type,&options).unwrap();// InvalidArgumentError("123456789 is too large to store in a Decimal128 of precision 6. Max is 999999")
DataFusion CLI v54.0.0>select cast( cast(12345.6789asdecimal(24,2)) asdecimal(6,2));
Optimizer rule 'simplify_expressions' failed
caused by
Arrow error: Invalid argument error: 12345.68 is too large to store in a Decimal128 of precision 6. Max is 9999.99
Activity
himadripal commentedon Nov 19, 2024
In Postgres the following query resulted in an error
findepi commentedon Nov 20, 2024
Losing decimal digits (rounding) in a cast is OK.
However here the cast changes value fundamentally, losing digits before the decimal dot, which is not OK.
The original value was ≈12345, the cast result is ≈1234.
andygrove commentedon Dec 3, 2024
I experimented with some test code in arrow-rs and see that there are validity checks when casting f64 to decimal but not when casting decimal to decimal.
Setup code:
Casting to decimal with smaller precision works when it should not:
Casting from f64 to decimal fails as expected:
himadripal commentedon Dec 4, 2024
working on it.
himadripal commentedon Dec 27, 2024
once the arrow release is out, we can create a Datafusion release and use that here to fix this
Jefffrey commentedon Jun 28, 2026
fixed upstream, running on datafusion main: