Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate ordinal based grouping expressions during analysis #8247

Merged
merged 1 commit into from
Jun 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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