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 c0344cbb4d [CALCITE-7025] Verifying the Quantify operator without 
compatible types, should throw an exception about the Quantify Operator
c0344cbb4d is described below

commit c0344cbb4dc33c2607420bec57371d44c96308d1
Author: Xiong Duan <[email protected]>
AuthorDate: Sun May 18 14:19:03 2025 +0800

    [CALCITE-7025] Verifying the Quantify operator without compatible types, 
should throw an exception about the Quantify Operator
---
 .../org/apache/calcite/sql/fun/SqlInOperator.java  |  2 +-
 .../calcite/sql/fun/SqlQuantifyOperator.java       |  4 ++++
 .../org/apache/calcite/test/SqlValidatorTest.java  |  4 ++--
 core/src/test/resources/sql/sub-query.iq           |  5 +++++
 .../org/apache/calcite/test/SqlOperatorTest.java   | 24 ++++++++++++++++++++++
 5 files changed, 36 insertions(+), 3 deletions(-)

diff --git a/core/src/main/java/org/apache/calcite/sql/fun/SqlInOperator.java 
b/core/src/main/java/org/apache/calcite/sql/fun/SqlInOperator.java
index 67fd330211..28cbf51730 100644
--- a/core/src/main/java/org/apache/calcite/sql/fun/SqlInOperator.java
+++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlInOperator.java
@@ -184,7 +184,7 @@ private static SqlBinaryOperator of(SqlKind kind) {
             callBinding,
             ImmutableList.of(leftRowType, rightRowType)), callBinding)) {
       throw validator.newValidationError(call,
-          RESOURCE.incompatibleValueType(SqlStdOperatorTable.IN.getName()));
+          RESOURCE.incompatibleValueType(call.getOperator().getName()));
     }
 
     // Result is a boolean, nullable if there are any nullable types
diff --git 
a/core/src/main/java/org/apache/calcite/sql/fun/SqlQuantifyOperator.java 
b/core/src/main/java/org/apache/calcite/sql/fun/SqlQuantifyOperator.java
index c07d63edba..dbd02f8e86 100644
--- a/core/src/main/java/org/apache/calcite/sql/fun/SqlQuantifyOperator.java
+++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlQuantifyOperator.java
@@ -33,6 +33,8 @@
 
 import static com.google.common.base.Preconditions.checkArgument;
 
+import static org.apache.calcite.util.Static.RESOURCE;
+
 import static java.util.Objects.requireNonNull;
 
 /**
@@ -115,6 +117,8 @@ public class SqlQuantifyOperator extends SqlInOperator {
                   || componentRightType.isNullable()
                   || leftType.isNullable());
         }
+        throw validator.newValidationError(call,
+            RESOURCE.incompatibleValueType(call.getOperator().getName()));
       }
     }
     return null;
diff --git a/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java 
b/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
index 19ef2b0347..91ed529f62 100644
--- a/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
+++ b/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
@@ -4691,9 +4691,9 @@ private void checkNegWindow(String s, String msg) {
         .fails(ERR_IN_VALUES_INCOMPATIBLE);
     expr("false and 1 = any ('b', 'c')").ok();
     expr("false and ^1 = any (date '2012-01-02', date '2012-01-04')^")
-        .fails(ERR_IN_OPERANDS_INCOMPATIBLE);
+        .fails("Values passed to = SOME operator must have compatible types");
     expr("1 > 5 or ^(1, 2) < any (3, 4)^")
-        .fails(ERR_IN_OPERANDS_INCOMPATIBLE);
+        .fails("Values passed to < SOME operator must have compatible types");
   }
 
   @Test void testDoubleNoAlias() {
diff --git a/core/src/test/resources/sql/sub-query.iq 
b/core/src/test/resources/sql/sub-query.iq
index b2217579d1..95734e88f2 100644
--- a/core/src/test/resources/sql/sub-query.iq
+++ b/core/src/test/resources/sql/sub-query.iq
@@ -4967,4 +4967,9 @@ select deptno from emp where deptno not in (50, 20);
 
 !ok
 
+# [CALCITE-7025] Verifying the Quantify operator without compatible types, 
should throw an exception about the Quantify Operator
+select * from emp where false > some(select deptno from dept);
+Values passed to > SOME operator must have compatible types
+!error
+
 # End sub-query.iq
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 4d8b153eac..28a9b633a1 100644
--- a/testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java
+++ b/testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java
@@ -16099,6 +16099,30 @@ void testTimestampDiff(boolean coercionEnabled) {
         "BOOLEAN", true);
   }
 
+  @Test void testQuantifyOperatorsWithTypeException() {
+    final SqlOperatorFixture f = fixture();
+    QUANTIFY_OPERATORS.forEach(operator -> f.setFor(operator, 
SqlOperatorFixture.VmName.EXPAND));
+    // some(List value)
+    f.checkFails("SELECT ^cast(true as boolean) = some(1, 2, 3)^",
+        "Values passed to = SOME operator must have compatible types", false);
+    // some(Collection value)
+    f.checkFails("^cast(true as boolean) = some (ARRAY[2,3,null])^",
+        "Values passed to = SOME operator must have compatible types", false);
+    f.checkFails("^cast(true as boolean) <> some (ARRAY[1,2,null])^",
+        "Values passed to <> SOME operator must have compatible types", false);
+    f.checkFails("^cast(true as boolean) < some (ARRAY[1,2,null])^",
+        "Values passed to < SOME operator must have compatible types", false);
+    f.checkFails("^cast(true as boolean) <= some (ARRAY[1,2,null])^",
+        "Values passed to <= SOME operator must have compatible types", false);
+    f.checkFails("^cast(true as boolean) > some (ARRAY[1,2,null])^",
+        "Values passed to > SOME operator must have compatible types", false);
+    f.checkFails("^cast(true as boolean) >= some (ARRAY[1,2,null])^",
+        "Values passed to >= SOME operator must have compatible types", false);
+    f.checkFails(
+        "SELECT ^cast(true as boolean) = some(x.t)^ FROM (SELECT 
ARRAY[1,2,3,null] as t) as x",
+        "Values passed to = SOME operator must have compatible types", false);
+  }
+
   @Test void testAnyValueFunc() {
     final SqlOperatorFixture f = fixture();
     f.setFor(SqlStdOperatorTable.ANY_VALUE, VM_EXPAND);

Reply via email to