Skip to content

Commit

Permalink
[FLINK-31836][table] Upgrade Calcite version to 1.34.0
Browse files Browse the repository at this point in the history
  • Loading branch information
snuyanzin committed Aug 29, 2024
1 parent addfb51 commit 2077fb1
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 20 deletions.
4 changes: 2 additions & 2 deletions flink-table/flink-sql-parser/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ under the License.
<version>${calcite.version}</version>
<exclusions>
<!--
"mvn dependency:tree" as of Calcite 1.33.0:
"mvn dependency:tree" as of Calcite 1.34.0:
[INFO] +- org.apache.calcite:calcite-core:jar:1.33.0:compile
[INFO] +- org.apache.calcite:calcite-core:jar:1.34.0:compile
[INFO] | +- org.apache.calcite.avatica:avatica-core:jar:1.23.0:compile
[INFO] | +- org.apiguardian:apiguardian-api:jar:1.1.2:compile
[INFO] | +- org.checkerframework:checker-qual:jar:3.12.0:compile
Expand Down
2 changes: 2 additions & 0 deletions flink-table/flink-sql-parser/src/main/codegen/data/Parser.tdd
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,8 @@
"CURSOR_NAME"
"DATA"
"DATABASE"
"DATE_DIFF"
"DATETIME_DIFF"
"DATETIME_INTERVAL_CODE"
"DATETIME_INTERVAL_PRECISION"
"DAYS"
Expand Down
148 changes: 138 additions & 10 deletions flink-table/flink-sql-parser/src/main/codegen/templates/Parser.jj
Original file line number Diff line number Diff line change
Expand Up @@ -1311,6 +1311,7 @@ SqlSelect SqlSelect() :
final SqlNodeList groupBy;
final SqlNode having;
final SqlNodeList windowDecls;
final SqlNode qualify;
final List<SqlNode> hints = new ArrayList<SqlNode>();
final Span s;
}
Expand All @@ -1337,20 +1338,22 @@ SqlSelect SqlSelect() :
( groupBy = GroupBy() | { groupBy = null; } )
( having = Having() | { having = null; } )
( windowDecls = Window() | { windowDecls = null; } )
( qualify = Qualify() | { qualify = null; } )
|
E() {
fromClause = null;
where = null;
groupBy = null;
having = null;
windowDecls = null;
qualify = null;
}
)
{
return new SqlSelect(s.end(this), keywordList,
new SqlNodeList(selectList, Span.of(selectList).pos()),
fromClause, where, groupBy, having, windowDecls, null, null, null,
new SqlNodeList(hints, getPos()));
fromClause, where, groupBy, having, windowDecls, qualify,
null, null, null, new SqlNodeList(hints, getPos()));
}
}

Expand Down Expand Up @@ -2773,6 +2776,15 @@ SqlNode WindowRange() :
)
}

/** Parses a QUALIFY clause for SELECT. */
SqlNode Qualify() :
{
SqlNode e;
}
{
<QUALIFY> e = Expression(ExprContext.ACCEPT_SUB_QUERY) { return e; }
}

/**
* Parses an ORDER BY clause.
*/
Expand Down Expand Up @@ -4033,6 +4045,7 @@ SqlNode AtomicRowExpression() :
}
{
(
LOOKAHEAD(2)
e = LiteralOrIntervalExpression()
|
e = DynamicParam()
Expand Down Expand Up @@ -4629,6 +4642,28 @@ SqlLiteral DateTimeLiteral() :
}
}

/** Parses a Date/Time constructor function, for example "DATE(1969, 7, 21)"
* or "DATETIME(d, t)". Enabled in some libraries (e.g. BigQuery). */
SqlNode DateTimeConstructorCall() :
{
final SqlFunctionCategory funcType = SqlFunctionCategory.TIMEDATE;
final SqlIdentifier qualifiedName;
final Span s;
final SqlLiteral quantifier;
final List<? extends SqlNode> args;
}
{
(<DATE> | <TIME> | <DATETIME> | <TIMESTAMP>) {
s = span();
qualifiedName = new SqlIdentifier(unquotedIdentifier(), getPos());
}
args = FunctionParameterList(ExprContext.ACCEPT_SUB_QUERY) {
quantifier = (SqlLiteral) args.get(0);
args.remove(0);
return createCall(qualifiedName, s.end(this), funcType, quantifier, args);
}
}

/** Parses a MULTISET constructor */
SqlNode MultisetConstructor() :
{
Expand Down Expand Up @@ -5047,13 +5082,42 @@ SqlIntervalQualifier IntervalQualifierStart() :
* registered as abbreviations in your time frame set.
*/
SqlIntervalQualifier TimeUnitOrName() : {
final Span span;
final String w;
final TimeUnit unit;
final SqlIdentifier unitName;
final SqlIntervalQualifier intervalQualifier;
}
{
// When we see a time unit that is also a non-reserved keyword, such as
// NANOSECOND, there is a choice between using the TimeUnit enum
// (TimeUnit.NANOSECOND) or the name. The following LOOKAHEAD directive
// tells the parser that we prefer the former.
//
// Reserved keywords, such as SECOND, cannot be identifiers, and are
// therefore not ambiguous.
LOOKAHEAD(2)
intervalQualifier = TimeUnit() {
return intervalQualifier;
}
| unitName = SimpleIdentifier() {
return new SqlIntervalQualifier(unitName.getSimple(),
unitName.getParserPosition());
}
}

/** Parses a built-in time unit (e.g. "YEAR")
* and returns a {@link SqlIntervalQualifier}.
*
* <p>Includes {@code WEEK} and {@code WEEK(SUNDAY)} through
{@code WEEK(SATURDAY)}.
*
* <p>Does not include SQL_TSI_DAY, SQL_TSI_FRAC_SECOND etc. These will be
* parsed as identifiers and can be resolved in the validator if they are
* registered as abbreviations in your time frame set.
*/
SqlIntervalQualifier TimeUnit() : {
final Span span;
final String w;
}
{
<NANOSECOND> { return new SqlIntervalQualifier(TimeUnit.NANOSECOND, null, getPos()); }
| <MICROSECOND> { return new SqlIntervalQualifier(TimeUnit.MICROSECOND, null, getPos()); }
| <MILLISECOND> { return new SqlIntervalQualifier(TimeUnit.MILLISECOND, null, getPos()); }
Expand All @@ -5067,6 +5131,8 @@ SqlIntervalQualifier TimeUnitOrName() : {
| <ISOYEAR> { return new SqlIntervalQualifier(TimeUnit.ISOYEAR, null, getPos()); }
| <WEEK> { span = span(); }
(
// There is a choice between "WEEK(weekday)" and "WEEK". We prefer
// the former, and the parser will look ahead for '('.
LOOKAHEAD(2)
<LPAREN> w = weekdayName() <RPAREN> {
return new SqlIntervalQualifier(w, span.end(this));
Expand All @@ -5081,10 +5147,6 @@ SqlIntervalQualifier TimeUnitOrName() : {
| <DECADE> { return new SqlIntervalQualifier(TimeUnit.DECADE, null, getPos()); }
| <CENTURY> { return new SqlIntervalQualifier(TimeUnit.CENTURY, null, getPos()); }
| <MILLENNIUM> { return new SqlIntervalQualifier(TimeUnit.MILLENNIUM, null, getPos()); }
| unitName = SimpleIdentifier() {
return new SqlIntervalQualifier(unitName.getSimple(),
unitName.getParserPosition());
}
}

String weekdayName() :
Expand Down Expand Up @@ -6085,10 +6147,16 @@ SqlNode BuiltinFunctionCall() :
<RPAREN> {
return SqlStdOperatorTable.TRIM.createCall(s.end(this), args);
}
|
node = DateTimeConstructorCall() { return node; }
|
node = DateDiffFunctionCall() { return node; }
|
node = DateTruncFunctionCall() { return node; }
|
node = TimestampAddFunctionCall() { return node; }
|
node = DatetimeDiffFunctionCall() { return node; }
|
node = TimestampDiffFunctionCall() { return node; }
|
Expand Down Expand Up @@ -6603,6 +6671,28 @@ SqlCall JsonArrayAggFunctionCall() :
}
}

/**
* Parses a call to BigQuery's DATE_DIFF.
*/
SqlCall DateDiffFunctionCall() :
{
final List<SqlNode> args = new ArrayList<SqlNode>();
final Span s;
final SqlIntervalQualifier unit;
}
{
<DATE_DIFF> { s = span(); }
<LPAREN>
AddExpression(args, ExprContext.ACCEPT_SUB_QUERY)
<COMMA>
AddExpression(args, ExprContext.ACCEPT_SUB_QUERY)
<COMMA>
unit = TimeUnitOrName() { args.add(unit); }
<RPAREN> {
return SqlLibraryOperators.DATE_DIFF.createCall(s.end(this), args);
}
}

/**
* Parses a call to TIMESTAMPADD.
*/
Expand Down Expand Up @@ -6676,6 +6766,28 @@ SqlCall TimestampDiff3FunctionCall() :
}
}

/**
* Parses BigQuery's built-in DATETIME_DIFF() function.
*/
SqlCall DatetimeDiffFunctionCall() :
{
final List<SqlNode> args = new ArrayList<SqlNode>();
final Span s;
final SqlIntervalQualifier unit;
}
{
<DATETIME_DIFF> { s = span(); }
<LPAREN>
AddExpression(args, ExprContext.ACCEPT_SUB_QUERY)
<COMMA>
AddExpression(args, ExprContext.ACCEPT_SUB_QUERY)
<COMMA>
unit = TimeUnitOrName() { args.add(unit); }
<RPAREN> {
return SqlLibraryOperators.DATETIME_DIFF.createCall(s.end(this), args);
}
}

/**
* Parses a call to DATE_TRUNC.
*/
Expand All @@ -6694,7 +6806,8 @@ SqlCall DateTruncFunctionCall() :
// the BigQuery variant, e.g. "DATE_TRUNC(d, YEAR)",
// and the Redshift variant, e.g. "DATE_TRUNC('year', DATE '2008-09-08')".
(
unit = TimeUnitOrName() { args.add(unit); }
LOOKAHEAD(2)
unit = TimeUnit() { args.add(unit); }
|
AddExpression(args, ExprContext.ACCEPT_SUB_QUERY)
)
Expand Down Expand Up @@ -7252,6 +7365,18 @@ SqlNode JdbcFunctionCall() :
s = span();
}
(
LOOKAHEAD(1)
call = DateDiffFunctionCall() {
name = call.getOperator().getName();
args = new SqlNodeList(call.getOperandList(), getPos());
}
|
LOOKAHEAD(1)
call = DatetimeDiffFunctionCall() {
name = call.getOperator().getName();
args = new SqlNodeList(call.getOperandList(), getPos());
}
|
LOOKAHEAD(1)
call = TimestampAddFunctionCall() {
name = call.getOperator().getName();
Expand Down Expand Up @@ -7658,8 +7783,10 @@ SqlPostfixOperator PostfixRowOperator() :
| < DATE: "DATE" >
| < DATE_TRUNC: "DATE_TRUNC" >
| < DATETIME: "DATETIME" >
| < DATETIME_DIFF: "DATETIME_DIFF" >
| < DATETIME_INTERVAL_CODE: "DATETIME_INTERVAL_CODE" >
| < DATETIME_INTERVAL_PRECISION: "DATETIME_INTERVAL_PRECISION" >
| < DATE_DIFF: "DATE_DIFF" >
| < DAY: "DAY" >
| < DAYS: "DAYS" >
| < DEALLOCATE: "DEALLOCATE" >
Expand Down Expand Up @@ -7958,6 +8085,7 @@ SqlPostfixOperator PostfixRowOperator() :
| < PRIVILEGES: "PRIVILEGES" >
| < PROCEDURE: "PROCEDURE" >
| < PUBLIC: "PUBLIC" >
| < QUALIFY: "QUALIFY" >
| < QUARTER: "QUARTER" >
| < QUARTERS: "QUARTERS" >
| < RANGE: "RANGE" >
Expand Down
8 changes: 4 additions & 4 deletions flink-table/flink-table-calcite-bridge/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ under the License.
<version>${calcite.version}</version>
<exclusions>
<!--
"mvn dependency:tree" as of Calcite 1.33.0:
[INFO] +- org.apache.calcite:calcite-core:jar:1.33.0:compile
[INFO] | +- org.apache.calcite:calcite-linq4j:jar:1.33.0:compile
"mvn dependency:tree" as of Calcite 1.34.0:
[INFO] +- org.apache.calcite:calcite-core:jar:1.34.0:compile
[INFO] | +- org.apache.calcite:calcite-linq4j:jar:1.34.0:compile
[INFO] | +- org.locationtech.jts:jts-core:jar:1.19.0:compile
[INFO] | +- com.fasterxml.jackson.core:jackson-annotations:jar:2.15.3:compile
[INFO] | +- org.apache.calcite.avatica:avatica-core:jar:1.23.0:compile
Expand All @@ -60,7 +60,7 @@ under the License.
[INFO] | | \- org.ow2.asm:asm:jar:9.1:runtime
[INFO] | +- commons-codec:commons-codec:jar:1.15:runtime
[INFO] | +- org.apache.commons:commons-math3:jar:3.6.1:runtime
[INFO] | \- commons-io:commons-io:jar:2.11.0:runtime
[INFO] | \- commons-io:commons-io:jar:2.15.1:runtime
Dependencies that are not needed for how we use Calcite right now.
-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ This project bundles the following dependencies under the Apache Software Licens

- com.google.guava:guava:32.1.3-jre
- com.google.guava:failureaccess:1.0.1
- org.apache.calcite:calcite-core:1.33.0
- org.apache.calcite:calcite-linq4j:1.33.0
- org.apache.calcite:calcite-core:1.34.0
- org.apache.calcite:calcite-linq4j:1.34.0
- org.apache.calcite.avatica:avatica-core:1.23.0
- org.apache.commons:commons-math3:3.6.1
- commons-codec:commons-codec:1.15
Expand Down
4 changes: 2 additions & 2 deletions flink-table/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ under the License.
</dependencyManagement>

<properties>
<calcite.version>1.33.0</calcite.version>
<!-- Calcite 1.33.0 depends on 3.1.8,
<calcite.version>1.34.0</calcite.version>
<!-- Calcite 1.34.0 depends on 3.1.8,
at the same time minimum 3.1.x Janino version passing Flink tests without WAs is 3.1.10,
more details are in FLINK-27995 -->
<janino.version>3.1.10</janino.version>
Expand Down

0 comments on commit 2077fb1

Please sign in to comment.