jayzhan211 commented on code in PR #26062:
URL: https://github.com/apache/datafusion/pull/26062#discussion_r4219602174


##########
datafusion/functions/src/macros.rs:
##########
@@ -297,36 +298,32 @@ macro_rules! make_math_unary_udf {
                     let args = ColumnarValue::values_to_arrays(&args.args)?;
                     let arr: ArrayRef = match args[0].data_type() {
                         DataType::Float64 => {
-                            let values = args[0]
-                                .as_primitive::<Float64Type>()
-                                .try_unary::<_, Float64Type, _>(
-                                |x: f64| -> std::result::Result<f64, 
ArrowError> {
-                                    if let Some(validate) = $VALIDATOR {
-                                        validate(x).map_err(|error| {
-                                            
ArrowError::ComputeError(error.to_string())
-                                        })?;
-                                    }
-
-                                    Ok(f64::$UNARY_FUNC(x))
-                                },
-                            )?;
-                            Arc::new(values) as ArrayRef
+                            let array = args[0].as_primitive::<Float64Type>();
+                            let result = match $INPUT_ERROR {
+                                Some(input_error) => {
+                                    
$crate::math::common::unary_with_input_check(
+                                        array,
+                                        f64::$UNARY_FUNC,
+                                        input_error,
+                                    )?
+                                }
+                                None => array.unary::<_, 
Float64Type>(f64::$UNARY_FUNC),
+                            };
+                            Arc::new(result) as ArrayRef
                         }
                         DataType::Float32 => {
-                            let values = args[0]
-                                .as_primitive::<Float32Type>()
-                                .try_unary::<_, Float32Type, _>(
-                                |x: f32| -> std::result::Result<f32, 
ArrowError> {
-                                    if let Some(validate) = $VALIDATOR {
-                                        validate(x as f64).map_err(|error| {
-                                            
ArrowError::ComputeError(error.to_string())
-                                        })?;
-                                    }
-
-                                    Ok(f32::$UNARY_FUNC(x))
-                                },
-                            )?;
-                            Arc::new(values) as ArrayRef
+                            let array = args[0].as_primitive::<Float32Type>();
+                            let result = match $INPUT_ERROR {
+                                Some(input_error) => {
+                                    
$crate::math::common::unary_with_input_check(
+                                        array,
+                                        f32::$UNARY_FUNC,
+                                        |x: f32| input_error(x as f64),

Review Comment:
   The Float32 error path isn't tested: if this closure is replaced with `|_x: 
f32| None`, all `datafusion-functions` unit tests and the 
`scalar`/`functions`/`math`/`expr` slt files still pass. Both cases below fail 
against that mutant and pass on this branch:
   
   ```diff
    # sqrt scalar negative float8
    query error cannot take square root of a negative number
    select sqrt((-1.0)::float8);
   +
   +# sqrt scalar negative float4
   +query error cannot take square root of a negative number
   +select sqrt(arrow_cast(-1, 'Float32'));
   +
   +# sqrt negative float4 column
   +query error cannot take square root of a negative number
   +select sqrt(arrow_cast(a, 'Float32')) from signed_integers;
   ```



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