Skip to content

Support complete distinct usage for aggregate expressions #2406

Open

Description

@WinkerDu

Is your feature request related to a problem or challenge? Please describe what you are trying to do.
Here are multiple aggregate expressions have not support distinct usage yet.
Though optimizer SingleDistinctToGroupBy (#1315) supports single distinct usage, there are more SQL scenes have not been covered, like

SELECT AVG(c1), SUM(DISTINCT c2) FROM test

I would like to take effort to work on the following tickets to complete distinct usage for aggregate expressions

Describe the solution you'd like
Adds specific aggregate expression support, like expressions::DistinctSum for sum(distinct)

Describe alternatives you've considered
No.

Additional context
No.

Activity

  1. WinkerDu commented on May 2, 2022

    @WinkerDu
    ContributorAuthor

    @andygrove @alamb can you please assign this issue to me? Thank you ❤️

  2. alamb commented on May 2, 2022

    @alamb
    Contributor

    @andygrove @alamb can you please assign this issue to me? Thank you ❤️

    Done -- thanks @WinkerDu

  3. Dandandan commented on Jun 1, 2026

    @Dandandan
    Contributor

    All done

  4. Jefffrey commented on Jun 1, 2026

    @Jefffrey
    Contributor

    I think there's still some that weren't listed here that still don't support distinct.

    Explicitly denies

    stddev

    fn accumulator(&self, acc_args: AccumulatorArgs) -> Result<Box<dyn Accumulator>> {
    if acc_args.is_distinct {
    return not_impl_err!("STDDEV_POP(DISTINCT) aggregations are not available");
    }
    Ok(Box::new(StddevAccumulator::try_new(StatsType::Sample)?))
    }

    approx_median

    fn accumulator(&self, acc_args: AccumulatorArgs) -> Result<Box<dyn Accumulator>> {
    if acc_args.is_distinct {
    return not_impl_err!(
    "APPROX_MEDIAN(DISTINCT) aggregations are not available"
    );
    }

    May be missing support

    These functions don't explicitly use the distinct flag to handle distinct specific behaviour, but depending on their semantics maybe distinct doesn't make sense for them? Anyway just listing them:

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

Metadata

Metadata

Assignees

No one assigned

    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