Jefffrey commented on code in PR #19395:
URL: https://github.com/apache/datafusion/pull/19395#discussion_r2644500341
##########
datafusion/spark/src/function/math/abs.rs:
##########
@@ -69,8 +70,35 @@ impl ScalarUDFImpl for SparkAbs {
&self.signature
}
- fn return_type(&self, arg_types: &[DataType]) -> Result<DataType> {
- Ok(arg_types[0].clone())
+ fn return_type(&self, _arg_types: &[DataType]) -> Result<DataType> {
+ internal_err!(
+ "SparkAbs: return_type() is not used; return_field_from_args() is
implemented"
+ )
+ }
+
+ fn return_field_from_args(&self, args: ReturnFieldArgs) ->
Result<FieldRef> {
+ if args.arg_fields.is_empty() {
+ return internal_err!(
+ "abs takes exactly 1 argument, but got: {}",
+ args.arg_fields.len()
+ );
+ }
+
+ let input_field = &args.arg_fields[0];
+ let out_dt = input_field.data_type().clone();
+ let mut out_nullable = input_field.is_nullable();
+
+ // If any scalar argument is explicitly null, output must be nullable
+ let scalar_null_present = args
+ .scalar_arguments
+ .iter()
+ .any(|opt_s| opt_s.is_some_and(|sv| sv.is_null()));
+
+ if scalar_null_present {
+ out_nullable = true;
+ }
Review Comment:
Is this scalar null check strictly required? If an input argument is scalar
null, then the datatype of that field would already be nullable, right?
##########
datafusion/spark/src/function/math/abs.rs:
##########
@@ -69,8 +70,35 @@ impl ScalarUDFImpl for SparkAbs {
&self.signature
}
- fn return_type(&self, arg_types: &[DataType]) -> Result<DataType> {
- Ok(arg_types[0].clone())
+ fn return_type(&self, _arg_types: &[DataType]) -> Result<DataType> {
+ internal_err!(
+ "SparkAbs: return_type() is not used; return_field_from_args() is
implemented"
+ )
+ }
+
+ fn return_field_from_args(&self, args: ReturnFieldArgs) ->
Result<FieldRef> {
+ if args.arg_fields.is_empty() {
+ return internal_err!(
+ "abs takes exactly 1 argument, but got: {}",
+ args.arg_fields.len()
+ );
+ }
Review Comment:
```suggestion
```
We don't need this check, signature guards us
--
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]