You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/08/08 10:57:40 UTC

[GitHub] [arrow-rs] HaoYang670 commented on a diff in pull request #2357: [WIP]Change precision of decimal without validation

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


##########
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:
   I am still learning the logic. Here is just a nit:
   ```suggestion
       let output_array  = output_array.with_precision_and_scale(
           *output_precision, 
           *output_scale, 
           output_precision - output_scale < input_precision - 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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org