findepi commented on code in PR #6836:
URL: https://github.com/apache/arrow-rs/pull/6836#discussion_r1870235805


##########
arrow-cast/src/cast/decimal.rs:
##########
@@ -112,8 +112,19 @@ where
     };
 
     Ok(match cast_options.safe {
-        true => array.unary_opt(f),
-        false => array.try_unary(|x| f(x).ok_or_else(|| error(x)))?,
+        true => {
+            array.unary_opt(|x| {
+                 f(x).filter(|v| O::is_valid_decimal_precision(*v, 
output_precision))
+            })
+        }
+        false => {
+            array.try_unary(|x| {
+                f(x).ok_or_else(|| error(x))
+                    .and_then(|v|{
+                        O:: validate_decimal_precision(v, 
output_precision).map(|_| v)

Review Comment:
   Why not do this when computing the value (the code above), and only when 
this can fail?
   (for example widening precision cannot fail, so no need to spend cycles on 
validating the produced values)



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