Skip to content

Improve performance of min/max aggregates for Durations via GroupsAccumulator #15317

Closed

Description

@alamb

Is your feature request related to a problem or challenge?

@svranesevic implemented basic support for Min/Max Duration types in this PR: ❤

However, this only implements the slower "Accumulator" interface.
There is a faster GroupsAccumulator that would be really nice to implement as well as it will be faster for larger numbers of groups.

Describe the solution you'd like

See Notes on Implementing GroupsAccumulator for more detail

Describe alternatives you've considered

It basically involves

  1. adding the correct Durations type in the list of supported types (the one for max is here): https://github.com/apache/datafusion/blob/42ec5109bb4c6249d8404e862c457ebd86ee0623/datafusion/functions-aggregate/src/min_max.rs#L243-L242
  2. Instantiating an accumulator here: https://github.com/apache/datafusion/blob/42ec5109bb4c6249d8404e862c457ebd86ee0623/datafusion/functions-aggregate/src/min_max.rs#L270-L269
  3. Writing some tests (perhaps add a few more rows to the test added in Support Duration in min/max agg functions #15310)

Additional context

No response

Activity

  1. alamb commented on Mar 19, 2025

    @alamb
    ContributorAuthor

    I think this is a pretty good first issue as it is well described and self contained

  2. alamb commented on Mar 19, 2025

    @alamb
    ContributorAuthor

    BTW you can make durations in SQL like

    > create or replace table foo as select unnest (generate_series(now(), now() + interval '1 year', interval '1 day')) as "ts";
    0 row(s) fetched.
    Elapsed 0.005 seconds.
    
    > select now() - ts, arrow_typeof(now() - ts) as arrow_type from foo;
    +------------------------------------------------+----------------------+
    | now() - foo.ts                                 | arrow_type           |
    +------------------------------------------------+----------------------+
    | 0 days 0 hours 0 mins 26.882508000 secs        | Duration(Nanosecond) |
    | 0 days -23 hours -59 mins -33.117492000 secs   | Duration(Nanosecond) |
    | -1 days -23 hours -59 mins -33.117492000 secs  | Duration(Nanosecond) |
    | -2 days -23 hours -59 mins -33.117492000 secs  | Duration(Nanosecond) |
    | -3 days -23 hours -59 mins -33.117492000 secs  | Duration(Nanosecond) |
    | -4 days -23 hours -59 mins -33.117492000 secs  | Duration(Nanosecond) |
    | -5 days -23 hours -59 mins -33.117492000 secs  | Duration(Nanosecond) |
    | -6 days -23 hours -59 mins -33.117492000 secs  | Duration(Nanosecond) |
    | -7 days -23 hours -59 mins -33.117492000 secs  | Duration(Nanosecond) |
    | -8 days -23 hours -59 mins -33.117492000 secs  | Duration(Nanosecond) |
    | -9 days -23 hours -59 mins -33.117492000 secs  | Duration(Nanosecond) |
    | -10 days -23 hours -59 mins -33.117492000 secs | Duration(Nanosecond) |
    | -11 days -23 hours -59 mins -33.117492000 secs | Duration(Nanosecond) |
    | -12 days -23 hours -59 mins -33.117492000 secs | Duration(Nanosecond) |
    | -13 days -23 hours -59 mins -33.117492000 secs | Duration(Nanosecond) |
    | -14 days -23 hours -59 mins -33.117492000 secs | Duration(Nanosecond) |
    | -15 days -23 hours -59 mins -33.117492000 secs | Duration(Nanosecond) |
    | -16 days -23 hours -59 mins -33.117492000 secs | Duration(Nanosecond) |
    | -17 days -23 hours -59 mins -33.117492000 secs | Duration(Nanosecond) |
    | -18 days -23 hours -59 mins -33.117492000 secs | Duration(Nanosecond) |
    | -19 days -23 hours -59 mins -33.117492000 secs | Duration(Nanosecond) |
    | -20 days -23 hours -59 mins -33.117492000 secs | Duration(Nanosecond) |
    | -21 days -23 hours -59 mins -33.117492000 secs | Duration(Nanosecond) |
    | -22 days -23 hours -59 mins -33.117492000 secs | Duration(Nanosecond) |
    | -23 days -23 hours -59 mins -33.117492000 secs | Duration(Nanosecond) |
    | -24 days -23 hours -59 mins -33.117492000 secs | Duration(Nanosecond) |
    | -25 days -23 hours -59 mins -33.117492000 secs | Duration(Nanosecond) |
    | -26 days -23 hours -59 mins -33.117492000 secs | Duration(Nanosecond) |
    | -27 days -23 hours -59 mins -33.117492000 secs | Duration(Nanosecond) |
    | -28 days -23 hours -59 mins -33.117492000 secs | Duration(Nanosecond) |
    | -29 days -23 hours -59 mins -33.117492000 secs | Duration(Nanosecond) |
    | -30 days -23 hours -59 mins -33.117492000 secs | Duration(Nanosecond) |
    | -31 days -23 hours -59 mins -33.117492000 secs | Duration(Nanosecond) |
    | -32 days -23 hours -59 mins -33.117492000 secs | Duration(Nanosecond) |
    | -33 days -23 hours -59 mins -33.117492000 secs | Duration(Nanosecond) |
    | -34 days -23 hours -59 mins -33.117492000 secs | Duration(Nanosecond) |
    | -35 days -23 hours -59 mins -33.117492000 secs | Duration(Nanosecond) |
    | -36 days -23 hours -59 mins -33.117492000 secs | Duration(Nanosecond) |
    | -37 days -23 hours -59 mins -33.117492000 secs | Duration(Nanosecond) |
    | -38 days -23 hours -59 mins -33.117492000 secs | Duration(Nanosecond) |
    | .                                                                     |
    | .                                                                     |
    | .                                                                     |
    +------------------------------------------------+----------------------+
    366 row(s) fetched. (First 40 displayed. Use --maxrows to adjust)
    Elapsed 0.005 seconds.
  3. changed the title [-]Improve performance if min/max aggregates for Durations[/-] [+]Improve performance of min/max aggregates for Durations via GroupsAccumulator[/+] on Mar 19, 2025
  4. shruti2522 commented on Mar 19, 2025

    @shruti2522
    Contributor

    take

  5. alamb commented on Mar 19, 2025

    @alamb
    ContributorAuthor

    Thanks @shruti2522 -- you are crushing it of late

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 requestperformanceMake DataFusion faster

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions