You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "comphead (via GitHub)" <gi...@apache.org> on 2023/04/01 18:31:21 UTC

[GitHub] [arrow-datafusion] comphead commented on a diff in pull request #5811: Scalar arithmetic should return error when overflows.

comphead commented on code in PR #5811:
URL: https://github.com/apache/arrow-datafusion/pull/5811#discussion_r1155153400


##########
datafusion/common/src/scalar.rs:
##########
@@ -573,12 +573,43 @@ macro_rules! primitive_op {
         match ($LEFT, $RIGHT) {
             (lhs, None) => Ok(ScalarValue::$SCALAR(*lhs)),
             #[allow(unused_variables)]
-            (None, Some(b)) => { primitive_right!(*b, $OPERATION, $SCALAR) },
-            (Some(a), Some(b)) => Ok(ScalarValue::$SCALAR(Some(*a $OPERATION *b))),
+            (None, Some(b)) => {
+                primitive_right!(*b, $OPERATION, $SCALAR)
+            }
+            (Some(a), Some(b)) => {
+                if let Some(value) = primitive_checked_op!(a, b, $OPERATION, $SCALAR) {
+                    Ok(ScalarValue::$SCALAR(Some(value)))
+                } else {
+                    Err(DataFusionError::Execution(
+                        "Overflow while calculating ScalarValue.".to_string(),
+                    ))
+                }
+            }
         }
     };
 }
 
+macro_rules! primitive_checked_op {
+    ($LEFT:expr, $RIGHT:expr, $OPERATION:tt, Float64) => {

Review Comment:
   cool!



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org