Jefffrey commented on code in PR #10707:
URL: https://github.com/apache/arrow-rs/pull/10707#discussion_r3795376715


##########
arrow-cast/src/cast/mod.rs:
##########
@@ -348,6 +348,36 @@ pub fn cast(array: &dyn Array, to_type: &DataType) -> 
Result<ArrayRef, ArrowErro
     cast_with_options(array, to_type, &CastOptions::default())
 }
 
+/// Convert an integer to a decimal native value without wrapping.
+///
+/// `AsPrimitive` / `as` silently truncates when the source is wider than `M`
+/// (for example `5_000_000_000i64 as i32`). All integer sources fit in `i128`
+/// losslessly, which [`DecimalCast`] then converts to the decimal native type
+/// with a range check.
+fn integer_to_decimal_native<I, M>(value: I) -> Option<M>
+where
+    I: Into<i128>,
+    M: DecimalCast,
+{
+    M::from_decimal(value.into())
+}
+
+/// Scale an integer down in its native type before narrowing it to the decimal
+/// native type.
+///
+/// If the scale factor cannot be represented by the input type, it is larger
+/// than every possible input value and integer division therefore produces
+/// zero.
+fn scale_integer_down<I>(value: I, scale: u32) -> Option<I>
+where
+    I: ArrowNativeTypeOp,
+{
+    match I::usize_as(10).pow_checked(scale) {

Review Comment:
   this would push the pow into the hotloop which can impact performance i 
believe



##########
arrow-cast/benches/integer_to_decimal.rs:
##########


Review Comment:
   can we centralize these to existing cast kernels benchmarks:
   
   https://github.com/apache/arrow-rs/blob/main/arrow/benches/cast_kernels.rs



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