jonahgao commented on code in PR #4830:
URL: https://github.com/apache/arrow-rs/pull/4830#discussion_r1329519775


##########
arrow-cast/src/cast.rs:
##########
@@ -2801,6 +2801,11 @@ where
     if cast_options.safe {
         let iter = from.iter().map(|v| {
             v.and_then(|v| parse_string_to_decimal_native::<T>(v, scale as 
usize).ok())
+                .and_then(|v| {
+                    T::validate_decimal_precision(v, precision)
+                        .is_ok()
+                        .then_some(v)
+                })

Review Comment:
   @viirya I noticed that casting from integers has this validation, which is 
inconsistent with the behavior of casting from strings.
   
   There is an intuitive example in Datafusion.
   ```
   DataFusion CLI v31.0.0
   ❯ select cast(1000 as decimal(10,8));
   Optimizer rule 'simplify_expressions' failed
   caused by
   Arrow error: Invalid argument error: 100000000000 is too large to store in a 
Decimal128 of precision 10. Max is 9999999999
   
   ❯ select cast('1000' as decimal(10,8));
   +--------------+
   | Utf8("1000") |
   +--------------+
   | 10.00000000  |
   +--------------+
   ```
   If they could have a unified behavior, it would be preferable.



##########
arrow-cast/src/cast.rs:
##########
@@ -2801,6 +2801,11 @@ where
     if cast_options.safe {
         let iter = from.iter().map(|v| {
             v.and_then(|v| parse_string_to_decimal_native::<T>(v, scale as 
usize).ok())
+                .and_then(|v| {
+                    T::validate_decimal_precision(v, precision)
+                        .is_ok()
+                        .then_some(v)
+                })

Review Comment:
   @viirya I noticed that casting from integers has this validation, which is 
inconsistent with the behavior of casting from strings.
   
   There is an intuitive example in Datafusion.
   ```
   DataFusion CLI v31.0.0
   ❯ select cast(1000 as decimal(10,8));
   Optimizer rule 'simplify_expressions' failed
   caused by
   Arrow error: Invalid argument error: 100000000000 is too large to store in a 
Decimal128 of precision 10. Max is 9999999999
   
   ❯ select cast('1000' as decimal(10,8));
   +--------------+
   | Utf8("1000") |
   +--------------+
   | 10.00000000  |
   +--------------+
   ```
   If they could have a unified behavior, it would be preferable.



-- 
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]

Reply via email to