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

[CALCITE-5191] Allow sort by alias in BigQuery #2833

Merged
merged 1 commit into from
Jun 20, 2022
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 @@ -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