Skip to content

Commit

Permalink
Validate ordinal based grouping expressions during analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
phd3 committed Jun 10, 2021
1 parent 0593a8e commit 41ff64c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2858,6 +2858,7 @@ private GroupingSetAnalysis analyzeGroupBy(QuerySpecification node, Scope scope,
}

column = outputExpressions.get(toIntExact(ordinal - 1));
verifyNoAggregateWindowOrGroupingFunctions(metadata, column, "GROUP BY clause");
}
else {
verifyNoAggregateWindowOrGroupingFunctions(metadata, column, "GROUP BY clause");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,18 @@ public void testGroupByInvalidOrdinal()
.hasErrorCode(INVALID_COLUMN_REFERENCE);
}

@Test
public void testGroupByAggregation()
{
assertFails("SELECT x, sum(y) FROM (VALUES (1, 2)) t(x, y) GROUP BY x, sum(y)")
.hasErrorCode(EXPRESSION_NOT_SCALAR)
.hasMessageMatching(".* GROUP BY clause cannot contain aggregations, window functions or grouping operations: .*");

assertFails("SELECT x, sum(y) FROM (VALUES (1, 2)) t(x, y) GROUP BY 1, 2")
.hasErrorCode(EXPRESSION_NOT_SCALAR)
.hasMessageMatching(".* GROUP BY clause cannot contain aggregations, window functions or grouping operations: .*");
}

@Test
public void testGroupByWithSubquerySelectExpression()
{
Expand Down

0 comments on commit 41ff64c

Please sign in to comment.