diff --git a/flink-formats/flink-protobuf/pom.xml b/flink-formats/flink-protobuf/pom.xml index 9ca5eea676287..5e8f9341882bf 100644 --- a/flink-formats/flink-protobuf/pom.xml +++ b/flink-formats/flink-protobuf/pom.xml @@ -36,7 +36,7 @@ under the License. - 3.1.11 + 3.1.12 diff --git a/flink-python/pyflink/table/tests/test_udf.py b/flink-python/pyflink/table/tests/test_udf.py index 182c46bbd9cf8..588add0ffba99 100644 --- a/flink-python/pyflink/table/tests/test_udf.py +++ b/flink-python/pyflink/table/tests/test_udf.py @@ -218,7 +218,7 @@ def udf_with_constant_params(p, null_param, tinyint_param, smallint_param, int_p "cast (1 as SMALLINT)," "cast (1 as INT)," "cast (1 as BIGINT)," - "cast (1.05 as DECIMAL)," + "cast (1.05 as DECIMAL(3,2))," "cast (1.23 as FLOAT)," "cast (1.98932 as DOUBLE)," "true," diff --git a/flink-table/flink-sql-parser/pom.xml b/flink-table/flink-sql-parser/pom.xml index 366d6d8ea1f2f..9a682e56e0846 100644 --- a/flink-table/flink-sql-parser/pom.xml +++ b/flink-table/flink-sql-parser/pom.xml @@ -68,14 +68,15 @@ under the License. ${calcite.version} diff --git a/flink-table/flink-sql-parser/src/main/codegen/data/Parser.tdd b/flink-table/flink-sql-parser/src/main/codegen/data/Parser.tdd index 1b73936914928..b7e6d7ab9ea3f 100644 --- a/flink-table/flink-sql-parser/src/main/codegen/data/Parser.tdd +++ b/flink-table/flink-sql-parser/src/main/codegen/data/Parser.tdd @@ -185,7 +185,6 @@ "org.apache.calcite.sql.SqlDrop" "org.apache.calcite.sql.SqlExplicitModelOperator" "org.apache.calcite.sql.SqlIntervalLiteral" - "org.apache.calcite.sql.SqlLambda" "org.apache.calcite.runtime.Resources" "java.util.ArrayList" "java.util.Collections" @@ -634,6 +633,7 @@ "OVERWRITING" "PARTITIONED" "PARTITIONS" + "UUID" "VIRTUAL" "ANALYZE" "COMPUTE" @@ -773,9 +773,13 @@ joinTypes: [ ] + # Method for parsing "SET [OR RESET]" calls. + setOptionParserMethod: "SqlSetOption" + includePosixOperators: false includeCompoundIdentifier: true includeBraces: true includeAdditionalDeclarations: false includeParsingStringLiteralAsArrayLiteral: false + includeIntervalWithoutQualifier: false } diff --git a/flink-table/flink-sql-parser/src/main/codegen/templates/Parser.jj b/flink-table/flink-sql-parser/src/main/codegen/templates/Parser.jj index 1f0ae3d455cd8..38b6748352831 100644 --- a/flink-table/flink-sql-parser/src/main/codegen/templates/Parser.jj +++ b/flink-table/flink-sql-parser/src/main/codegen/templates/Parser.jj @@ -40,6 +40,7 @@ import org.apache.calcite.runtime.CalciteContextException; import org.apache.calcite.sql.JoinConditionType; import org.apache.calcite.sql.JoinType; import org.apache.calcite.sql.SqlAlter; +import org.apache.calcite.sql.SqlAsofJoin; import org.apache.calcite.sql.SqlBasicTypeNameSpec; import org.apache.calcite.sql.SqlBinaryOperator; import org.apache.calcite.sql.SqlCall; @@ -73,6 +74,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; @@ -177,6 +179,7 @@ public class ${parser.class} extends SqlAbstractParserImpl final String sql = ((SourceStringReader) reader).getSourceString(); parser.setOriginalSql(sql); + parser.jj_input_stream.ReInit(reader, 1, 1, sql.length()); } return parser; } @@ -1112,17 +1115,19 @@ SqlNodeList SqlStmtList() : SqlNode stmt; } { - stmt = SqlStmt() { - stmtList.add(stmt); - } ( - - [ - stmt = SqlStmt() { - stmtList.add(stmt); - } - ] - )* + stmt = SqlStmt() { + stmtList.add(stmt); + } + ( + + [ + stmt = SqlStmt() { + stmtList.add(stmt); + } + ] + )* + )? { return new SqlNodeList(stmtList, Span.of(stmtList).pos()); @@ -1143,7 +1148,7 @@ SqlNode SqlStmt() : LOOKAHEAD(2) stmt = ${method} | - stmt = SqlSetOption(Span.of(), null) + stmt = ${parser.setOptionParserMethod!default.parser.setOptionParserMethod}(Span.of(), null) | stmt = SqlAlter() | @@ -1743,10 +1748,10 @@ SqlNode SqlInsert() : ( LOOKAHEAD(2) p = ParenthesizedCompoundIdentifierList() { - if (p.right.size() > 0) { + if (!p.right.isEmpty()) { tableRef = extend(tableRef, p.right); } - if (p.left.size() > 0) { + if (!p.left.isEmpty()) { columnList = p.left; } else { columnList = null; @@ -1818,14 +1823,14 @@ SqlNode SqlUpdate() : ( tableRef = TableHints(tableName) | { tableRef = tableName; } ) [ tableRef = ExtendTable(tableRef) ] ( [ ] alias = SimpleIdentifier() | { alias = null; } ) - id = SimpleIdentifier() { + id = CompoundIdentifier() { targetColumnList.add(id); } // TODO: support DEFAULT also AddExpression(sourceExpressionList, ExprContext.ACCEPT_SUB_QUERY) ( - id = SimpleIdentifier() { targetColumnList.add(id); } + id = CompoundIdentifier() { targetColumnList.add(id); } AddExpression(sourceExpressionList, ExprContext.ACCEPT_SUB_QUERY) )* ( where = Where() | { where = null; } ) @@ -1943,13 +1948,19 @@ SqlInsert WhenNotMatchedClause(SqlNode table) : */ void AddSelectItem(List list) : { - final SqlNode e; + SqlNode e; final SqlIdentifier id; } { e = SelectExpression() ( - [ ] + [ + [ { + e = SqlInternalOperators.MEASURE.createCall( + e.getParserPosition(), e); + } + ] + ] ( id = SimpleIdentifier() | @@ -1992,6 +2003,7 @@ SqlLiteral Natural() : SqlLiteral JoinType() : { JoinType joinType; + boolean asof = false; } { ( @@ -2004,7 +2016,9 @@ SqlLiteral JoinType() : | { joinType = JoinType.INNER; } | - [ ] { joinType = JoinType.LEFT; } + { joinType = JoinType.ASOF; } + | + [ | { asof = true; } ] { joinType = asof ? JoinType.LEFT_ASOF : JoinType.LEFT; } | [ ] { joinType = JoinType.RIGHT; } | @@ -2068,7 +2082,7 @@ SqlNode JoinOrCommaTable(SqlNode e) : /** Matches "LEFT JOIN t ON ...", "RIGHT JOIN t USING ...", "JOIN t". */ SqlNode JoinTable(SqlNode e) : { - SqlNode e2, condition; + SqlNode e2, condition, matchCondition = null; final SqlLiteral natural, joinType, on, using; SqlNodeList list; } @@ -2085,13 +2099,32 @@ SqlNode JoinTable(SqlNode e) : // // We allow CROSS JOIN (joinType = CROSS_JOIN) to have a join condition, // even though that is not valid SQL; the validator will catch it. - LOOKAHEAD(3) + LOOKAHEAD(4) natural = Natural() joinType = JoinType() e2 = TableRef1(ExprContext.ACCEPT_QUERY_OR_JOIN) ( + [ matchCondition = Expression(ExprContext.ACCEPT_SUB_QUERY) ] { on = JoinConditionType.ON.symbol(getPos()); } condition = Expression(ExprContext.ACCEPT_SUB_QUERY) { + JoinType type = joinType.getValueAs(JoinType.class); + if (matchCondition != null) { + if (type != JoinType.ASOF && type != JoinType.LEFT_ASOF) { + throw SqlUtil.newContextException(getPos(), RESOURCE.matchConditionRequiresAsof()); + } + return new SqlAsofJoin(joinType.getParserPosition(), + e, + natural, + joinType, + e2, + on, + condition, + matchCondition); + } else { + if (type == JoinType.ASOF || type == JoinType.LEFT_ASOF) { + throw SqlUtil.newContextException(getPos(), RESOURCE.asofRequiresMatchCondition()); + } + } return new SqlJoin(joinType.getParserPosition(), e, natural, @@ -2740,6 +2773,7 @@ SqlWindow WindowSpecification() : final SqlNodeList orderList; final SqlLiteral isRows; final SqlNode lowerBound, upperBound; + final SqlLiteral exclude; final Span s, s1, s2; final SqlLiteral allowPartial; } @@ -2772,9 +2806,11 @@ SqlWindow WindowSpecification() : lowerBound = WindowRange() { upperBound = null; } ) + exclude = WindowExclusion() | { isRows = SqlLiteral.createBoolean(false, SqlParserPos.ZERO); + exclude = SqlWindow.createExcludeNoOthers(getPos()); lowerBound = upperBound = null; } ) @@ -2791,7 +2827,7 @@ SqlWindow WindowSpecification() : { return SqlWindow.create(null, id, partitionList, orderList, - isRows, lowerBound, upperBound, allowPartial, s.end(this)); + isRows, lowerBound, upperBound, allowPartial, exclude, s.end(this)); } } @@ -2830,6 +2866,27 @@ SqlNode WindowRange() : ) } +/** Parses an exclusion clause for WINDOW FRAME. */ +SqlLiteral WindowExclusion() : +{ +} +{ + ( + + ( + { return SqlWindow.createExcludeCurrentRow(getPos()); } + | + { return SqlWindow.createExcludeNoOthers(getPos()); } + | + { return SqlWindow.createExcludeGroup(getPos()); } + | + { return SqlWindow.createExcludeTies(getPos()); } + ) + | + { return SqlWindow.createExcludeNoOthers(SqlParserPos.ZERO); } + ) +} + /** Parses a QUALIFY clause for SELECT. */ SqlNode Qualify() : { @@ -3791,8 +3848,12 @@ List Expression2(ExprContext exprContext) : AddExpression2b(list, ExprContext.ACCEPT_SUB_QUERY) | - itemOp = getItemOp() - e = Expression(ExprContext.ACCEPT_SUB_QUERY) + ( { itemOp = SqlLibraryOperators.OFFSET; } { e = Expression(ExprContext.ACCEPT_SUB_QUERY); } + | { itemOp = SqlLibraryOperators.ORDINAL; } { e = Expression(ExprContext.ACCEPT_SUB_QUERY); } + | { itemOp = SqlLibraryOperators.SAFE_OFFSET; } { e = Expression(ExprContext.ACCEPT_SUB_QUERY); } + | { itemOp = SqlLibraryOperators.SAFE_ORDINAL; } { e = Expression(ExprContext.ACCEPT_SUB_QUERY); } + | { itemOp = SqlStdOperatorTable.ITEM; } e = Expression(ExprContext.ACCEPT_SUB_QUERY) + ) { list.add( new SqlParserUtil.ToTreeListItem( @@ -3827,22 +3888,6 @@ List Expression2(ExprContext exprContext) : ) } -/** Returns the appropriate ITEM operator for indexing arrays. */ -SqlOperator getItemOp() : -{ -} -{ - { return SqlLibraryOperators.OFFSET; } -| - { return SqlLibraryOperators.ORDINAL; } -| - { return SqlLibraryOperators.SAFE_OFFSET; } -| - { return SqlLibraryOperators.SAFE_ORDINAL; } -| - { return SqlStdOperatorTable.ITEM; } -} - /** Parses a comparison operator inside a SOME / ALL predicate. */ SqlKind comp() : { @@ -3961,7 +4006,7 @@ SqlNode Expression3(ExprContext exprContext) : { if (list1.size() == 1) { // interpret as single value or query - return list1.get(0); + return list1.get(0).clone(list1.getParserPosition()); } else { // interpret as row constructor return SqlStdOperatorTable.ROW.createCall(span().end(list1), @@ -4342,7 +4387,7 @@ SqlSetOption SqlSetOption(Span s, String scope) : } ) { - return new SqlSetOption(s.end(val), scope, name, val); + return new SqlSetOption(s.end(val), scope, (SqlNode) name, val); } | { @@ -4357,7 +4402,7 @@ SqlSetOption SqlSetOption(Span s, String scope) : } ) { - return new SqlSetOption(s.end(name), scope, name, null); + return new SqlSetOption(s.end(name), scope, (SqlNode) name, null); } ) } @@ -4381,8 +4426,7 @@ SqlAlter SqlAlter() : alterNode = ${method}(s, scope) | - - alterNode = SqlSetOption(s, scope) + alterNode = ${parser.setOptionParserMethod!default.parser.setOptionParserMethod}(s, scope) ) { return alterNode; @@ -4835,6 +4879,11 @@ SqlLiteral DateTimeLiteral() :