Skip to content
Open
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
2 changes: 1 addition & 1 deletion flink-formats/flink-protobuf/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ under the License.

<properties>
<!-- the same with flink-table/pom.xml -->
<janino.version>3.1.10</janino.version>
<janino.version>3.1.12</janino.version>
</properties>

<dependencies>
Expand Down
6 changes: 3 additions & 3 deletions flink-table/flink-sql-parser/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ under the License.
<version>${calcite.version}</version>
<exclusions>
<!--
"mvn dependency:tree" as of Calcite 1.36.0:
"mvn dependency:tree" as of Calcite 1.37.0:

[INFO] +- org.apache.calcite:calcite-core:jar:1.36.0:compile
[INFO] | +- org.apache.calcite.avatica:avatica-core:jar:1.23.0:compile
[INFO] +- org.apache.calcite:calcite-core:jar:1.37.0:compile
[INFO] | +- org.apache.calcite.avatica:avatica-core:jar:1.25.0:compile
[INFO] | +- org.apiguardian:apiguardian-api:jar:1.1.2:compile
[INFO] | +- org.checkerframework:checker-qual:jar:3.37.0:compile
[INFO] | \- org.apache.commons:commons-math3:jar:3.6.1:runtime
Expand Down
100 changes: 74 additions & 26 deletions flink-table/flink-sql-parser/src/main/codegen/templates/Parser.jj
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ import org.apache.calcite.sql.SqlJsonQueryWrapperBehavior;
import org.apache.calcite.sql.SqlJsonValueEmptyOrErrorBehavior;
import org.apache.calcite.sql.SqlJsonValueReturning;
import org.apache.calcite.sql.SqlKind;
import org.apache.calcite.sql.SqlLambda;
import org.apache.calcite.sql.SqlLiteral;
import org.apache.calcite.sql.SqlMatchRecognize;
import org.apache.calcite.sql.SqlMerge;
Expand Down Expand Up @@ -1033,6 +1034,9 @@ void AddArg0(List<SqlNode> list, ExprContext exprContext) :
)
(
e = Default()
|
LOOKAHEAD((SimpleIdentifierOrList() | <LPAREN> <RPAREN>) <LAMBDA>)
e = LambdaExpression()
|
LOOKAHEAD(3)
e = TableParam()
Expand Down Expand Up @@ -1060,6 +1064,9 @@ void AddArg(List<SqlNode> list, ExprContext exprContext) :
)
(
e = Default()
|
LOOKAHEAD((SimpleIdentifierOrList() | <LPAREN> <RPAREN>) <LAMBDA>)
e = LambdaExpression()
|
e = Expression(exprContext)
|
Expand Down Expand Up @@ -3951,6 +3958,43 @@ SqlNode Expression3(ExprContext exprContext) :
}
}

/**
* Parses a lambda expression.
*/
SqlNode LambdaExpression() :
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we have a dummy test showing that it fails somewhere on validation rather than in runtime?

{
final SqlNodeList parameters;
final SqlNode expression;
final Span s;
}
{
parameters = SimpleIdentifierOrListOrEmpty()
<LAMBDA> { s = span(); }
expression = Expression(ExprContext.ACCEPT_NON_QUERY)
{
return new SqlLambda(s.end(this), parameters, expression);
}
}

/**
* List of simple identifiers in parentheses or empty parentheses or one simple identifier.
* <ul>Examples:
* <li>{@code ()}
* <li>{@code DEPTNO}
* <li>{@code (EMPNO, DEPTNO)}
* </ul>
*/
SqlNodeList SimpleIdentifierOrListOrEmpty() :
{
SqlNodeList list;
}
{
LOOKAHEAD(2)
<LPAREN> <RPAREN> { return SqlNodeList.EMPTY; }
|
list = SimpleIdentifierOrList() { return list; }
}

SqlOperator periodOperator() :
{
}
Expand Down Expand Up @@ -4742,6 +4786,7 @@ SqlLiteral DateTimeLiteral() :
{
final String p;
final Span s;
boolean local = false;
}
{
<LBRACE_D> <QUOTED_STRING> {
Expand Down Expand Up @@ -4773,6 +4818,7 @@ SqlLiteral DateTimeLiteral() :
return SqlLiteral.createUnknown("DATETIME", p, s.end(this));
}
|
LOOKAHEAD(2)
<TIME> { s = span(); } p = SimpleStringLiteral() {
return SqlLiteral.createUnknown("TIME", p, s.end(this));
}
Expand All @@ -4782,8 +4828,14 @@ SqlLiteral DateTimeLiteral() :
return SqlLiteral.createUnknown("TIMESTAMP", p, s.end(this));
}
|
<TIMESTAMP> { s = span(); } <WITH> <LOCAL> <TIME> <ZONE> p = SimpleStringLiteral() {
return SqlLiteral.createUnknown("TIMESTAMP WITH LOCAL TIME ZONE", p, s.end(this));
LOOKAHEAD(2)
<TIME> { s = span(); } <WITH> ( <LOCAL> { local = true; } )? <TIME> <ZONE> p = SimpleStringLiteral() {
return SqlLiteral.createUnknown("TIME WITH " + (local ? "LOCAL " : "") + "TIME ZONE", p, s.end(this));
}
|
LOOKAHEAD(2)
<TIMESTAMP> { s = span(); } <WITH> ( <LOCAL> { local = true; } )? <TIME> <ZONE> p = SimpleStringLiteral() {
return SqlLiteral.createUnknown("TIMESTAMP WITH " + (local ? "LOCAL " : "") + "TIME ZONE", p, s.end(this));
Comment on lines +4832 to +4838
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it now also supported for Flink?

}
}

Expand Down Expand Up @@ -6070,7 +6122,6 @@ SqlTypeNameSpec DateTimeTypeName() :
{
int precision = -1;
SqlTypeName typeName;
boolean withLocalTimeZone = false;
final Span s;
}
{
Expand All @@ -6082,25 +6133,15 @@ SqlTypeNameSpec DateTimeTypeName() :
LOOKAHEAD(2)
<TIME> { s = span(); }
precision = PrecisionOpt()
withLocalTimeZone = TimeZoneOpt()
typeName = TimeZoneOpt(true)
{
if (withLocalTimeZone) {
typeName = SqlTypeName.TIME_WITH_LOCAL_TIME_ZONE;
} else {
typeName = SqlTypeName.TIME;
}
return new SqlBasicTypeNameSpec(typeName, precision, s.end(this));
}
|
<TIMESTAMP> { s = span(); }
precision = PrecisionOpt()
withLocalTimeZone = TimeZoneOpt()
typeName = TimeZoneOpt(false)
{
if (withLocalTimeZone) {
typeName = SqlTypeName.TIMESTAMP_WITH_LOCAL_TIME_ZONE;
} else {
typeName = SqlTypeName.TIMESTAMP;
}
return new SqlBasicTypeNameSpec(typeName, precision, s.end(this));
}
}
Expand All @@ -6121,23 +6162,21 @@ int PrecisionOpt() :

/**
* Parse a time zone suffix for DateTime types. According to SQL-2011,
* "with time zone" and "without time zone" belong to standard SQL but we
* only implement the "without time zone".
*
* <p>We also support "with local time zone".
*
* @return true if this is "with local time zone".
* "with time zone" and "without time zone" belong to standard SQL.
* We also support "with local time zone".
*/
boolean TimeZoneOpt() :
SqlTypeName TimeZoneOpt(boolean timeType) :
{
boolean local = false;
}
{
LOOKAHEAD(3)
<WITHOUT> <TIME> <ZONE> { return false; }
<WITHOUT> <TIME> <ZONE> { return timeType ? SqlTypeName.TIME : SqlTypeName.TIMESTAMP; }
|
<WITH> <LOCAL> <TIME> <ZONE> { return true; }
<WITH> ( <LOCAL> { local = true; } )? <TIME> <ZONE> {
return timeType ? (local ? SqlTypeName.TIME_WITH_LOCAL_TIME_ZONE : SqlTypeName.TIME_TZ)
: (local ? SqlTypeName.TIMESTAMP_WITH_LOCAL_TIME_ZONE : SqlTypeName.TIMESTAMP_TZ); }
|
{ return false; }
{ return timeType ? SqlTypeName.TIME : SqlTypeName.TIMESTAMP; }
}

/**
Expand Down Expand Up @@ -6178,6 +6217,7 @@ SqlNode BuiltinFunctionCall() :
final SqlNode node;
final SqlLiteral style; // mssql convert 'style' operand
final SqlFunction f;
final SqlNode format;
}
{
//~ FUNCTIONS WITH SPECIAL SYNTAX ---------------------------------------
Expand All @@ -6194,6 +6234,7 @@ SqlNode BuiltinFunctionCall() :
|
<INTERVAL> e = IntervalQualifier() { args.add(e); }
)
[ <FORMAT> format = StringLiteral() { args.add(format); } ]
<RPAREN> {
return f.createCall(s.end(this), args);
}
Expand Down Expand Up @@ -6733,6 +6774,12 @@ List<SqlNode> JsonNameAndValue() :
}
(
<VALUE>
|
<COMMA> {
if (kvMode) {
throw SqlUtil.newContextException(getPos(), RESOURCE.illegalComma());
}
}
|
<COLON> {
if (kvMode) {
Expand Down Expand Up @@ -8834,6 +8881,7 @@ void NonReservedKeyWord2of3() :
| < NE2: "!=" >
| < PLUS: "+" >
| < MINUS: "-" >
| < LAMBDA: "->" >
| < STAR: "*" >
| < SLASH: "/" >
| < PERCENT_REMAINDER: "%" >
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package org.apache.calcite.sql;

import com.google.common.base.Preconditions;
import org.apache.calcite.sql.parser.SqlParserPos;
import org.apache.calcite.sql.type.SqlTypeName;
import org.apache.calcite.sql.util.SqlString;
Expand All @@ -28,6 +27,7 @@
import java.util.List;
import java.util.function.UnaryOperator;

import static com.google.common.base.Preconditions.checkArgument;
import static java.util.Objects.requireNonNull;

/** Parse tree node representing a {@code JOIN} clause. */
Expand Down Expand Up @@ -70,7 +70,7 @@ public SqlJoin(
this.conditionType = requireNonNull(conditionType, "conditionType");
this.condition = condition;

Preconditions.checkArgument(natural.getTypeName() == SqlTypeName.BOOLEAN);
checkArgument(natural.getTypeName() == SqlTypeName.BOOLEAN);
conditionType.getValueAs(JoinConditionType.class);
joinType.getValueAs(JoinType.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public enum SqlTypeFamily implements RelDataTypeFamily {
CURSOR,
COLUMN_LIST,
GEO,
FUNCTION,
VARIANT,
/** Like ANY, but do not even validate the operand. It may not be an expression. */
IGNORE;
Expand Down Expand Up @@ -173,10 +174,15 @@ public Collection<SqlTypeName> getTypeNames() {
case DATE:
return ImmutableList.of(SqlTypeName.DATE);
case TIME:
return ImmutableList.of(SqlTypeName.TIME, SqlTypeName.TIME_WITH_LOCAL_TIME_ZONE);
return ImmutableList.of(
SqlTypeName.TIME,
SqlTypeName.TIME_WITH_LOCAL_TIME_ZONE,
SqlTypeName.TIME_TZ);
case TIMESTAMP:
return ImmutableList.of(
SqlTypeName.TIMESTAMP, SqlTypeName.TIMESTAMP_WITH_LOCAL_TIME_ZONE);
SqlTypeName.TIMESTAMP,
SqlTypeName.TIMESTAMP_WITH_LOCAL_TIME_ZONE,
SqlTypeName.TIMESTAMP_TZ);
case BOOLEAN:
return SqlTypeName.BOOLEAN_TYPES;
case INTERVAL_YEAR_MONTH:
Expand Down Expand Up @@ -211,6 +217,8 @@ public Collection<SqlTypeName> getTypeNames() {
return ImmutableList.of(SqlTypeName.CURSOR);
case COLUMN_LIST:
return ImmutableList.of(SqlTypeName.COLUMN_LIST);
case FUNCTION:
return ImmutableList.of(SqlTypeName.FUNCTION);
case VARIANT:
return ImmutableList.of(SqlTypeName.VARIANT);
default:
Expand Down Expand Up @@ -269,6 +277,10 @@ public Collection<SqlTypeName> getTypeNames() {
return factory.createSqlType(SqlTypeName.CURSOR);
case COLUMN_LIST:
return factory.createSqlType(SqlTypeName.COLUMN_LIST);
case FUNCTION:
return factory.createFunctionSqlType(
factory.createStructType(ImmutableList.of(), ImmutableList.of()),
factory.createSqlType(SqlTypeName.ANY));
default:
return null;
}
Expand Down
Loading