Skip to content

Conversation

@Lordworms
Copy link
Contributor

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?

@github-actions github-actions bot added the functions Changes to functions implementation label Aug 21, 2024
Copy link
Contributor

@alamb alamb left a 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>(
Copy link
Contributor

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::<
Copy link
Contributor

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()) {
Copy link
Contributor

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>(
Copy link
Contributor

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

@alamb alamb merged commit beb3d5a into apache:main Aug 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

functions Changes to functions implementation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use GenericStringBuilder to improve performance of UDF split_part

2 participants