comphead commented on code in PR #9973:
URL: https://github.com/apache/arrow-datafusion/pull/9973#discussion_r1555017714
##########
datafusion/functions/src/unicode/substrindex.rs:
##########
@@ -101,38 +101,151 @@ pub fn substr_index<T: OffsetSizeTrait>(args:
&[ArrayRef]) -> Result<ArrayRef> {
let delimiter_array = as_generic_string_array::<T>(&args[1])?;
let count_array = as_int64_array(&args[2])?;
- let result = string_array
+ let mut builder = StringBuilder::new();
+ string_array
.iter()
.zip(delimiter_array.iter())
.zip(count_array.iter())
- .map(|((string, delimiter), n)| match (string, delimiter, n) {
+ .for_each(|((string, delimiter), n)| match (string, delimiter, n) {
(Some(string), Some(delimiter), Some(n)) => {
// In MySQL, these cases will return an empty string.
if n == 0 || string.is_empty() || delimiter.is_empty() {
- return Some(String::new());
+ builder.append_value("");
+ return;
}
- let splitted: Box<dyn Iterator<Item = _>> = if n > 0 {
- Box::new(string.split(delimiter))
+ let occurrences =
usize::try_from(n.unsigned_abs()).unwrap_or(usize::MAX);
+ let length = if n > 0 {
+ let splitted = string.split(delimiter);
+ splitted
Review Comment:
can be done in follow up PR @kevinmingtarja
--
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]