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


##########
datafusion/functions/src/unicode/substrindex.rs:
##########
@@ -182,7 +182,8 @@ fn substr_index_general<
 where
     T::Native: OffsetSizeTrait,
 {
-    let mut builder = StringBuilder::new();
+    let num_rows = string_array.len();

Review Comment:
   If you wanted to make this really fast, you could also implement special 
case code for the common cases where `delimiter` and `count` were scalar values 
-- I suspect you could make it quite fast.



##########
datafusion/functions/src/unicode/substrindex.rs:
##########
@@ -198,31 +199,49 @@ where
                 }
 
                 let occurrences = 
usize::try_from(n.unsigned_abs()).unwrap_or(usize::MAX);
-                let length = if n > 0 {
-                    let split = string.split(delimiter);
-                    split
-                        .take(occurrences)
-                        .map(|s| s.len() + delimiter.len())
-                        .sum::<usize>()
-                        - delimiter.len()
-                } else {
-                    let split = string.rsplit(delimiter);
-                    split
-                        .take(occurrences)
-                        .map(|s| s.len() + delimiter.len())
-                        .sum::<usize>()
-                        - delimiter.len()
-                };
-                if n > 0 {
-                    match string.get(..length) {
-                        Some(substring) => builder.append_value(substring),
-                        None => builder.append_null(),
+                let result_idx = if delimiter.len() == 1 {

Review Comment:
   I double checked that this checks for length in bytes
   
   https://doc.rust-lang.org/std/string/struct.String.html#method.len



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