Skip to content
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

feat(udf): POC faster min max accumulator #12677

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

devanbenz
Copy link
Contributor

Which issue does this PR close?

Closes #6906

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 physical-expr Physical Expressions functions labels Sep 30, 2024
@devanbenz devanbenz marked this pull request as draft September 30, 2024 01:28

let input_array = &values[0];

for (i, &group_index) in group_indices.iter().enumerate() {
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 much of the filter logic is handled by accumulate_indices

accumulate_indices(
group_indices,
values.logical_nulls().as_ref(),
opt_filter,
|group_index| {
self.counts[group_index] += 1;
},
);

You could likely avoid much of this repetition (and likely it would be faster)

It woudl also be nice to avoid the duplication between min /max by using generics. Here is how the primitive one does it (passes in a comparison function)

https://github.com/apache/datafusion/blob/main/datafusion/functions-aggregate/src/min_max.rs#L119

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.

Thanks @devanbenz -- I think this is on the right track

What I suggest is:

  1. We start with StringArray (rather than StringViewArray)
  2. Run some benchmarks (clickbench) -- I can do this if it would help

All in all, thanks again

@devanbenz
Copy link
Contributor Author

@alamb thanks for taking a peek. Will go ahead and implement this for StringArray as well and modify the core functionality to lean on already existing methods + make it more generic so that MAX and MIN can share code. 🫡

@alamb
Copy link
Contributor

alamb commented Oct 1, 2024

BTW here is an example of using a const generic: #12703

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
functions physical-expr Physical Expressions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement fast min/max accumulator for binary / strings (now it uses the slower path)
2 participants