SubhamSinghal commented on code in PR #20189:
URL: https://github.com/apache/datafusion/pull/20189#discussion_r2805221674


##########
datafusion/spark/src/function/math/negative.rs:
##########
@@ -96,37 +95,80 @@ impl ScalarUDFImpl for SparkNegative {
     }
 
     fn invoke_with_args(&self, args: ScalarFunctionArgs) -> 
Result<ColumnarValue> {
-        spark_negative(&args.args)
+        spark_negative(&args.args, 
args.config_options.execution.enable_ansi_mode)
     }
 }
 
 /// Core implementation of Spark's negative function
-fn spark_negative(args: &[ColumnarValue]) -> Result<ColumnarValue> {
+fn spark_negative(
+    args: &[ColumnarValue],
+    enable_ansi_mode: bool,
+) -> Result<ColumnarValue> {
     let [arg] = take_function_args("negative", args)?;
 
     match arg {
         ColumnarValue::Array(array) => match array.data_type() {
             DataType::Null => Ok(arg.clone()),
 
-            // Signed integers - use wrapping negation (Spark legacy mode 
behavior)
+            // Signed integers - use checked negation in ANSI mode, wrapping 
in legacy mode
             DataType::Int8 => {
                 let array = array.as_primitive::<Int8Type>();
-                let result: PrimitiveArray<Int8Type> = array.unary(|x| 
x.wrapping_neg());
+                let result: PrimitiveArray<Int8Type> = if enable_ansi_mode {
+                    array.try_unary(|x| {
+                        x.checked_neg().ok_or_else(|| {
+                            ArrowError::ComputeError(format!(

Review Comment:
   @comphead I was looking at 
[this](https://github.com/apache/datafusion/blob/main/datafusion/spark/src/function/math/abs.rs#L100)
 which throw Arrow::ComputeError. Do we need to throw `exec_err! `instead?



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