diff --git a/core/src/main/java/org/apache/calcite/sql/validate/SqlConformance.java b/core/src/main/java/org/apache/calcite/sql/validate/SqlConformance.java index 2e5a386ba32..e6493b3a091 100644 --- a/core/src/main/java/org/apache/calcite/sql/validate/SqlConformance.java +++ b/core/src/main/java/org/apache/calcite/sql/validate/SqlConformance.java @@ -155,6 +155,7 @@ public interface SqlConformance { *
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}, diff --git a/core/src/main/java/org/apache/calcite/sql/validate/SqlConformanceEnum.java b/core/src/main/java/org/apache/calcite/sql/validate/SqlConformanceEnum.java index 76786f4531a..dd564741034 100644 --- a/core/src/main/java/org/apache/calcite/sql/validate/SqlConformanceEnum.java +++ b/core/src/main/java/org/apache/calcite/sql/validate/SqlConformanceEnum.java @@ -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: diff --git a/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java b/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java index b2f91e384fc..d1dbdcfcb80 100644 --- a/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java +++ b/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java @@ -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(); }