neilconway commented on code in PR #26062:
URL: https://github.com/apache/datafusion/pull/26062#discussion_r4219745419
##########
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:
Thanks, good catch! Fixed.
--
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]