Skip to content

Commit

Permalink
[CALCITE-5191] Allow ORDER BY alias in BigQuery
Browse files Browse the repository at this point in the history
Close #2833
  • Loading branch information
wenruimeng authored and julianhyde committed Jun 20, 2022
1 parent de41df4 commit 1226d1a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ public interface SqlConformance {
* <p>Among the built-in conformance levels, true in
* {@link SqlConformanceEnum#DEFAULT},
* {@link SqlConformanceEnum#BABEL},
* {@link SqlConformanceEnum#BIG_QUERY},
* {@link SqlConformanceEnum#LENIENT},
* {@link SqlConformanceEnum#MYSQL_5},
* {@link SqlConformanceEnum#ORACLE_10},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ public enum SqlConformanceEnum implements SqlConformance {
case DEFAULT:
case BABEL:
case LENIENT:
case BIG_QUERY:
case MYSQL_5:
case ORACLE_10:
case ORACLE_12:
Expand Down
11 changes: 11 additions & 0 deletions core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6710,6 +6710,17 @@ public boolean isBangEqualAllowed() {
sql("select 'foo' as empno from emp order by empno + 5").ok();
}

/** Tests that you can reference a column alias in the ORDER BY clause if
* {@link SqlConformance#isSortByAlias()}. */
@Test void testOrderByAlias() {
sql("select count(*) as total from emp order by ^total^")
.ok()
.withConformance(SqlConformanceEnum.BIG_QUERY)
.ok()
.withConformance(SqlConformanceEnum.STRICT_2003)
.fails("Column 'TOTAL' not found in any table");
}

@Test void testOrderJoin() {
sql("select * from emp as e, dept as d order by e.empno").ok();
}
Expand Down

0 comments on commit 1226d1a

Please sign in to comment.