alamb commented on code in PR #21119:
URL: https://github.com/apache/datafusion/pull/21119#discussion_r3002353938


##########
datafusion/functions/src/string/split_part.rs:
##########
@@ -203,71 +197,93 @@ impl ScalarUDFImpl for SplitPartFunc {
     }
 }
 
-fn split_part_impl<'a, StringArrType, DelimiterArrType, StringArrayLen>(
+/// Finds the nth split part of `string` by `delimiter`.
+#[inline]
+fn split_nth<'a>(string: &'a str, delimiter: &str, n: usize) -> Option<&'a 
str> {
+    if delimiter.len() == 1 {

Review Comment:
   As a follow on, we can  probably hoist this check out of the loop (so call 
it once per batch rather than once per string) and see if that makes things any 
faster (sometimes it allows the compiler to optimize things better)



##########
datafusion/functions/src/string/split_part.rs:
##########
@@ -123,71 +126,62 @@ impl ScalarUDFImpl for SplitPartFunc {
 
         // Unpack the ArrayRefs from the arguments
         let n_array = as_int64_array(&args[2])?;
-        let result = match (args[0].data_type(), args[1].data_type()) {
-            (DataType::Utf8View, DataType::Utf8View) => {
-                split_part_impl::<&StringViewArray, &StringViewArray, i32>(
-                    &args[0].as_string_view(),
-                    &args[1].as_string_view(),
-                    n_array,
-                )
-            }
-            (DataType::Utf8View, DataType::Utf8) => {
-                split_part_impl::<&StringViewArray, &GenericStringArray<i32>, 
i32>(
-                    &args[0].as_string_view(),
-                    &args[1].as_string::<i32>(),
-                    n_array,
-                )
-            }
-            (DataType::Utf8View, DataType::LargeUtf8) => {
-                split_part_impl::<&StringViewArray, &GenericStringArray<i64>, 
i32>(
-                    &args[0].as_string_view(),
-                    &args[1].as_string::<i64>(),
-                    n_array,
-                )
-            }
-            (DataType::Utf8, DataType::Utf8View) => {
-                split_part_impl::<&GenericStringArray<i32>, &StringViewArray, 
i32>(
-                    &args[0].as_string::<i32>(),
-                    &args[1].as_string_view(),
-                    n_array,
-                )
-            }
-            (DataType::LargeUtf8, DataType::Utf8View) => {
-                split_part_impl::<&GenericStringArray<i64>, &StringViewArray, 
i64>(
-                    &args[0].as_string::<i64>(),
-                    &args[1].as_string_view(),
-                    n_array,
-                )
-            }
-            (DataType::Utf8, DataType::Utf8) => {
-                split_part_impl::<&GenericStringArray<i32>, 
&GenericStringArray<i32>, i32>(
-                    &args[0].as_string::<i32>(),
-                    &args[1].as_string::<i32>(),
-                    n_array,
-                )
-            }
-            (DataType::LargeUtf8, DataType::LargeUtf8) => {
-                split_part_impl::<&GenericStringArray<i64>, 
&GenericStringArray<i64>, i64>(
-                    &args[0].as_string::<i64>(),
-                    &args[1].as_string::<i64>(),
-                    n_array,
-                )
-            }
-            (DataType::Utf8, DataType::LargeUtf8) => {
-                split_part_impl::<&GenericStringArray<i32>, 
&GenericStringArray<i64>, i32>(
-                    &args[0].as_string::<i32>(),
-                    &args[1].as_string::<i64>(),
-                    n_array,
+
+        // Dispatch on delimiter type for a given string array and builder.
+        macro_rules! split_part_for_delimiter_type {
+            ($str_arr:expr, $builder:expr) => {
+                match args[1].data_type() {
+                    DataType::Utf8View => split_part_impl(
+                        $str_arr,
+                        &args[1].as_string_view(),

Review Comment:
   As a follow on, we can  probably make this even faster with a special, no 
copy implementation for Utf8View (reuse the same string buffers, but just 
adjust the views)



-- 
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]

Reply via email to