Skip to content

Commit

Permalink
support select distinct with aggregate
Browse files Browse the repository at this point in the history
  • Loading branch information
924060929 committed May 14, 2024
1 parent 9195d79 commit fe4ee7b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2912,10 +2912,6 @@ private LogicalPlan withSelectQuerySpecification(
SelectColumnClauseContext selectColumnCtx = selectClause.selectColumnClause();
LogicalPlan aggregate = withAggregate(filter, selectColumnCtx, aggClause);
boolean isDistinct = (selectClause.DISTINCT() != null);
if (isDistinct && aggregate instanceof Aggregate) {
throw new ParseException("cannot combine SELECT DISTINCT with aggregate functions or GROUP BY",
selectClause);
}
if (!(aggregate instanceof Aggregate) && havingClause.isPresent()) {
// create a project node for pattern match of ProjectToGlobalAggregate rule
// then ProjectToGlobalAggregate rule can insert agg node as LogicalHaving node's child
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,13 @@ suite("window_function") {
left join adj_nullable_2 on c1 = c4
where c6 is not null;
"""

// distinct with window
sql """
SELECT
DISTINCT dt,
count(dt2) over (partition by dt) as num
from
(select 1 as dt,2 as dt2)t
group by dt,dt2"""
}

0 comments on commit fe4ee7b

Please sign in to comment.