coderfender commented on code in PR #2542:
URL: https://github.com/apache/datafusion-comet/pull/2542#discussion_r2424669749
##########
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:
Thank you for the suggestion @andygrove . Let me update it to use `map_err`
instead of `match` statement
##########
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(),
+ )),
+ }
+ } else {
+ Ok(($X - rem).sub_wrapping($DIV))
+ }
} else if rem >= $HALF {
- ($X - rem).add_wrapping($DIV)
+ if $FAIL_ON_ERROR {
+ match ($X - rem).add_checked($DIV) {
Review Comment:
Sure
##########
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(),
+ )),
+ }
+ } else {
+ Ok(($X - rem).sub_wrapping($DIV))
+ }
} else if rem >= $HALF {
- ($X - rem).add_wrapping($DIV)
+ if $FAIL_ON_ERROR {
+ match ($X - rem).add_checked($DIV) {
+ Ok(v) => Ok(v),
+ Err(_e) => Err(ArrowError::ComputeError(
+ arithmetic_overflow_error("integer").to_string(),
+ )),
+ }
+ } else {
+ Ok(($X - rem).add_wrapping($DIV))
+ }
} else {
- $X - rem
+ if $FAIL_ON_ERROR {
+ match $X.sub_checked(rem) {
Review Comment:
Sure
--
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]