diff --git a/arrow-arith/src/arithmetic.rs b/arrow-arith/src/arithmetic.rs index 124614d77f97..febf5ceabdd9 100644 --- a/arrow-arith/src/arithmetic.rs +++ b/arrow-arith/src/arithmetic.rs @@ -122,7 +122,7 @@ pub fn multiply_fixed_point_checked( let mut mul = a.wrapping_mul(b); mul = divide_and_round::(mul, divisor); mul.to_i128().ok_or_else(|| { - ArrowError::ComputeError(format!("Overflow happened on: {:?} * {:?}", a, b)) + ArrowError::ArithmeticOverflow(format!("Overflow happened on: {:?} * {:?}", a, b)) }) }) .and_then(|a| a.with_precision_and_scale(precision, required_scale)) @@ -323,7 +323,7 @@ mod tests { // `multiply` overflows on this case. let err = mul(&a, &b).unwrap_err(); - assert_eq!(err.to_string(), "Compute error: Overflow happened on: 123456789000000000000000000 * 10000000000000000000"); + assert_eq!(err.to_string(), "Arithmetic overflow: Overflow happened on: 123456789000000000000000000 * 10000000000000000000"); // Avoid overflow by reducing the scale. let result = multiply_fixed_point(&a, &b, 28).unwrap(); diff --git a/arrow-arith/src/numeric.rs b/arrow-arith/src/numeric.rs index 91aaf628438d..b6af40f7d7c2 100644 --- a/arrow-arith/src/numeric.rs +++ b/arrow-arith/src/numeric.rs @@ -888,15 +888,15 @@ mod tests { test_neg_primitive::( &[i32::MIN], - Err("Compute error: Overflow happened on: - -2147483648"), + Err("Arithmetic overflow: Overflow happened on: - -2147483648"), ); test_neg_primitive::( &[i64::MIN], - Err("Compute error: Overflow happened on: - -9223372036854775808"), + Err("Arithmetic overflow: Overflow happened on: - -9223372036854775808"), ); test_neg_primitive::( &[i64::MIN], - Err("Compute error: Overflow happened on: - -9223372036854775808"), + Err("Arithmetic overflow: Overflow happened on: - -9223372036854775808"), ); let r = neg_wrapping(&Int32Array::from(vec![i32::MIN])).unwrap(); @@ -911,7 +911,7 @@ mod tests { assert_eq!( err, - "Compute error: Overflow happened on: - -9223372036854775808" + "Arithmetic overflow: Overflow happened on: - -9223372036854775808" ); let a = Decimal128Array::from(vec![1, 3, -44, 2, 4]) @@ -1016,28 +1016,31 @@ mod tests { let a = UInt8Array::from(vec![56, 5, 3]); let b = UInt8Array::from(vec![200, 2, 5]); let err = add(&a, &b).unwrap_err().to_string(); - assert_eq!(err, "Compute error: Overflow happened on: 56 + 200"); + assert_eq!(err, "Arithmetic overflow: Overflow happened on: 56 + 200"); let result = add_wrapping(&a, &b).unwrap(); assert_eq!(result.as_ref(), &UInt8Array::from(vec![0, 7, 8])); let a = UInt8Array::from(vec![34, 5, 3]); let b = UInt8Array::from(vec![200, 2, 5]); let err = sub(&a, &b).unwrap_err().to_string(); - assert_eq!(err, "Compute error: Overflow happened on: 34 - 200"); + assert_eq!(err, "Arithmetic overflow: Overflow happened on: 34 - 200"); let result = sub_wrapping(&a, &b).unwrap(); assert_eq!(result.as_ref(), &UInt8Array::from(vec![90, 3, 254])); let a = UInt8Array::from(vec![34, 5, 3]); let b = UInt8Array::from(vec![200, 2, 5]); let err = mul(&a, &b).unwrap_err().to_string(); - assert_eq!(err, "Compute error: Overflow happened on: 34 * 200"); + assert_eq!(err, "Arithmetic overflow: Overflow happened on: 34 * 200"); let result = mul_wrapping(&a, &b).unwrap(); assert_eq!(result.as_ref(), &UInt8Array::from(vec![144, 10, 15])); let a = Int16Array::from(vec![i16::MIN]); let b = Int16Array::from(vec![-1]); let err = div(&a, &b).unwrap_err().to_string(); - assert_eq!(err, "Compute error: Overflow happened on: -32768 / -1"); + assert_eq!( + err, + "Arithmetic overflow: Overflow happened on: -32768 / -1" + ); let a = Int16Array::from(vec![21]); let b = Int16Array::from(vec![0]); @@ -1146,7 +1149,7 @@ mod tests { .with_precision_and_scale(3, -2) .unwrap(); let err = add(&a, &b).unwrap_err().to_string(); - assert_eq!(err, "Compute error: Overflow happened on: 10 ^ 39"); + assert_eq!(err, "Arithmetic overflow: Overflow happened on: 10 ^ 39"); let a = Decimal128Array::from(vec![10]) .with_precision_and_scale(3, -1) @@ -1154,7 +1157,7 @@ mod tests { let err = add(&a, &b).unwrap_err().to_string(); assert_eq!( err, - "Compute error: Overflow happened on: 10 * 100000000000000000000000000000000000000" + "Arithmetic overflow: Overflow happened on: 10 * 100000000000000000000000000000000000000" ); let b = Decimal128Array::from(vec![0]) @@ -1349,7 +1352,10 @@ mod tests { let a = IntervalMonthDayNanoArray::from(vec![IntervalMonthDayNano::MAX]); let b = IntervalMonthDayNanoArray::from(vec![IntervalMonthDayNano::ONE]); let err = add(&a, &b).unwrap_err().to_string(); - assert_eq!(err, "Compute error: Overflow happened on: 2147483647 + 1"); + assert_eq!( + err, + "Arithmetic overflow: Overflow happened on: 2147483647 + 1" + ); } fn test_duration_impl>() { @@ -1384,7 +1390,7 @@ mod tests { let err = add(&a, &b).unwrap_err().to_string(); assert_eq!( err, - "Compute error: Overflow happened on: 9223372036854775807 + 1" + "Arithmetic overflow: Overflow happened on: 9223372036854775807 + 1" ); } @@ -1511,7 +1517,7 @@ mod tests { let err = sub(&a, &b).unwrap_err().to_string(); assert_eq!( err, - "Compute error: Overflow happened on: 9223372036854775807 - -1" + "Arithmetic overflow: Overflow happened on: 9223372036854775807 - -1" ); } } diff --git a/arrow-array/src/arithmetic.rs b/arrow-array/src/arithmetic.rs index 078c2e3bc40e..fb9c868fb6c0 100644 --- a/arrow-array/src/arithmetic.rs +++ b/arrow-array/src/arithmetic.rs @@ -154,7 +154,7 @@ macro_rules! native_type_op { #[inline] fn add_checked(self, rhs: Self) -> Result { self.checked_add(rhs).ok_or_else(|| { - ArrowError::ComputeError(format!( + ArrowError::ArithmeticOverflow(format!( "Overflow happened on: {:?} + {:?}", self, rhs )) @@ -169,7 +169,7 @@ macro_rules! native_type_op { #[inline] fn sub_checked(self, rhs: Self) -> Result { self.checked_sub(rhs).ok_or_else(|| { - ArrowError::ComputeError(format!( + ArrowError::ArithmeticOverflow(format!( "Overflow happened on: {:?} - {:?}", self, rhs )) @@ -184,7 +184,7 @@ macro_rules! native_type_op { #[inline] fn mul_checked(self, rhs: Self) -> Result { self.checked_mul(rhs).ok_or_else(|| { - ArrowError::ComputeError(format!( + ArrowError::ArithmeticOverflow(format!( "Overflow happened on: {:?} * {:?}", self, rhs )) @@ -202,7 +202,7 @@ macro_rules! native_type_op { Err(ArrowError::DivideByZero) } else { self.checked_div(rhs).ok_or_else(|| { - ArrowError::ComputeError(format!( + ArrowError::ArithmeticOverflow(format!( "Overflow happened on: {:?} / {:?}", self, rhs )) @@ -221,7 +221,7 @@ macro_rules! native_type_op { Err(ArrowError::DivideByZero) } else { self.checked_rem(rhs).ok_or_else(|| { - ArrowError::ComputeError(format!( + ArrowError::ArithmeticOverflow(format!( "Overflow happened on: {:?} % {:?}", self, rhs )) @@ -237,14 +237,17 @@ macro_rules! native_type_op { #[inline] fn neg_checked(self) -> Result { self.checked_neg().ok_or_else(|| { - ArrowError::ComputeError(format!("Overflow happened on: - {:?}", self)) + ArrowError::ArithmeticOverflow(format!("Overflow happened on: - {:?}", self)) }) } #[inline] fn pow_checked(self, exp: u32) -> Result { self.checked_pow(exp).ok_or_else(|| { - ArrowError::ComputeError(format!("Overflow happened on: {:?} ^ {exp:?}", self)) + ArrowError::ArithmeticOverflow(format!( + "Overflow happened on: {:?} ^ {exp:?}", + self + )) }) } diff --git a/arrow-cast/src/cast/mod.rs b/arrow-cast/src/cast/mod.rs index 7df9420f94f0..5f72debcdad2 100644 --- a/arrow-cast/src/cast/mod.rs +++ b/arrow-cast/src/cast/mod.rs @@ -4531,7 +4531,7 @@ mod tests { ))], IntervalUnit::DayTime, format!( - "Compute error: Overflow happened on: {} * 100", + "Arithmetic overflow: Overflow happened on: {} * 100", i64::MAX - 2 ) ); @@ -4543,7 +4543,10 @@ mod tests { i64::MAX - 2 ))], IntervalUnit::MonthDayNano, - format!("Compute error: Overflow happened on: {} * 12", i64::MAX - 2) + format!( + "Arithmetic overflow: Overflow happened on: {} * 12", + i64::MAX - 2 + ) ); } diff --git a/arrow-schema/src/error.rs b/arrow-schema/src/error.rs index d9a0f3452c86..5e632d051f0f 100644 --- a/arrow-schema/src/error.rs +++ b/arrow-schema/src/error.rs @@ -33,6 +33,7 @@ pub enum ArrowError { SchemaError(String), ComputeError(String), DivideByZero, + ArithmeticOverflow(String), CsvError(String), JsonError(String), IoError(String, std::io::Error), @@ -88,6 +89,7 @@ impl Display for ArrowError { ArrowError::ParseError(desc) => write!(f, "Parser error: {desc}"), ArrowError::SchemaError(desc) => write!(f, "Schema error: {desc}"), ArrowError::ComputeError(desc) => write!(f, "Compute error: {desc}"), + ArrowError::ArithmeticOverflow(desc) => write!(f, "Arithmetic overflow: {desc}"), ArrowError::DivideByZero => write!(f, "Divide by zero error"), ArrowError::CsvError(desc) => write!(f, "Csv error: {desc}"), ArrowError::JsonError(desc) => write!(f, "Json error: {desc}"),