Jefffrey commented on code in PR #22244:
URL: https://github.com/apache/datafusion/pull/22244#discussion_r3426089468
##########
datafusion/spark/src/function/string/concat.rs:
##########
@@ -71,28 +71,29 @@ impl ScalarUDFImpl for SparkConcat {
}
fn coerce_types(&self, arg_types: &[DataType]) -> Result<Vec<DataType>> {
- // Accept any string types, including zero arguments
- Ok(arg_types.to_vec())
+ if arg_types.is_empty() {
+ // Spark semantics: allow concat with zero arguments
+ Ok(vec![])
+ } else {
+ // Use concat coercion rules
+ ConcatFunc::new().coerce_types(arg_types)
+ }
}
fn return_type(&self, _arg_types: &[DataType]) -> Result<DataType> {
datafusion_common::internal_err!(
"return_type should not be called for Spark concat"
)
}
fn return_field_from_args(&self, args: ReturnFieldArgs<'_>) ->
Result<FieldRef> {
- use DataType::*;
-
// Spark semantics: concat returns NULL if ANY input is NULL
let nullable = args.arg_fields.iter().any(|f| f.is_nullable());
- // Determine return type: Utf8View > LargeUtf8 > Utf8
- let mut dt = &Utf8;
- for field in args.arg_fields {
- let data_type = field.data_type();
- if data_type == &Utf8View || (data_type == &LargeUtf8 && dt !=
&Utf8View) {
- dt = data_type;
- }
- }
+ let arg_types: Vec<DataType> = args
+ .arg_fields
+ .iter()
+ .map(|f| f.data_type().clone())
+ .collect();
+ let dt = ConcatFunc::new().return_type(&arg_types)?;
Ok(Arc::new(Field::new("concat", dt.clone(), nullable)))
Review Comment:
```suggestion
let field = ConcatFunc::new().return_field_from_args(args)?;
Ok(Arc::new(Field::new(
"concat",
field.data_type().clone(),
nullable,
)))
```
--
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]