andygrove commented on issue #13492:
URL: https://github.com/apache/datafusion/issues/13492#issuecomment-2515808157

   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:
   
   ```rust
           let array = vec![Some(123456789)];
           let array = create_decimal_array(array, 24, 2).unwrap();
           println!("{:?}", array);
           // PrimitiveArray<Decimal128(24, 2)>
           // [
           //     123456789,
           // ]
   
           let input_type = DataType::Decimal128(24, 2);
           let output_type = DataType::Decimal128(6, 2);
           assert!(can_cast_types(&input_type, &output_type));
   
           let mut options = CastOptions::default();
           options.safe = false;
   
   ```
   
   Casting to decimal with smaller precision works when it should not:
   
   ```rust
           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:
   
   ```rust
           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")
   ```
           


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to