This is an automated email from the ASF dual-hosted git repository.
snuyanzin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git
The following commit(s) were added to refs/heads/master by this push:
new 3212758626d [FLINK-39982][table] Drop `SqlCollectionTypeNameSpec` and
`SqlJsonQueryFunction` from Flink codebase
3212758626d is described below
commit 3212758626d73dfefdf49317b9ef1da07c2d0c72
Author: Sergey Nuyanzin <[email protected]>
AuthorDate: Wed Jun 24 13:21:04 2026 +0200
[FLINK-39982][table] Drop `SqlCollectionTypeNameSpec` and
`SqlJsonQueryFunction` from Flink codebase
---
.../calcite/sql/SqlCollectionTypeNameSpec.java | 140 ---------------
.../calcite/sql/fun/SqlJsonQueryFunction.java | 192 ---------------------
.../org/apache/calcite/sql/type/SqlTypeUtil.java | 16 +-
3 files changed, 11 insertions(+), 337 deletions(-)
diff --git
a/flink-table/flink-sql-parser/src/main/java/org/apache/calcite/sql/SqlCollectionTypeNameSpec.java
b/flink-table/flink-sql-parser/src/main/java/org/apache/calcite/sql/SqlCollectionTypeNameSpec.java
deleted file mode 100644
index 440f3823c40..00000000000
---
a/flink-table/flink-sql-parser/src/main/java/org/apache/calcite/sql/SqlCollectionTypeNameSpec.java
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.calcite.sql;
-
-import org.apache.calcite.rel.type.RelDataType;
-import org.apache.calcite.rel.type.RelDataTypeFactory;
-import org.apache.calcite.sql.parser.SqlParserPos;
-import org.apache.calcite.sql.type.SqlTypeName;
-import org.apache.calcite.sql.validate.SqlValidator;
-import org.apache.calcite.util.Litmus;
-import org.apache.calcite.util.Util;
-
-import java.util.Objects;
-
-import static java.util.Objects.requireNonNull;
-
-/**
- * A sql type name specification of collection type.
- *
- * <p>The grammar definition in SQL-2011 IWD 9075-2:201?(E) 6.1 <collection
type> is as
- * following:
- *
- * <blockquote>
- *
- * <pre>
- * <collection type> ::=
- * <array type>
- * | <multiset type>
- *
- * <array type> ::=
- * <data type> ARRAY
- * [ <left bracket or trigraph>
- * <maximum cardinality>
- * <right bracket or trigraph> ]
- *
- * <maximum cardinality> ::=
- * <unsigned integer>
- *
- * <multiset type> ::=
- * <data type> MULTISET
- * </pre>
- *
- * </blockquote>
- *
- * <p>This class is intended to describe SQL collection type. It can describe
either simple
- * collection type like "int array" or nested collection type like "int array
array" or "int array
- * multiset". For nested collection type, the element type name of this {@code
- * SqlCollectionTypeNameSpec} is also a {@code SqlCollectionTypeNameSpec}.
- *
- * <p>The class is copied from Calcite because of 1.40.0 regression at
CALCITE-1466. Flink
- * modification at lines: 91 ~ 93
- */
-public class SqlCollectionTypeNameSpec extends SqlTypeNameSpec {
- private final SqlTypeNameSpec elementTypeName;
- private final SqlTypeName collectionTypeName;
-
- /**
- * Creates a {@code SqlCollectionTypeNameSpec}.
- *
- * @param elementTypeName Type of the collection element
- * @param collectionTypeName Collection type name
- * @param pos Parser position, must not be null
- */
- public SqlCollectionTypeNameSpec(
- SqlTypeNameSpec elementTypeName, SqlTypeName collectionTypeName,
SqlParserPos pos) {
- super(new SqlIdentifier(collectionTypeName.name(), pos), pos);
- this.elementTypeName = requireNonNull(elementTypeName,
"elementTypeName");
- this.collectionTypeName = requireNonNull(collectionTypeName,
"collectionTypeName");
- }
-
- public SqlTypeNameSpec getElementTypeName() {
- return elementTypeName;
- }
-
- @Override
- public RelDataType deriveType(SqlValidator validator) {
- // FLINK MODIFICATION BEGIN
- final RelDataType type = elementTypeName.deriveType(validator);
- // FLINK MODIFICATION END
- return createCollectionType(type, validator.getTypeFactory());
- }
-
- @Override
- public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
- elementTypeName.unparse(writer, leftPrec, rightPrec);
- writer.keyword(collectionTypeName.name());
- }
-
- @Override
- public boolean equalsDeep(SqlTypeNameSpec spec, Litmus litmus) {
- if (!(spec instanceof SqlCollectionTypeNameSpec)) {
- return litmus.fail("{} != {}", this, spec);
- }
- SqlCollectionTypeNameSpec that = (SqlCollectionTypeNameSpec) spec;
- if (!this.elementTypeName.equalsDeep(that.elementTypeName, litmus)) {
- return litmus.fail("{} != {}", this, spec);
- }
- if (!Objects.equals(this.collectionTypeName, that.collectionTypeName))
{
- return litmus.fail("{} != {}", this, spec);
- }
- return litmus.succeed();
- }
-
- // ~ Tools
------------------------------------------------------------------
-
- /**
- * Create collection data type.
- *
- * @param elementType Type of the collection element
- * @param typeFactory Type factory
- * @return The collection data type, or throw exception if the collection
type name does not
- * belong to {@code SqlTypeName} enumerations
- */
- private RelDataType createCollectionType(
- RelDataType elementType, RelDataTypeFactory typeFactory) {
- switch (collectionTypeName) {
- case MULTISET:
- return typeFactory.createMultisetType(elementType, -1);
- case ARRAY:
- return typeFactory.createArrayType(elementType, -1);
-
- default:
- throw Util.unexpected(collectionTypeName);
- }
- }
-}
diff --git
a/flink-table/flink-sql-parser/src/main/java/org/apache/calcite/sql/fun/SqlJsonQueryFunction.java
b/flink-table/flink-sql-parser/src/main/java/org/apache/calcite/sql/fun/SqlJsonQueryFunction.java
deleted file mode 100644
index 9161da5ea2d..00000000000
---
a/flink-table/flink-sql-parser/src/main/java/org/apache/calcite/sql/fun/SqlJsonQueryFunction.java
+++ /dev/null
@@ -1,192 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.calcite.sql.fun;
-
-import org.apache.calcite.rel.type.RelDataType;
-import org.apache.calcite.sql.SqlBasicCall;
-import org.apache.calcite.sql.SqlCall;
-import org.apache.calcite.sql.SqlFunction;
-import org.apache.calcite.sql.SqlFunctionCategory;
-import org.apache.calcite.sql.SqlJsonQueryEmptyOrErrorBehavior;
-import org.apache.calcite.sql.SqlJsonQueryWrapperBehavior;
-import org.apache.calcite.sql.SqlKind;
-import org.apache.calcite.sql.SqlLiteral;
-import org.apache.calcite.sql.SqlNode;
-import org.apache.calcite.sql.SqlOperatorBinding;
-import org.apache.calcite.sql.SqlWriter;
-import org.apache.calcite.sql.parser.SqlParserPos;
-import org.apache.calcite.sql.type.OperandTypes;
-import org.apache.calcite.sql.type.ReturnTypes;
-import org.apache.calcite.sql.type.SqlTypeFamily;
-import org.apache.calcite.sql.type.SqlTypeTransforms;
-import org.checkerframework.checker.nullness.qual.Nullable;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Optional;
-
-import static java.util.Objects.requireNonNull;
-
-/**
- * The <code>JSON_QUERY</code> function.
- *
- * <p>This class was copied over from Calcite to support RETURNING clause in
JSON_QUERY
- * (CALCITE-6365). When upgrading to Calcite 1.38.0 version, please remove the
entire class.
- */
-public class SqlJsonQueryFunction extends SqlFunction {
-
- public SqlJsonQueryFunction() {
- super(
- "JSON_QUERY",
- SqlKind.OTHER_FUNCTION,
- ReturnTypes.cascade(
- opBinding ->
- explicitTypeSpec(opBinding)
- .orElseGet(
- () ->
-
ReturnTypes.VARCHAR_2000.inferReturnType(
- opBinding)),
- SqlTypeTransforms.FORCE_NULLABLE),
- null,
- OperandTypes.family(
- Arrays.asList(
- SqlTypeFamily.ANY,
- SqlTypeFamily.CHARACTER,
- SqlTypeFamily.ANY,
- SqlTypeFamily.ANY,
- SqlTypeFamily.ANY,
- SqlTypeFamily.ANY),
- i -> i >= 5),
- SqlFunctionCategory.SYSTEM);
- }
-
- @Override
- public @Nullable String getSignatureTemplate(int operandsCount) {
- if (operandsCount == 6) {
- return "{0}({1} {2} RETURNING {6} {3} WRAPPER {4} ON EMPTY {5} ON
ERROR)";
- } else {
- return "{0}({1} {2} {3} WRAPPER {4} ON EMPTY {5} ON ERROR)";
- }
- }
-
- @Override
- public void unparse(SqlWriter writer, SqlCall call, int leftPrec, int
rightPrec) {
- final SqlWriter.Frame frame = writer.startFunCall(getName());
- call.operand(0).unparse(writer, 0, 0);
- writer.sep(",", true);
- call.operand(1).unparse(writer, 0, 0);
-
- if (call.operandCount() == 6) {
- writer.keyword("RETURNING");
- call.operand(5).unparse(writer, 0, 0);
- }
- final SqlJsonQueryWrapperBehavior wrapperBehavior =
getEnumValue(call.operand(2));
- switch (wrapperBehavior) {
- case WITHOUT_ARRAY:
- writer.keyword("WITHOUT ARRAY");
- break;
- case WITH_CONDITIONAL_ARRAY:
- writer.keyword("WITH CONDITIONAL ARRAY");
- break;
- case WITH_UNCONDITIONAL_ARRAY:
- writer.keyword("WITH UNCONDITIONAL ARRAY");
- break;
- default:
- throw new IllegalStateException("unreachable code");
- }
- writer.keyword("WRAPPER");
- unparseEmptyOrErrorBehavior(writer, getEnumValue(call.operand(3)));
- writer.keyword("ON EMPTY");
- unparseEmptyOrErrorBehavior(writer, getEnumValue(call.operand(4)));
- writer.keyword("ON ERROR");
- writer.endFunCall(frame);
- }
-
- public SqlCall createCall(
- @Nullable SqlLiteral functionQualifier,
- SqlParserPos pos,
- @Nullable SqlNode... operands) {
- final List<SqlNode> args = new ArrayList<>();
- args.add(operands[0]);
- args.add(operands[1]);
-
- if (operands[2] == null) {
-
args.add(SqlLiteral.createSymbol(SqlJsonQueryWrapperBehavior.WITHOUT_ARRAY,
pos));
- } else {
- args.add(operands[2]);
- }
- if (operands[3] == null) {
-
args.add(SqlLiteral.createSymbol(SqlJsonQueryEmptyOrErrorBehavior.NULL, pos));
- } else {
- args.add(operands[3]);
- }
- if (operands[4] == null) {
-
args.add(SqlLiteral.createSymbol(SqlJsonQueryEmptyOrErrorBehavior.NULL, pos));
- } else {
- args.add(operands[4]);
- }
-
- if (operands.length >= 6 && operands[5] != null) {
- args.add(operands[5]);
- }
-
- pos = pos.plusAll(operands);
- return new SqlBasicCall(this, args, pos, functionQualifier);
- }
-
- private static void unparseEmptyOrErrorBehavior(
- SqlWriter writer, SqlJsonQueryEmptyOrErrorBehavior emptyBehavior) {
- switch (emptyBehavior) {
- case NULL:
- writer.keyword("NULL");
- break;
- case ERROR:
- writer.keyword("ERROR");
- break;
- case EMPTY_ARRAY:
- writer.keyword("EMPTY ARRAY");
- break;
- case EMPTY_OBJECT:
- writer.keyword("EMPTY OBJECT");
- break;
- default:
- throw new IllegalStateException("unreachable code");
- }
- }
-
- @SuppressWarnings("unchecked")
- private static <E extends Enum<E>> E getEnumValue(SqlNode operand) {
- return (E) requireNonNull(((SqlLiteral) operand).getValue(),
"operand.value");
- }
-
- public static boolean hasExplicitTypeSpec(@Nullable SqlNode[] operands) {
- return operands.length >= 6;
- }
-
- public static List<SqlNode> removeTypeSpecOperands(SqlCall call) {
- return call.getOperandList().subList(0, 5);
- }
-
- /** Returns the optional explicit returning type specification. * */
- private static Optional<RelDataType> explicitTypeSpec(SqlOperatorBinding
opBinding) {
- if (opBinding.getOperandCount() >= 6) {
- return Optional.of(opBinding.getOperandType(5));
- }
- return Optional.empty();
- }
-}
diff --git
a/flink-table/flink-table-planner/src/main/java/org/apache/calcite/sql/type/SqlTypeUtil.java
b/flink-table/flink-table-planner/src/main/java/org/apache/calcite/sql/type/SqlTypeUtil.java
index 105f6c0682f..89d15cf6bd2 100644
---
a/flink-table/flink-table-planner/src/main/java/org/apache/calcite/sql/type/SqlTypeUtil.java
+++
b/flink-table/flink-table-planner/src/main/java/org/apache/calcite/sql/type/SqlTypeUtil.java
@@ -16,6 +16,7 @@
*/
package org.apache.calcite.sql.type;
+import org.apache.flink.sql.parser.type.ExtendedSqlCollectionTypeNameSpec;
import org.apache.flink.sql.parser.type.ExtendedSqlRowTypeNameSpec;
import com.google.common.collect.ImmutableList;
@@ -31,7 +32,6 @@ import org.apache.calcite.sql.SqlBasicTypeNameSpec;
import org.apache.calcite.sql.SqlCall;
import org.apache.calcite.sql.SqlCallBinding;
import org.apache.calcite.sql.SqlCollation;
-import org.apache.calcite.sql.SqlCollectionTypeNameSpec;
import org.apache.calcite.sql.SqlDataTypeSpec;
import org.apache.calcite.sql.SqlIdentifier;
import org.apache.calcite.sql.SqlMapTypeNameSpec;
@@ -75,8 +75,9 @@ import static org.apache.calcite.util.Static.RESOURCE;
* <p>FLINK modifications are at lines
*
* <ol>
- * <li>We should use ExtendedSqlRowTypeNameSpec for rows: Lines 1092-1096
- * <li>Should be removed after fixing CALCITE-7062: Lines 1116-1118
+ * <li>We should use ExtendedSqlCollectionTypeNameSpec for rows: Lines
1104-1112
+ * <li>We should use ExtendedSqlRowTypeNameSpec for rows: Lines 1124-1128
+ * <li>Should be removed after fixing CALCITE-7062: Lines 1148-1150
* </ol>
*/
public abstract class SqlTypeUtil {
@@ -1099,11 +1100,16 @@ public abstract class SqlTypeUtil {
new SqlBasicTypeNameSpec(
typeName, precision, scale, charSetName,
SqlParserPos.ZERO);
} else if (isCollection(type)) {
+ // FLINK MODIFICATION BEGIN
+ final RelDataType componentType = getComponentTypeOrThrow(type);
typeNameSpec =
- new SqlCollectionTypeNameSpec(
-
convertTypeToSpec(getComponentTypeOrThrow(type)).getTypeNameSpec(),
+ new ExtendedSqlCollectionTypeNameSpec(
+ convertTypeToSpec(componentType).getTypeNameSpec(),
+ componentType.isNullable(),
typeName,
+ true,
SqlParserPos.ZERO);
+ // FLINK MODIFICATION END
} else if (isRow(type)) {
RelRecordType recordType = (RelRecordType) type;
List<RelDataTypeField> fields = recordType.getFieldList();