andygrove commented on code in PR #2542:
URL: https://github.com/apache/datafusion-comet/pull/2542#discussion_r2424655991


##########
native/spark-expr/src/math_funcs/round.rs:
##########
@@ -15,49 +15,90 @@
 // specific language governing permissions and limitations
 // under the License.
 
+use crate::arithmetic_overflow_error;
 use crate::math_funcs::utils::{get_precision_scale, make_decimal_array, 
make_decimal_scalar};
 use arrow::array::{Array, ArrowNativeTypeOp};
 use arrow::array::{Int16Array, Int32Array, Int64Array, Int8Array};
 use arrow::datatypes::DataType;
+use arrow::error::ArrowError;
 use datafusion::common::{exec_err, internal_err, DataFusionError, ScalarValue};
 use datafusion::{functions::math::round::round, physical_plan::ColumnarValue};
 use std::{cmp::min, sync::Arc};
 
 macro_rules! integer_round {
-    ($X:expr, $DIV:expr, $HALF:expr) => {{
+    ($X:expr, $DIV:expr, $HALF:expr, $FAIL_ON_ERROR:expr) => {{
         let rem = $X % $DIV;
         if rem <= -$HALF {
-            ($X - rem).sub_wrapping($DIV)
+            if $FAIL_ON_ERROR {
+                match ($X - rem).sub_checked($DIV) {
+                    Ok(v) => Ok(v),
+                    Err(_e) => Err(ArrowError::ComputeError(
+                        arithmetic_overflow_error("integer").to_string(),
+                    )),
+                }

Review Comment:
   Since the `Ok` value is unchanged and the `Err` is changed, it would be 
better to use `map_err` rather than a match here.
   
   ```suggestion
                   ($X - rem).sub_checked($DIV).map_err(|_| {
                       
ArrowError::ComputeError(arithmetic_overflow_error("integer").to_string())
                   })
   ```



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to