Skip to content

Commit

Permalink
[CALCITE-1873] In a "GROUP BY ordinal" query, validator gives invalid…
Browse files Browse the repository at this point in the history
… "Expression is not being grouped" error if column has alias

The solution is to ignore column aliases when validating a "GROUP BY
ordinal" query. Otherwise, you get an error like "Expression 'EMP.EMPNO'
is not being grouped" (see test case).

Close #490
  • Loading branch information
gianm authored and julianhyde committed Jul 6, 2017
1 parent 47c8df9 commit d4ab1e5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5415,7 +5415,7 @@ public SqlNode visit(SqlLiteral literal) {

// SQL ordinals are 1-based, but Sort's are 0-based
int ordinal = intValue - 1;
return select.getSelectList().get(ordinal);
return SqlUtil.stripAs(select.getSelectList().get(ordinal));
}
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6304,6 +6304,12 @@ public boolean isBangEqualAllowed() {
+ " group by 1,2")
.tester(strict).fails("Expression 'DEPTNO' is not being grouped")
.tester(lenient).sansCarets().ok();
sql("select ^empno^, count(*) from emp group by 1 order by 1")
.tester(strict).fails("Expression 'EMPNO' is not being grouped")
.tester(lenient).sansCarets().ok();
sql("select ^empno^ eno, count(*) from emp group by 1 order by 1")
.tester(strict).fails("Expression 'EMPNO' is not being grouped")
.tester(lenient).sansCarets().ok();
sql("select count(*) from (select 1 from emp"
+ " group by substring(ename from 2 for 3))")
.tester(strict).ok()
Expand Down

0 comments on commit d4ab1e5

Please sign in to comment.