viirya commented on code in PR #2357:
URL: https://github.com/apache/arrow-rs/pull/2357#discussion_r940614439


##########
arrow/src/compute/kernels/cast.rs:
##########
@@ -1276,8 +1277,17 @@ fn cast_decimal_to_decimal(
             .iter()
             .map(|v| v.map(|v| v.as_i128() * mul))
             .collect::<Decimal128Array>()
-    }
-    .with_precision_and_scale(*output_precision, *output_scale)?;
+    };
+    // For decimal cast to decimal, if the range of output is gt_eq than the 
input, don't need to
+    // do validation.
+    let output_array  = match output_precision-output_scale>=input_precision - 
input_scale {
+        true => {
+            output_array.with_precision_and_scale(*output_precision, 
*output_scale, false)
+        }
+        false => {
+            output_array.with_precision_and_scale(*output_precision, 
*output_scale, true)
+        }
+    }?;

Review Comment:
   > if cast decimal(5,2) to decimal(5,3). a value of 123.45 will be convert to 
123.450, but the 123450 is out of range of decimal(5,3).
   
   This out-of-range should already be caught now as `with_precision_and_scale` 
will do the validation.
   
   But I got your point of the change here. `with_precision_and_scale` will do 
validation here all the time. But for some cases `output precision >= input 
precision + (output scale - input scale)`, we can skip the validation.
   
   I'd suggest to rewrite the condition as `output precision >= input precision 
+ (output scale - input scale)`.
   
   



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