This is an automated email from the ASF dual-hosted git repository.

xiong pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/main by this push:
     new 53cde5105d [CALCITE-7105] ARRAY_CONCAT should only accept arguments 
with type ARRAY
53cde5105d is described below

commit 53cde5105dce5c2e35f23306d9d0ec67a53fc65e
Author: Mihai Budiu <[email protected]>
AuthorDate: Thu Jul 24 16:18:32 2025 -0700

    [CALCITE-7105] ARRAY_CONCAT should only accept arguments with type ARRAY
    
    Signed-off-by: Mihai Budiu <[email protected]>
---
 .../calcite/sql/fun/SqlLibraryOperators.java       | 31 +++++++++++++++++++++-
 .../org/apache/calcite/test/SqlOperatorTest.java   |  2 ++
 2 files changed, 32 insertions(+), 1 deletion(-)

diff --git 
a/core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java 
b/core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java
index e3f234a6f0..0df863630b 100644
--- a/core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java
+++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java
@@ -26,6 +26,7 @@
 import org.apache.calcite.sql.SqlFunction;
 import org.apache.calcite.sql.SqlFunctionCategory;
 import org.apache.calcite.sql.SqlKind;
+import org.apache.calcite.sql.SqlOperandCountRange;
 import org.apache.calcite.sql.SqlOperator;
 import org.apache.calcite.sql.SqlOperatorBinding;
 import org.apache.calcite.sql.SqlOperatorTable;
@@ -36,6 +37,7 @@
 import org.apache.calcite.sql.type.OperandHandlers;
 import org.apache.calcite.sql.type.OperandTypes;
 import org.apache.calcite.sql.type.ReturnTypes;
+import org.apache.calcite.sql.type.SameOperandTypeChecker;
 import org.apache.calcite.sql.type.SqlOperandCountRanges;
 import org.apache.calcite.sql.type.SqlReturnTypeInference;
 import org.apache.calcite.sql.type.SqlTypeFamily;
@@ -1512,7 +1514,34 @@ private static RelDataType 
arrayCompactReturnType(SqlOperatorBinding opBinding)
   public static final SqlFunction ARRAY_CONCAT =
       SqlBasicFunction.create(SqlKind.ARRAY_CONCAT,
           ReturnTypes.LEAST_RESTRICTIVE,
-          OperandTypes.AT_LEAST_ONE_SAME_VARIADIC);
+          new SameOperandTypeChecker(-1) {
+            @Override public boolean checkOperandTypes(
+                SqlCallBinding callBinding,
+                boolean throwOnFailure) {
+              boolean result = super.checkOperandTypes(callBinding, 
throwOnFailure);
+              if (!result) {
+                return false;
+              }
+              for (int i = 0; i < callBinding.getOperandCount(); i++) {
+                RelDataType operandType = callBinding.getOperandType(i);
+                if (operandType.getSqlTypeName() != SqlTypeName.ARRAY) {
+                  if (throwOnFailure) {
+                    throw callBinding.newValidationSignatureError();
+                  }
+                  return false;
+                }
+              }
+              return true;
+            }
+
+              @Override public SqlOperandCountRange getOperandCountRange() {
+                return SqlOperandCountRanges.from(1);
+              }
+
+              @Override public String getAllowedSignatures(SqlOperator op, 
String opName) {
+                return opName + "(...)";
+              }
+          });
 
   /** The "ARRAY_CONTAINS(array, element)" function. */
   @LibraryOperator(libraries = {SPARK})
diff --git a/testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java 
b/testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java
index ff98edc508..65426d6c32 100644
--- a/testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java
+++ b/testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java
@@ -8064,6 +8064,8 @@ void checkRegexpExtract(SqlOperatorFixture f0, 
FunctionAlias functionAlias) {
     SqlOperatorFixture f = fixture()
         .setFor(SqlLibraryOperators.ARRAY_CONCAT)
         .withLibrary(SqlLibrary.BIG_QUERY);
+    // Test case for [CALCITE-7105] ARRAY_CONCAT should only accept arguments 
with type ARRAY
+    f.checkFails("^array_concat('a')^", "Cannot apply 'ARRAY_CONCAT'.*", 
false);
     f.checkFails("^array_concat()^", INVALID_ARGUMENTS_NUMBER, false);
     f.checkScalar("array_concat(array[1, 2], array[2, 3])", "[1, 2, 2, 3]",
         "INTEGER NOT NULL ARRAY NOT NULL");

Reply via email to