viirya commented on code in PR #2717:
URL: https://github.com/apache/arrow-rs/pull/2717#discussion_r969861636
##########
arrow/src/datatypes/native.rs:
##########
@@ -172,32 +175,56 @@ pub(crate) mod native_op {
macro_rules! native_type_op {
($t:tt) => {
impl native_op::ArrowNativeTypeOp for $t {
- fn add_checked(self, rhs: Self) -> Option<Self> {
- self.checked_add(rhs)
+ fn add_checked(self, rhs: Self) -> Result<Self> {
+ self.checked_add(rhs).ok_or_else(|| {
+ ArrowError::ComputeError(format!(
+ "Overflow happened on: {:?} + {:?}",
+ self, rhs
+ ))
+ })
}
fn add_wrapping(self, rhs: Self) -> Self {
self.wrapping_add(rhs)
}
- fn sub_checked(self, rhs: Self) -> Option<Self> {
- self.checked_sub(rhs)
+ fn sub_checked(self, rhs: Self) -> Result<Self> {
+ self.checked_sub(rhs).ok_or_else(|| {
+ ArrowError::ComputeError(format!(
+ "Overflow happened on: {:?} - {:?}",
+ self, rhs
+ ))
+ })
}
fn sub_wrapping(self, rhs: Self) -> Self {
self.wrapping_sub(rhs)
}
- fn mul_checked(self, rhs: Self) -> Option<Self> {
- self.checked_mul(rhs)
+ fn mul_checked(self, rhs: Self) -> Result<Self> {
+ self.checked_mul(rhs).ok_or_else(|| {
+ ArrowError::ComputeError(format!(
+ "Overflow happened on: {:?} * {:?}",
+ self, rhs
+ ))
+ })
}
fn mul_wrapping(self, rhs: Self) -> Self {
self.wrapping_mul(rhs)
}
- fn div_checked(self, rhs: Self) -> Option<Self> {
- self.checked_div(rhs)
+ fn div_checked(self, rhs: Self) -> Result<Self> {
+ if rhs.is_zero() {
+ Err(ArrowError::DivideByZero)
+ } else {
Review Comment:
Ehh, I don't think this is correct. Your proposal #2719 is only checking
division by zero error for integer division. But it doesn't match the behavior
of C++ DivideChecked kernel, and Spark divide expression. We have clean
distinction between checked and non-checked kernels. The checked kernel should
catch such invalid inputs at the runtime.
--
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]