GitHub user hvanhovell opened a pull request:

    [SPARK-17616][SQL] Support a single distinct aggregate combined with a 
non-partial aggregate

    ## What changes were proposed in this pull request?
    We currently cannot execute an aggregate that contains a single distinct 
aggregate function and an one or more non-partially plannable aggregate 
functions, for example:
    select   grp, 
             count(distinct col2)
    from     tbl_a
    group by 1
    This is a regression from Spark 1.6. This is caused by the fact that the 
single distinct aggregation code path assumes that all aggregates can be 
planned in two phases (is partially aggregatable). This PR works around this 
issue by triggering the `RewriteDistinctAggregates` in such cases (this is 
similar to the approach taken in 1.6).
    ## How was this patch tested?
    Created `RewriteDistinctAggregatesSuite` which checks if the aggregates 
with distinct aggregate functions get rewritten into two `Aggregates` and an 
`Expand`. Added a regression test to `DataFrameAggregateSuite`.

You can merge this pull request into a Git repository by running:

    $ git pull SPARK-17616

Alternatively you can review and apply these changes as the patch at:

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #15187
commit 4a9ffaacac03070aa64baeb0a0e3b00d40865491
Author: Herman van Hovell <>
Date:   2016-09-21T22:11:56Z

    Add case to RewriteDistinctAggregates to rewrite a single distinct 
aggregate combined with a non-partial aggregate.


If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at or file a JIRA ticket
with INFRA.

To unsubscribe, e-mail:
For additional commands, e-mail:

Reply via email to