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


##########
arrow-cast/src/cast/decimal.rs:
##########
@@ -121,6 +169,40 @@ where
     })
 }
 
+pub(crate) fn convert_to_bigger_or_equal_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 = output_scale - input_scale;
+    // if the gain in precision (digits) is greater than the multiplication 
due to scaling
+    // every number will fit into the output type
+    let is_infallible_cast = (input_precision as i8) + delta_scale <= 
(output_precision as i8);

Review Comment:
   I've looked into this a little bit more, and it seems that the precision and 
scale are checked when building an array using the 
`validate_decimal_precision_and_scale` function. My feeling is that the arrays 
should always be constructed correctly, but anyway I added a the validation at 
the top of the cast functions.



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