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


##########
arrow-cast/src/cast/decimal.rs:
##########
@@ -76,6 +76,54 @@ where
     }
 }
 
+pub(crate) fn convert_to_smaller_scale_decimal_same_type<T>(
+    array: &PrimitiveArray<T>,
+    input_precision: u8,
+    input_scale: i8,
+    output_precision: u8,
+    output_scale: i8,
+    cast_options: &CastOptions,
+) -> Result<PrimitiveArray<T>, ArrowError>
+where
+    T: DecimalType,
+    T::Native: DecimalCast + ArrowNativeTypeOp,
+{
+    let delta_scale = input_scale - output_scale;
+    // if the reudction of the input number through scaling (dividing) is 
greater
+    // than a possible precision loss (plus potential increase via rounding) 
every input number will fit into the output type
+    let is_infallible_cast = (input_precision as i8) - delta_scale < 
(output_precision as i8);
+
+    if is_infallible_cast {

Review Comment:
   Doing this check inside the `convert_to_smaller_scale_decimal` and only 
by-pass the validation part based on this?
    In that case conversion logic can be one place.



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