comphead commented on code in PR #21131:
URL: https://github.com/apache/datafusion/pull/21131#discussion_r2997691314
##########
datafusion/functions-nested/src/string.rs:
##########
@@ -242,13 +248,77 @@ impl ScalarUDFImpl for StringToArray {
}
fn invoke_with_args(&self, args: ScalarFunctionArgs) ->
Result<ColumnarValue> {
- let args = &args.args;
- match args[0].data_type() {
- Utf8 | Utf8View =>
make_scalar_function(string_to_array_inner::<i32>)(args),
- LargeUtf8 =>
make_scalar_function(string_to_array_inner::<i64>)(args),
+ let ScalarFunctionArgs { args, .. } = args;
+
+ let delimiter_is_scalar = matches!(&args[1], ColumnarValue::Scalar(_));
+ let null_str_is_scalar = args
+ .get(2)
+ .is_none_or(|a| matches!(a, ColumnarValue::Scalar(_)));
+
+ if !(delimiter_is_scalar && null_str_is_scalar) {
+ return make_scalar_function(string_to_array_fallback)(&args);
+ }
+
+ // Delimiter and null_str (if given) are scalar, so use the fast path
+ let delimiter = match &args[1] {
+ ColumnarValue::Scalar(s) => match s.try_as_str() {
+ Some(s) => s,
+ None => {
+ return exec_err!(
+ "unsupported type for string_to_array delimiter: {:?}",
+ args[1].data_type()
+ );
+ }
+ },
+ _ => unreachable!("delimiter must be scalar in this branch"),
+ };
Review Comment:
```suggestion
let delimiter = match &args[1] {
ColumnarValue::Scalar(s) => s.try_as_str().ok_or_else(|| {
exec_err!(
"unsupported type for string_to_array delimiter: {:?}",
args[1].data_type()
)
})?,
_ => unreachable!("delimiter must be scalar in this branch"),
};
```
##########
datafusion/functions-nested/src/string.rs:
##########
@@ -242,13 +248,77 @@ impl ScalarUDFImpl for StringToArray {
}
fn invoke_with_args(&self, args: ScalarFunctionArgs) ->
Result<ColumnarValue> {
- let args = &args.args;
- match args[0].data_type() {
- Utf8 | Utf8View =>
make_scalar_function(string_to_array_inner::<i32>)(args),
- LargeUtf8 =>
make_scalar_function(string_to_array_inner::<i64>)(args),
+ let ScalarFunctionArgs { args, .. } = args;
+
+ let delimiter_is_scalar = matches!(&args[1], ColumnarValue::Scalar(_));
+ let null_str_is_scalar = args
+ .get(2)
+ .is_none_or(|a| matches!(a, ColumnarValue::Scalar(_)));
+
+ if !(delimiter_is_scalar && null_str_is_scalar) {
+ return make_scalar_function(string_to_array_fallback)(&args);
+ }
+
+ // Delimiter and null_str (if given) are scalar, so use the fast path
+ let delimiter = match &args[1] {
+ ColumnarValue::Scalar(s) => match s.try_as_str() {
+ Some(s) => s,
+ None => {
+ return exec_err!(
+ "unsupported type for string_to_array delimiter: {:?}",
+ args[1].data_type()
+ );
+ }
+ },
+ _ => unreachable!("delimiter must be scalar in this branch"),
+ };
+ let null_value = match args.get(2) {
+ Some(ColumnarValue::Scalar(s)) => match s.try_as_str() {
Review Comment:
same
--
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]