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

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


The following commit(s) were added to refs/heads/branch-3.1 by this push:
     new adcae179701 branch-3.1: [fix](nereids) add "Check expression limit" 
back #52378 (#52565)
adcae179701 is described below

commit adcae17970127d92489eed8ec363c28961a9479c
Author: github-actions[bot] 
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Wed Jul 2 10:31:04 2025 +0800

    branch-3.1: [fix](nereids) add "Check expression limit" back #52378 (#52565)
    
    Cherry-picked from #52378
    
    Co-authored-by: minghong <[email protected]>
---
 .../nereids/trees/expressions/Expression.java      | 14 ++++++
 .../expression/expression_depth_check.groovy       | 56 ++++++++++++++++++++++
 2 files changed, 70 insertions(+)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Expression.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Expression.java
index aa81c2ae685..13f7d1b764c 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Expression.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Expression.java
@@ -17,6 +17,7 @@
 
 package org.apache.doris.nereids.trees.expressions;
 
+import org.apache.doris.common.Config;
 import org.apache.doris.nereids.analyzer.Unbound;
 import org.apache.doris.nereids.analyzer.UnboundVariable;
 import org.apache.doris.nereids.exceptions.AnalysisException;
@@ -117,6 +118,7 @@ public abstract class Expression extends 
AbstractTreeNode<Expression> implements
                 this.compareWidthAndDepth = compareWidthAndDepth;
                 this.fastChildrenHashCode = fastChildrenHashCode;
         }
+        checkLimit();
         this.inferred = false;
         this.hasUnbound = hasUnbound || this instanceof Unbound;
     }
@@ -170,10 +172,22 @@ public abstract class Expression extends 
AbstractTreeNode<Expression> implements
                 this.compareWidthAndDepth = compareWidthAndDepth && 
supportCompareWidthAndDepth();
                 this.fastChildrenHashCode = fastChildrenhashCode;
         }
+        checkLimit();
         this.inferred = inferred;
         this.hasUnbound = hasUnbound || this instanceof Unbound;
     }
 
+    private void checkLimit() {
+        if (depth > Config.expr_depth_limit) {
+            throw new AnalysisException(String.format("Exceeded the maximum 
depth of an "
+                    + "expression tree (%s).", Config.expr_depth_limit));
+        }
+        if (width > Config.expr_children_limit) {
+            throw new AnalysisException(String.format("Exceeded the maximum 
children of an "
+                    + "expression tree (%s).", Config.expr_children_limit));
+        }
+    }
+
     public Alias alias(String alias) {
         return new Alias(this, alias);
     }
diff --git 
a/regression-test/suites/nereids_p0/expression/expression_depth_check.groovy 
b/regression-test/suites/nereids_p0/expression/expression_depth_check.groovy
new file mode 100644
index 00000000000..8fd2a2a726a
--- /dev/null
+++ b/regression-test/suites/nereids_p0/expression/expression_depth_check.groovy
@@ -0,0 +1,56 @@
+// 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.
+
+suite("expression_depth_check", "nonConcurrent") {
+    sql """
+        drop table if exists tbl1;
+        CREATE TABLE tbl1
+        (
+            k1 int,
+            k2 int
+        )
+        DISTRIBUTED BY HASH(k1) BUCKETS 6
+        PROPERTIES
+        (
+            "replication_num" = "1"
+        );
+        select floor(abs(ceil(1+k1))) from tbl1;
+    """
+    sql """
+        admin set frontend config("expr_depth_limit" = "3");
+    """
+    def depthCheckFailed = true;
+    try {
+        sql """ 
+        select floor(abs(ceil(1+k1))) from tbl1
+        """
+    } catch (Exception e) {
+        if (e.getMessage().contains("Exceeded the maximum depth of an 
expression tree (3)")) {
+            depthCheckFailed = false;
+        }
+    } finally {
+        sql """
+        admin set frontend config("expr_depth_limit" = "3000");
+        """
+        if (depthCheckFailed) {
+            throw new RuntimeException("check expression depth failed")
+        }
+    }
+
+     
+
+}
\ No newline at end of file


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

Reply via email to