liukun4515 commented on code in PR #2650:
URL: https://github.com/apache/arrow-rs/pull/2650#discussion_r963225816


##########
arrow/src/compute/kernels/arity.rs:
##########
@@ -83,6 +84,41 @@ where
     PrimitiveArray::<O>::from(data)
 }
 
+/// A overflow-checking variant of `unary`.
+pub(crate) fn unary_checked<I, F, O>(
+    array: &PrimitiveArray<I>,
+    op: F,
+) -> Result<PrimitiveArray<O>>
+where
+    I: ArrowPrimitiveType,
+    O: ArrowPrimitiveType,
+    F: Fn(I::Native) -> Option<O::Native>,
+    I::Native: ArrowNativeTypeOp,
+{
+    let values = array.values().iter().map(|v| {
+        let result = op(*v);
+        if let Some(r) = result {
+            Ok(r)
+        } else {
+            // Overflow
+            Err(ArrowError::ComputeError(format!(
+                "Overflow happened on: {:?}",
+                *v
+            )))
+        }
+    });

Review Comment:
   ```suggestion
       let values = array.values().iter().map(|v| {
           op(*v)
       });
   ```



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

Reply via email to