Skip to content

Commit

Permalink
[CALCITE-5191] Allow sort by alias in BigQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
wenruimeng authored and chunweilei committed Jun 20, 2022
1 parent de41df4 commit fa65a2e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ public enum SqlConformanceEnum implements SqlConformance {
case ORACLE_12:
case STRICT_92:
case SQL_SERVER_2008:
case BIG_QUERY:
return true;
default:
return false;
Expand Down
16 changes: 11 additions & 5 deletions core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
import java.util.Objects;
import java.util.function.Consumer;

import static org.apache.calcite.sql.validate.SqlConformanceEnum.BIG_QUERY;
import static org.apache.calcite.test.Matchers.isCharset;

import static org.hamcrest.CoreMatchers.equalTo;
Expand Down Expand Up @@ -369,7 +370,7 @@ static SqlOperatorTable operatorTableFor(SqlLibrary library) {
@Test void testNiladicForBigQuery() {
sql("select current_time, current_time(), current_date, "
+ "current_date(), current_timestamp, current_timestamp()")
.withConformance(SqlConformanceEnum.BIG_QUERY).ok();
.withConformance(BIG_QUERY).ok();
}

@Test void testEqualNotEqual() {
Expand Down Expand Up @@ -1533,21 +1534,21 @@ public void _testLikeAndSimilarFails() {
@Test void testCurrentDatetime() throws SqlParseException, ValidationException {
final String currentDateTimeExpr = "select ^current_datetime^";
SqlValidatorFixture shouldFail = sql(currentDateTimeExpr)
.withConformance(SqlConformanceEnum.BIG_QUERY);
.withConformance(BIG_QUERY);
final String expectedError = "query [select CURRENT_DATETIME]; exception "
+ "[Column 'CURRENT_DATETIME' not found in any table]; class "
+ "[class org.apache.calcite.sql.validate.SqlValidatorException]; pos [line 1 col 8 thru line 1 col 8]";
shouldFail.fails("Column 'CURRENT_DATETIME' not found in any table");

final SqlOperatorTable opTable = operatorTableFor(SqlLibrary.BIG_QUERY);
sql("select current_datetime()")
.withConformance(SqlConformanceEnum.BIG_QUERY)
.withConformance(BIG_QUERY)
.withOperatorTable(opTable).ok();
sql("select CURRENT_DATETIME('America/Los_Angeles')")
.withConformance(SqlConformanceEnum.BIG_QUERY)
.withConformance(BIG_QUERY)
.withOperatorTable(opTable).ok();
sql("select CURRENT_DATETIME(CAST(NULL AS VARCHAR(20)))")
.withConformance(SqlConformanceEnum.BIG_QUERY)
.withConformance(BIG_QUERY)
.withOperatorTable(opTable).ok();
}

Expand Down Expand Up @@ -7354,6 +7355,11 @@ public void _testGroupExpressionEquivalenceParams() {
sql("select deptno as d, count(*) as c from emp group by deptno").ok();
}

@Test void testSortByAliasColumnBigQuery() {
sql("select count(*) as total from emp order by total").withConformance(BIG_QUERY).ok();
}


@Test void testNestedAggFails() {
// simple case
sql("select ^sum(max(empno))^ from emp")
Expand Down

0 comments on commit fa65a2e

Please sign in to comment.