Skip to content

Reduce duplication between BoundedAggregateStream and GroupedHashAggregateStream #6798

Closed

Description

@alamb

Is your feature request related to a problem or challenge?

We are trying to make hash based aggregation significantly faster -- see #4973

This will require some non trivial changes to the organization of how hash aggregation works. At the moment BoundedAggregateStream and GroupedHashAggregateStream both share significant amounts of code and so either we will have to duplicate the work to make hashing aggregation faster or else BoundedAggregateStream will not get the benefits.

Here is a visual depiction of the common code:

 meld datafusion/core/src/physical_plan/aggregates/bounded_aggregate_stream.rs datafusion/core/src/physical_plan/aggregates/row_hash.rs 

Screenshot 2023-06-29 at 9 16 18 AM

Describe the solution you'd like

Reduce duplication between BoundedAggregateStream and GroupedHashAggregateStream

The major differences are:

  1. Choice of when output can be emitted
  2. Clearing previous group state when groups have been emitted

Describe alternatives you've considered

No response

Additional context

No response

Activity

  1. alamb commented on Jun 29, 2023

    @alamb
    ContributorAuthor

    I wonder if you have any thoughts on this proposal @metesynnada and @mustafasrepo ?

  2. mustafasrepo commented on Jul 3, 2023

    @mustafasrepo
    Contributor

    During streaming support for aggregation I tried to reduce duplication between BoundedAggregateStream and GroupedHashAggregateStream. However, it reduced performance for some queries as seen in discussion

    However, I think to benefit both implementations with the following major change. It is better to reduce duplication as much as possible even if it introduces minor overhead during benchmarks.

  3. alamb commented on Jul 3, 2023

    @alamb
    ContributorAuthor

    Thanks for the comments @mustafasrepo -- I have been studying the code and I am confident I can reduce the duplication. I hope to have a PR ready for review that brings us in this direction in a few days.

  4. self-assigned this
    on Jul 3, 2023
  5. alamb commented on Jul 3, 2023

    @alamb
    ContributorAuthor

    I plan to do this

  6. alamb commented on Jul 7, 2023

    @alamb
    ContributorAuthor

    I have completed my study of the code -- and I added some comments here #6881

    Rather than try and consolidate the BoundedAggregateStream on main, what I think I would like to do is to merge in the new GroupByHash implementation - #4973 and then remove BoundedAggregateStream by porting its functionality to the new hash stream

  7. alamb commented on Jul 15, 2023

    @alamb
    ContributorAuthor

    I have a PR ready that consolidates the logic which I am quite pleased with: #6932

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions