1fanwang commented on code in PR #7599:
URL: https://github.com/apache/datafusion-comet/pull/7599#discussion_r4591540878


##########
native/spark-expr/src/math_funcs/negative.rs:
##########
@@ -447,4 +453,91 @@ mod tests {
             "expected the ArrowError to pass through unchanged, got: {err:?}"
         );
     }
+
+    /// Negate `input` as a scalar and as a one element array, and return both 
results.
+    fn negate_as_scalar_and_array(
+        input: &ScalarValue,
+        fail_on_error: bool,
+    ) -> (ScalarValue, ScalarValue) {
+        let ColumnarValue::Scalar(from_scalar) = eval_scalar(input.clone(), 
fail_on_error).unwrap()
+        else {
+            panic!("expected scalar result")
+        };
+        let ColumnarValue::Array(from_array) =
+            eval_array(input.to_array().unwrap(), fail_on_error).unwrap()
+        else {
+            panic!("expected array result")
+        };
+        (
+            from_scalar,
+            ScalarValue::try_from_array(&from_array, 0).unwrap(),
+        )
+    }
+
+    /// In legacy mode the minimum of a signed integer type negates to itself, 
as a scalar just
+    /// as in an array. ANSI mode still raises the overflow for the same 
scalar.
+    fn assert_legacy_scalar_wraps_min(min: ScalarValue) {
+        let (from_scalar, from_array) = negate_as_scalar_and_array(&min, 
false);
+        assert_eq!(from_array, min);
+        assert_eq!(from_scalar, min);
+        assert!(eval_scalar(min, true).is_err());
+    }

Review Comment:
   Done in 
https://github.com/apache/datafusion-comet/commit/c133a96ff8633a1e6f03274e69b8b4a8b8b53f32.
 The loop also covers an ordinary value and a null, since test_scalar_negation 
only ran those with ANSI on. The SQL case has not been run yet because the 
Spark JVM suite is not set up on my machine, so please treat it as unverified 
until CI reports.



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

Reply via email to