mbutrovich commented on code in PR #11369:
URL: https://github.com/apache/arrow-rs/pull/11369#discussion_r4225262624


##########
arrow-cast/src/cast/mod.rs:
##########
@@ -443,18 +442,14 @@ where
                     .expect("value fits the decimal")
             }),
             (Some(scale_factor), true) => array.unary_opt::<_, D>(|v| {
-                let v = v
-                    .div_checked(scale_factor)
-                    .ok()
-                    .and_then(integer_to_decimal_native::<_, M>)?;
+                let v = v.div_wrapping(scale_factor);
+                let v = integer_to_decimal_native::<_, M>(v)?;
                 (D::is_valid_decimal_precision(v, precision)).then_some(v)
             }),
             (Some(scale_factor), false) => array.try_unary::<_, D, _>(|v| {
-                let v = v
-                    .div_checked(scale_factor)
-                    .ok()
-                    .and_then(integer_to_decimal_native::<_, M>)
-                    .ok_or_else(|| overflow(v))?;
+                let original_v = v;
+                let v = v.div_wrapping(scale_factor);
+                let v = integer_to_decimal_native::<_, M>(v).ok_or_else(|| 
overflow(original_v))?;
                 D::validate_decimal_precision(v, precision, scale).map(|()| v)

Review Comment:
   Could this arm follow the `all_fit` arm above it, which passes 
`v.div_wrapping(scale_factor)` straight into `integer_to_decimal_native`? 
Naming the quotient keeps `v` for the error message, so `original_v` isn't 
needed.
   
   ```suggestion
                   let d = integer_to_decimal_native::<_, 
M>(v.div_wrapping(scale_factor))
                       .ok_or_else(|| overflow(v))?;
                   D::validate_decimal_precision(d, precision, scale).map(|()| 
d)
   ```



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