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

yiguolei pushed a commit to branch branch-4.2
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-4.2 by this push:
     new 55b0db6177e [branch-4.2](fe) Reject complex types in IN predicates 
(#69122) (#69178)
55b0db6177e is described below

commit 55b0db6177e5a6315d12c494375757df2bfa0948
Author: Chenyang Sun <[email protected]>
AuthorDate: Fri Oct 16 23:31:22 2026 +0800

    [branch-4.2](fe) Reject complex types in IN predicates (#69122) (#69178)
    
    pick from master #69122
---
 .../nereids/trees/expressions/InPredicate.java     | 22 -----------
 .../nereids/types/VarBinarySqlSupportTest.java     | 10 ++++-
 .../doris/nereids/util/TypeCoercionUtilsTest.java  | 11 +++---
 .../nereids_syntax_p0/inpredicate_with_list.out    | 15 -------
 .../nereids_syntax_p0/inpredicate_with_struct.out  | 19 ---------
 .../data/query_p0/sql_functions/test_in_expr.out   |  4 --
 .../nereids_syntax_p0/inpredicate_with_list.groovy | 42 +++++++++++---------
 .../inpredicate_with_struct.groovy                 | 46 ++++++++++++----------
 .../query_p0/sql_functions/test_in_expr.groovy     | 16 --------
 9 files changed, 63 insertions(+), 122 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/InPredicate.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/InPredicate.java
index 533f1aa4594..2d1ad1f9f9a 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/InPredicate.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/InPredicate.java
@@ -136,28 +136,6 @@ public class InPredicate extends Expression {
     @Override
     public void checkLegalityBeforeTypeCoercion() {
         List<Expression> arguments = getArguments();
-        if (arguments.get(0).getDataType().isStructType()) {
-            // we should check in value list is all struct type
-            for (int i = 1; i < arguments.size(); i++) {
-                if (!arguments.get(i).getDataType().isStructType() && 
!arguments.get(i).getDataType().isNullType()) {
-                    throw new AnalysisException("in predicate struct should 
compare with struct type list, but got : "
-                            + arguments.get(i).getDataType().toSql());
-                }
-            }
-            return;
-        }
-
-        if (arguments.get(0).getDataType().isArrayType()) {
-            // we should check in value list is all list type
-            for (int i = 1; i < arguments.size(); i++) {
-                if (!arguments.get(i).getDataType().isArrayType() && 
!arguments.get(i).getDataType().isNullType()) {
-                    throw new AnalysisException("in predicate list should 
compare with struct type list, but got : "
-                            + arguments.get(i).getDataType().toSql());
-                }
-            }
-            return;
-        }
-
         arguments.forEach(c -> {
             if (c.getDataType().isObjectType()) {
                 throw new AnalysisException("in predicate could not contains 
object type: " + this.toSql());
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/nereids/types/VarBinarySqlSupportTest.java
 
b/fe/fe-core/src/test/java/org/apache/doris/nereids/types/VarBinarySqlSupportTest.java
index e454bda3752..ca5c1475178 100644
--- 
a/fe/fe-core/src/test/java/org/apache/doris/nereids/types/VarBinarySqlSupportTest.java
+++ 
b/fe/fe-core/src/test/java/org/apache/doris/nereids/types/VarBinarySqlSupportTest.java
@@ -84,7 +84,9 @@ public class VarBinarySqlSupportTest extends 
TestWithFeService {
                 "cast(encoded as varbinary) not in (X'01', X'02')",
                 "cast(encoded as varbinary(2)) in (cast(encoded as 
varbinary(2)), cast(encoded as varbinary(2)))",
                 "cast(encoded as varbinary) in ('first', 'second')",
-                "encoded in (X'01', X'02')",
+                "encoded in (X'01', X'02')"
+        });
+        assertExpressionsRejected("in predicate could not contains complex 
type", new String[] {
                 "array(cast(encoded as varbinary)) in (array(X'01'), 
array(X'02'))",
                 "struct(cast(encoded as varbinary)) in (struct(X'01'), 
struct(X'02'))"
         });
@@ -125,6 +127,10 @@ public class VarBinarySqlSupportTest extends 
TestWithFeService {
     }
 
     private void assertBinaryExpressionsRejected(String[] expressions) {
+        assertExpressionsRejected("does not support VARBINARY", expressions);
+    }
+
+    private void assertExpressionsRejected(String expectedMessage, String[] 
expressions) {
         boolean oldBehavior = GlobalVariable.enableNewTypeCoercionBehavior;
         try {
             for (boolean newBehavior : new boolean[] {false, true}) {
@@ -134,7 +140,7 @@ public class VarBinarySqlSupportTest extends 
TestWithFeService {
                             
org.apache.doris.nereids.exceptions.AnalysisException.class,
                             () -> 
PlanChecker.from(connectContext).analyze("select " + expression + " from 
source_bytes"),
                             expression);
-                    Assertions.assertTrue(error.getMessage().contains("does 
not support VARBINARY"), error.getMessage());
+                    
Assertions.assertTrue(error.getMessage().contains(expectedMessage), 
error.getMessage());
                 }));
             }
         } finally {
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/nereids/util/TypeCoercionUtilsTest.java
 
b/fe/fe-core/src/test/java/org/apache/doris/nereids/util/TypeCoercionUtilsTest.java
index 69092f57b45..d95f5a6859f 100644
--- 
a/fe/fe-core/src/test/java/org/apache/doris/nereids/util/TypeCoercionUtilsTest.java
+++ 
b/fe/fe-core/src/test/java/org/apache/doris/nereids/util/TypeCoercionUtilsTest.java
@@ -895,7 +895,7 @@ public class TypeCoercionUtilsTest {
     }
 
     @Test
-    public void testInPredicateStructCastKeepsNullableCastResult() {
+    public void testInPredicateStructIsRejected() {
         StructLiteral stringStruct = new StructLiteral(ImmutableList.of(
                 new IntegerLiteral(1), new StringLiteral("2")));
         StructLiteral integerStruct = new StructLiteral(ImmutableList.of(
@@ -903,11 +903,10 @@ public class TypeCoercionUtilsTest {
         InPredicate predicate = new InPredicate(stringStruct,
                 ImmutableList.of(integerStruct, NullLiteral.INSTANCE));
 
-        InPredicate coerced = (InPredicate) 
TypeCoercionUtils.processInPredicate(predicate);
-
-        StructType commonType = (StructType) 
coerced.getCompareExpr().getDataType();
-        Assertions.assertTrue(commonType.getFields().get(1).isNullable(),
-                "String-to-decimal coercion can produce NULL inside the struct 
field");
+        AnalysisException error = 
Assertions.assertThrows(AnalysisException.class,
+                () -> TypeCoercionUtils.processInPredicate(predicate));
+        Assertions.assertTrue(error.getMessage().contains("in predicate could 
not contains complex type"),
+                error.getMessage());
     }
 
     @Test
diff --git a/regression-test/data/nereids_syntax_p0/inpredicate_with_list.out 
b/regression-test/data/nereids_syntax_p0/inpredicate_with_list.out
index 2aaf57f0cd5..4b46a583195 100644
--- a/regression-test/data/nereids_syntax_p0/inpredicate_with_list.out
+++ b/regression-test/data/nereids_syntax_p0/inpredicate_with_list.out
@@ -2,18 +2,3 @@
 -- !select_default --
 1      [1, 2, 3]
 2      [4, 5, 6]
-
--- !in_predicate_17 --
-
--- !in_predicate_18 --
-
--- !in_predicate_19 --
-2      [4, 5, 6]
-
--- !in_predicate_20 --
-2      [4, 5, 6]
-
--- !in_predicate_21 --
-
--- !in_predicate_22 --
-
diff --git a/regression-test/data/nereids_syntax_p0/inpredicate_with_struct.out 
b/regression-test/data/nereids_syntax_p0/inpredicate_with_struct.out
deleted file mode 100644
index 5e1e97a235b..00000000000
--- a/regression-test/data/nereids_syntax_p0/inpredicate_with_struct.out
+++ /dev/null
@@ -1,19 +0,0 @@
--- This file is automatically generated. You should know what you did if you 
want to edit this
--- !in_predicate_11 --
-\N
-
--- !in_predicate_12 --
-\N
-
--- !in_predicate_13 --
-true
-
--- !in_predicate_14 --
-false
-
--- !in_predicate_15 --
-true
-
--- !in_predicate_16 --
-false
-
diff --git a/regression-test/data/query_p0/sql_functions/test_in_expr.out 
b/regression-test/data/query_p0/sql_functions/test_in_expr.out
index 43bb4b43bfb..5f6f4177493 100644
--- a/regression-test/data/query_p0/sql_functions/test_in_expr.out
+++ b/regression-test/data/query_p0/sql_functions/test_in_expr.out
@@ -72,7 +72,3 @@ d
 \N
 
 -- !select --
-
--- !select --
-[1, 2, 3, 4, 5]        \N
-
diff --git 
a/regression-test/suites/nereids_syntax_p0/inpredicate_with_list.groovy 
b/regression-test/suites/nereids_syntax_p0/inpredicate_with_list.groovy
index 95c3a1d5a29..9faf96f673a 100644
--- a/regression-test/suites/nereids_syntax_p0/inpredicate_with_list.groovy
+++ b/regression-test/suites/nereids_syntax_p0/inpredicate_with_list.groovy
@@ -35,24 +35,30 @@ suite("inpredicate_with_list") {
 
         sql """ set enable_nereids_planner = true;"""
         sql """ set enable_fallback_to_original_planner=false;"""
-        order_qt_in_predicate_17 """
-            SELECT * FROM ${tableName} where c_array in ([1,2], [1,3]);
-        """
-        order_qt_in_predicate_18 """
-            SELECT * FROM ${tableName} where c_array in (null, [1,3]);
-        """
-        order_qt_in_predicate_19 """
-            SELECT * FROM ${tableName} where c_array in ([1,2], [1,3], 
[4,5,6]);
-        """
-        order_qt_in_predicate_20 """
-            SELECT * FROM ${tableName} where c_array in ([1,2], null, [4,5,6]);
-        """
-        order_qt_in_predicate_21 """
-            SELECT * FROM ${tableName} where c_array in ([1,2], null, [4,5,3]);
-        """
-        order_qt_in_predicate_22 """
-            SELECT * FROM ${tableName} where c_array in ([1,2], [6,5,4], 
[4,5,3]);
-        """
+        test {
+            sql """ SELECT * FROM ${tableName} where c_array in ([1,2], 
[1,3]); """
+            exception "in predicate could not contains complex type"
+        }
+        test {
+            sql """ SELECT * FROM ${tableName} where c_array in (null, [1,3]); 
"""
+            exception "in predicate could not contains complex type"
+        }
+        test {
+            sql """ SELECT * FROM ${tableName} where c_array in ([1,2], [1,3], 
[4,5,6]); """
+            exception "in predicate could not contains complex type"
+        }
+        test {
+            sql """ SELECT * FROM ${tableName} where c_array in ([1,2], null, 
[4,5,6]); """
+            exception "in predicate could not contains complex type"
+        }
+        test {
+            sql """ SELECT * FROM ${tableName} where c_array in ([1,2], null, 
[4,5,3]); """
+            exception "in predicate could not contains complex type"
+        }
+        test {
+            sql """ SELECT * FROM ${tableName} where c_array in ([1,2], 
[6,5,4], [4,5,3]); """
+            exception "in predicate could not contains complex type"
+        }
     } finally {
         try_sql("DROP TABLE IF EXISTS ${tableName}")
     }
diff --git 
a/regression-test/suites/nereids_syntax_p0/inpredicate_with_struct.groovy 
b/regression-test/suites/nereids_syntax_p0/inpredicate_with_struct.groovy
index fb686fbc9ef..7705a98fb6a 100644
--- a/regression-test/suites/nereids_syntax_p0/inpredicate_with_struct.groovy
+++ b/regression-test/suites/nereids_syntax_p0/inpredicate_with_struct.groovy
@@ -15,27 +15,33 @@
 // specific language governing permissions and limitations
 // under the License.
 
-suite("inpredicate_with_struct") {
+suite("inpredicate_with_complex_type") {
     sql """ set enable_nereids_planner = true;"""
     sql """ set enable_fallback_to_original_planner=false;"""
-    // support struct type
-    order_qt_in_predicate_11 """
-         select struct(1,"2")  in (struct(1,3), null);
-    """
-    order_qt_in_predicate_12 """
-         select struct(1,"2")  not in (struct(1,3), null);
-    """
-    order_qt_in_predicate_13 """
-         select struct(1,"2")  in (struct(1,3), struct(1,2));
-    """
-    order_qt_in_predicate_14 """
-         select struct(1,"2")  not in (struct(1,3), struct(1,2));
-    """
-    order_qt_in_predicate_15 """
-         select struct(1,"2")  in (struct(1,3), struct(1,"2"), struct(1,1));
-    """
-    order_qt_in_predicate_16 """
-         select struct(1,"2")  not in (struct(1,3), struct(1,"2"), 
struct(1,1));
-    """
+
+    test {
+        sql """ select struct(1, "2") in (struct(1, 2)); """
+        exception "in predicate could not contains complex type"
+    }
+
+    test {
+        sql """ select struct(1, "2") not in (struct(1, 2)); """
+        exception "in predicate could not contains complex type"
+    }
+
+    test {
+        sql """ select [1, 2] in ([1, 2]); """
+        exception "in predicate could not contains complex type"
+    }
+
+    test {
+        sql """ select map('a', 1) in (map('a', 1)); """
+        exception "in predicate could not contains complex type"
+    }
+
+    test {
+        sql """ select 1 in (struct(1, 2)); """
+        exception "in predicate could not contains complex type"
+    }
 }
 
diff --git a/regression-test/suites/query_p0/sql_functions/test_in_expr.groovy 
b/regression-test/suites/query_p0/sql_functions/test_in_expr.groovy
index b6955e8df12..a40ef731631 100644
--- a/regression-test/suites/query_p0/sql_functions/test_in_expr.groovy
+++ b/regression-test/suites/query_p0/sql_functions/test_in_expr.groovy
@@ -131,22 +131,6 @@ suite("test_in_expr", "query") { // "arrow_flight_sql", 
groovy not support print
     SELECT CASE (TIMESTAMP '1970-12-04 03:51:34' NOT BETWEEN TIMESTAMP 
'1970-11-11 16:41:26' AND CURRENT_TIMESTAMP())  WHEN (0.7532032132148743 
BETWEEN 0.7817240953445435 AND CAST('.' AS FLOAT) ) THEN (- (- 2093562249))  
WHEN CAST((true IN (false)) AS BOOLEAN)  THEN (+ 1351956476) END  FROM t11 
WHERE (NULL IN (CASE CAST('-658171195' AS BOOLEAN)   WHEN ((TIMESTAMP 
'1970-02-25 22:11:59') IS NOT NULL) THEN NULL  WHEN ((true) IS NULL) THEN NULL 
END )) GROUP BY t11.c0 ORDER BY 1;
     """
 
-    sql " drop table if exists `array_in_test` "
-    sql """
-    CREATE TABLE `array_in_test` (
-        `id` int(11) NULL COMMENT "",
-        `c_array` ARRAY<int(11)> NULL COMMENT ""
-    )
-    DISTRIBUTED BY HASH(`id`) BUCKETS 1
-    PROPERTIES (
-    "replication_allocation" = "tag.location.default: 1"
-    );
-    """
-
-    sql """ INSERT INTO `array_in_test` VALUES (1, [1,2,3,4,5]); """
-
-    qt_select """ select c_array, c_array in (null) from array_in_test; """
-
     sql " drop table if exists `json_in_test` "
     sql """
         CREATE TABLE json_in_test (


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to