-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Improve split_part udf by using a GenericStringBuilder #12093
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
alamb
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great to me -- thank you @Lordworms
I had some suggestions that could possibly make this PR better, but overall this look pretty good to me
| .map(|((string, delimiter), n)| match (string, delimiter, n) { | ||
| /// Splits string at occurrences of delimiter and returns the n'th field (counting from one). | ||
| /// split_part('abc~@~def~@~ghi', '~@~', 2) = 'def' | ||
| pub fn split_part<StringArrayLen: OffsetSizeTrait, DelimiterArrayLen: OffsetSizeTrait>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😍 love the function rather than macro
| n_array, | ||
| ) | ||
| } | ||
| (_, DataType::Utf8View) => split_part_impl::< |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I almost wonder if it would be simpler to call spit_part_impl directly from invoke
This extra level of indirection does save some repetition, but it might be clearer if all the possible combination of argument types were simply specified directly
|
|
||
| // 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()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice
| .zip($n_array.iter()) | ||
| .map(|((string, delimiter), n)| match (string, delimiter, n) { | ||
| /// impl | ||
| pub fn split_part_impl<'a, StringArrType, DelimiterArrType, StringArrayLen>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a nice pattern. Thanks @Lordworms
Which issue does this PR close?
Closes #12084
Rationale for this change
What changes are included in this PR?
Are these changes tested?
Are there any user-facing changes?