himadripal commented on code in PR #7021:
URL: https://github.com/apache/arrow-rs/pull/7021#discussion_r1950402313


##########
arrow-cast/src/cast/decimal.rs:
##########
@@ -99,10 +100,24 @@ where
     I::Native: DecimalCast + ArrowNativeTypeOp,
     O::Native: DecimalCast + ArrowNativeTypeOp,
 {
+    validate_decimal_precision_and_scale::<O>(output_precision, output_scale)?;

Review Comment:
   I was thinking something like the below, but realized the version you have 
is better and I think having the validation check inside `is_infallible_cast` 
branch, sounds like a good idea.
   ```rust 
   Ok(if cast_options.safe {
           array.unary_opt(|x| {
               let result = f(x);
               if is_infallible_cast {
                   result
               } else {
                   result.filter(|v| O::is_valid_decimal_precision(*v, 
output_precision))
               }
           })
       } else {
           array.try_unary(|x| {
               let result = f(x).ok_or_else(|| error(x))?;
               if is_infallible_cast {
                   result
               } else {
                   O::validate_decimal_precision(result, 
output_precision).map(|_| result)
               }
           })?
       })
   ```



-- 
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: github-unsubscr...@arrow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to