Jefffrey commented on code in PR #19871:
URL: https://github.com/apache/datafusion/pull/19871#discussion_r2703276398
##########
datafusion/functions/src/math/signum.rs:
##########
@@ -98,41 +97,58 @@ impl ScalarUDFImpl for SignumFunc {
}
fn invoke_with_args(&self, args: ScalarFunctionArgs) ->
Result<ColumnarValue> {
- make_scalar_function(signum, vec![])(&args.args)
+ let return_type = args.return_type().clone();
+ let [arg] = take_function_args(self.name(), args.args)?;
+
+ match arg {
+ ColumnarValue::Scalar(scalar) => {
+ if scalar.is_null() {
+ return ColumnarValue::Scalar(ScalarValue::Null)
+ .cast_to(&return_type, None);
+ }
+
+ match scalar {
+ ScalarValue::Float64(Some(v)) => {
+ let result = if v == 0.0 { 0.0 } else { v.signum() };
+
Ok(ColumnarValue::Scalar(ScalarValue::Float64(Some(result))))
+ }
+ ScalarValue::Float32(Some(v)) => {
+ let result = if v == 0.0 { 0.0 } else { v.signum() };
+
Ok(ColumnarValue::Scalar(ScalarValue::Float32(Some(result))))
+ }
+ _ => {
+ internal_err!(
+ "Unexpected scalar type for signum: {:?}",
+ scalar.data_type()
+ )
+ }
+ }
+ }
+ ColumnarValue::Array(array) => match array.data_type() {
+ Float64 => Ok(ColumnarValue::Array(Arc::new(
+ array.as_primitive::<Float64Type>().unary::<_,
Float64Type>(
+ |x: f64| {
+ if x == 0.0 { 0.0 } else { x.signum() }
+ },
+ ),
+ ))),
+ Float32 => Ok(ColumnarValue::Array(Arc::new(
+ array.as_primitive::<Float32Type>().unary::<_,
Float32Type>(
+ |x: f32| {
+ if x == 0.0 { 0.0 } else { x.signum() }
+ },
+ ),
+ ))),
+ other => exec_err!("Unsupported data type {other:?} for
function signum"),
Review Comment:
nit: this should be internal error to be consistent with scalar path above
--
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]