perf: Optimize string_to_array for scalar args#21131
Open
neilconway wants to merge 7 commits intoapache:mainfrom
Open
perf: Optimize string_to_array for scalar args#21131neilconway wants to merge 7 commits intoapache:mainfrom
string_to_array for scalar args#21131neilconway wants to merge 7 commits intoapache:mainfrom
Conversation
neilconway
commented
Mar 23, 2026
| Ok(()) | ||
| } | ||
|
|
||
| /// String_to_array SQL function |
Contributor
Author
There was a problem hiding this comment.
I had to move some code around to group the string_to_array functions together in the file, sorry for the noisy diff.
neilconway
commented
Mar 23, 2026
| list_builder.append(true); | ||
| } | ||
| (Some(string), None) => { | ||
| string.chars().map(|c| c.to_string()).for_each(|c| { |
Contributor
Author
There was a problem hiding this comment.
This was the inefficient NULL delimiter handling mentioned in the PR summary.
comphead
reviewed
Mar 26, 2026
comphead
reviewed
Mar 26, 2026
comphead
reviewed
Mar 26, 2026
Comment on lines
+514
to
+527
| fn get_str_value(array: &ArrayRef, i: usize) -> Option<&str> { | ||
| if array.is_null(i) { | ||
| return None; | ||
| } | ||
| match array.data_type() { | ||
| Utf8 => Some(array.as_string::<i32>().value(i)), | ||
| LargeUtf8 => Some(array.as_string::<i64>().value(i)), | ||
| Utf8View => Some(array.as_string_view().value(i)), | ||
| other => { | ||
| debug_assert!(false, "unexpected type in get_str_value: {other:?}"); | ||
| None | ||
| } | ||
| } | ||
| } |
Contributor
There was a problem hiding this comment.
Suggested change
| fn get_str_value(array: &ArrayRef, i: usize) -> Option<&str> { | |
| if array.is_null(i) { | |
| return None; | |
| } | |
| match array.data_type() { | |
| Utf8 => Some(array.as_string::<i32>().value(i)), | |
| LargeUtf8 => Some(array.as_string::<i64>().value(i)), | |
| Utf8View => Some(array.as_string_view().value(i)), | |
| other => { | |
| debug_assert!(false, "unexpected type in get_str_value: {other:?}"); | |
| None | |
| } | |
| } | |
| } | |
| #[inline] | |
| fn get_str_value<O: OffsetSizeTrait>( | |
| array: &GenericStringArray<O>, | |
| i: usize, | |
| ) -> Option<&str> { | |
| if array.is_null(i) { | |
| None | |
| } else { | |
| Some(array.value(i)) | |
| } | |
| } |
Contributor
Author
There was a problem hiding this comment.
Thanks for the suggestion! However, GenericStringArray doesn't handle StringViewArray; the current approach was overall the cleanest way I could think of, but let me know if you know of a better way to do this.
comphead
reviewed
Mar 26, 2026
Contributor
comphead
left a comment
There was a problem hiding this comment.
Thanks @neilconway I left some comments but i didn't check its performace
Contributor
Author
|
@comphead Thanks for the review! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
string_to_arrayfor scalar args #21129.Rationale for this change
When the delimiter (and null string, if supplied) are scalars, we can implement
string_to_arraymore efficiently. In particular, we can construct amemmem::Finderand use it to search for delimiters more efficiently.This PR implements this optimization; it also fixes a place where we were allocating an intermediate
Stringfor every character when the delimiter isNULL. (This isn't a common case but worth fixing.)Benchmarks (M4 Max):
What changes are included in this PR?
string_to_arrayAre these changes tested?
Yes.
Are there any user-facing changes?
No.