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

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


The following commit(s) were added to refs/heads/branch-2.1 by this push:
     new a3032bb7370 [fix](nereids)fix sql be blocked  fall back to legacy 
planner (#54415)
a3032bb7370 is described below

commit a3032bb7370d42664a4176108284124b4579126b
Author: feiniaofeiafei <[email protected]>
AuthorDate: Fri Aug 8 09:37:05 2025 +0800

    [fix](nereids)fix sql be blocked  fall back to legacy planner (#54415)
---
 .../apache/doris/blockrule/SqlBlockRuleMgr.java    | 27 +++++++++---------
 .../java/org/apache/doris/qe/StmtExecutor.java     |  6 ++--
 .../doris/blockrule/SqlBlockRuleMgrTest.java       | 15 +++++-----
 .../sql_block_rule_p0/block_not_fall_back.groovy   | 33 ++++++++++++++++++++++
 4 files changed, 58 insertions(+), 23 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/blockrule/SqlBlockRuleMgr.java 
b/fe/fe-core/src/main/java/org/apache/doris/blockrule/SqlBlockRuleMgr.java
index 13df2eb9377..199976266a4 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/blockrule/SqlBlockRuleMgr.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/blockrule/SqlBlockRuleMgr.java
@@ -31,6 +31,7 @@ import org.apache.doris.common.io.Writable;
 import org.apache.doris.common.util.SqlBlockUtil;
 import org.apache.doris.metric.MetricRepo;
 import org.apache.doris.mysql.privilege.Auth;
+import org.apache.doris.nereids.exceptions.DoNotFallbackException;
 import org.apache.doris.persist.gson.GsonUtils;
 import org.apache.doris.qe.ConnectContext;
 
@@ -226,7 +227,7 @@ public class SqlBlockRuleMgr implements Writable {
     /**
      * Match SQL according to rules.
      **/
-    public void matchSql(String originSql, String sqlHash, String user) throws 
AnalysisException {
+    public void matchSql(String originSql, String sqlHash, String user) {
         if (Config.sql_block_rule_ignore_admin && (Auth.ROOT_USER.equals(user) 
|| Auth.ADMIN_USER.equals(user))) {
             return;
         }
@@ -251,16 +252,18 @@ public class SqlBlockRuleMgr implements Writable {
         }
     }
 
-    private void matchSql(SqlBlockRule rule, String originSql, String sqlHash) 
throws AnalysisException {
+    private void matchSql(SqlBlockRule rule, String originSql, String sqlHash) 
{
         if (rule.getEnable()) {
             if (StringUtils.isNotEmpty(rule.getSqlHash()) && 
!SqlBlockUtil.STRING_DEFAULT.equals(rule.getSqlHash())
                     && rule.getSqlHash().equals(sqlHash)) {
                 MetricRepo.COUNTER_HIT_SQL_BLOCK_RULE.increase(1L);
-                throw new AnalysisException("sql match hash sql block rule: " 
+ rule.getName());
+                throw new DoNotFallbackException("sql match hash sql block 
rule: "
+                        + rule.getName());
             } else if (StringUtils.isNotEmpty(rule.getSql()) && 
!SqlBlockUtil.STRING_DEFAULT.equals(rule.getSql())
                     && rule.getSqlPattern() != null && 
rule.getSqlPattern().matcher(originSql).find()) {
                 MetricRepo.COUNTER_HIT_SQL_BLOCK_RULE.increase(1L);
-                throw new AnalysisException("sql match regex sql block rule: " 
+ rule.getName());
+                throw new DoNotFallbackException("sql match regex sql block 
rule: "
+                        + rule.getName());
             }
         }
     }
@@ -268,8 +271,7 @@ public class SqlBlockRuleMgr implements Writable {
     /**
      * Check number whether legal by user.
      **/
-    public void checkLimitations(Long partitionNum, Long tabletNum, Long 
cardinality, String user)
-            throws AnalysisException {
+    public void checkLimitations(Long partitionNum, Long tabletNum, Long 
cardinality, String user) {
         if (ConnectContext.get().getSessionVariable().internalSession) {
             return;
         }
@@ -293,8 +295,7 @@ public class SqlBlockRuleMgr implements Writable {
     /**
      * Check number whether legal by SqlBlockRule.
      **/
-    private void checkLimitations(SqlBlockRule rule, Long partitionNum, Long 
tabletNum, Long cardinality)
-            throws AnalysisException {
+    private void checkLimitations(SqlBlockRule rule, Long partitionNum, Long 
tabletNum, Long cardinality) {
         if (rule.getPartitionNum() == 0 && rule.getTabletNum() == 0 && 
rule.getCardinality() == 0) {
             return;
         } else if (rule.getEnable()) {
@@ -303,15 +304,15 @@ public class SqlBlockRuleMgr implements Writable {
                     && rule.getCardinality() < cardinality)) {
                 MetricRepo.COUNTER_HIT_SQL_BLOCK_RULE.increase(1L);
                 if (rule.getPartitionNum() < partitionNum && 
rule.getPartitionNum() != 0) {
-                    throw new AnalysisException(
+                    throw new DoNotFallbackException(
                             "sql hits sql block rule: " + rule.getName() + ", 
reach partition_num : "
                                     + rule.getPartitionNum());
                 } else if (rule.getTabletNum() < tabletNum && 
rule.getTabletNum() != 0) {
-                    throw new AnalysisException("sql hits sql block rule: " + 
rule.getName() + ", reach tablet_num : "
-                            + rule.getTabletNum());
+                    throw new DoNotFallbackException("sql hits sql block rule: 
" + rule.getName()
+                            + ", reach tablet_num : " + rule.getTabletNum());
                 } else if (rule.getCardinality() < cardinality && 
rule.getCardinality() != 0) {
-                    throw new AnalysisException("sql hits sql block rule: " + 
rule.getName() + ", reach cardinality : "
-                            + rule.getCardinality());
+                    throw new DoNotFallbackException("sql hits sql block rule: 
" + rule.getName()
+                            + ", reach cardinality : " + 
rule.getCardinality());
                 }
             }
         }
diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java 
b/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java
index f5ab4137f29..05bb067acca 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java
@@ -632,12 +632,12 @@ public class StmtExecutor {
         }
     }
 
-    public void checkBlockRules() throws AnalysisException {
+    public void checkBlockRules() {
         checkBlockRulesByRegex(originStmt);
         checkBlockRulesByScan(planner);
     }
 
-    public void checkBlockRulesByRegex(OriginStatement originStmt) throws 
AnalysisException {
+    public void checkBlockRulesByRegex(OriginStatement originStmt) {
         if (originStmt == null) {
             return;
         }
@@ -645,7 +645,7 @@ public class StmtExecutor {
                 originStmt.originStmt, context.getSqlHash(), 
context.getQualifiedUser());
     }
 
-    public void checkBlockRulesByScan(Planner planner) throws 
AnalysisException {
+    public void checkBlockRulesByScan(Planner planner) {
         if (planner == null) {
             return;
         }
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/blockrule/SqlBlockRuleMgrTest.java 
b/fe/fe-core/src/test/java/org/apache/doris/blockrule/SqlBlockRuleMgrTest.java
index b1684ef74a0..98fa9b2cb67 100644
--- 
a/fe/fe-core/src/test/java/org/apache/doris/blockrule/SqlBlockRuleMgrTest.java
+++ 
b/fe/fe-core/src/test/java/org/apache/doris/blockrule/SqlBlockRuleMgrTest.java
@@ -26,6 +26,7 @@ import org.apache.doris.common.Config;
 import org.apache.doris.common.DdlException;
 import org.apache.doris.common.ExceptionChecker;
 import org.apache.doris.metric.MetricRepo;
+import org.apache.doris.nereids.exceptions.DoNotFallbackException;
 import org.apache.doris.utframe.TestWithFeService;
 import org.apache.doris.utframe.UtFrameUtils;
 
@@ -76,7 +77,7 @@ public class SqlBlockRuleMgrTest extends TestWithFeService {
         String setPropertyStr = "set property for \"root\" \"sql_block_rules\" 
= \"test_rule\"";
         SetUserPropertyStmt setUserPropertyStmt = (SetUserPropertyStmt) 
parseAndAnalyzeStmt(setPropertyStr);
         Env.getCurrentEnv().getAuth().updateUserProperty(setUserPropertyStmt);
-        ExceptionChecker.expectThrowsWithMsg(AnalysisException.class, "sql 
match hash sql block rule: test_rule",
+        ExceptionChecker.expectThrowsWithMsg(DoNotFallbackException.class, 
"sql match hash sql block rule: test_rule",
                 () -> Env.getCurrentEnv().getSqlBlockRuleMgr().matchSql(sql, 
sqlHash, "root"));
         dropSqlBlockRule(dropSqlRule);
     }
@@ -88,7 +89,7 @@ public class SqlBlockRuleMgrTest extends TestWithFeService {
         String sqlRule = "CREATE SQL_BLOCK_RULE test_rule 
PROPERTIES(\"sql\"=\"select \\\\* from test_table1\","
                 + " \"global\"=\"true\", \"enable\"=\"true\");";
         createSqlBlockRule(sqlRule);
-        ExceptionChecker.expectThrowsWithMsg(AnalysisException.class, "sql 
match regex sql block rule: test_rule",
+        ExceptionChecker.expectThrowsWithMsg(DoNotFallbackException.class, 
"sql match regex sql block rule: test_rule",
                 () -> mgr.matchSql(sql, sqlHash, "test"));
         dropSqlBlockRule(dropSqlRule);
     }
@@ -100,7 +101,7 @@ public class SqlBlockRuleMgrTest extends TestWithFeService {
         String sqlRule = "CREATE SQL_BLOCK_RULE test_rule 
PROPERTIES(\"sql\"=\".* join .*\", \"global\"=\"true\","
                 + " \"enable\"=\"true\");";
         createSqlBlockRule(sqlRule);
-        ExceptionChecker.expectThrowsWithMsg(AnalysisException.class, "sql 
match regex sql block rule: test_rule",
+        ExceptionChecker.expectThrowsWithMsg(DoNotFallbackException.class, 
"sql match regex sql block rule: test_rule",
                 () -> mgr.matchSql(sql, sqlHash, "root"));
         dropSqlBlockRule(dropSqlRule);
     }
@@ -112,7 +113,7 @@ public class SqlBlockRuleMgrTest extends TestWithFeService {
         String sqlRule = "CREATE SQL_BLOCK_RULE test_rule 
PROPERTIES(\"sqlHash\"=\"" + sqlHash
                 + "\", \"global\"=\"true\", \"enable\"=\"true\");";
         createSqlBlockRule(sqlRule);
-        ExceptionChecker.expectThrowsWithMsg(AnalysisException.class, "sql 
match hash sql block rule: test_rule",
+        ExceptionChecker.expectThrowsWithMsg(DoNotFallbackException.class, 
"sql match hash sql block rule: test_rule",
                 () -> mgr.matchSql(sql, sqlHash, "root"));
         dropSqlBlockRule(dropSqlRule);
     }
@@ -313,16 +314,16 @@ public class SqlBlockRuleMgrTest extends 
TestWithFeService {
                 + " \"global\"=\"true\", \"enable\"=\"true\");";
         createSqlBlockRule(sqlRule);
         Config.sql_block_rule_ignore_admin = false;
-        ExceptionChecker.expectThrowsWithMsg(AnalysisException.class,
+        ExceptionChecker.expectThrowsWithMsg(DoNotFallbackException.class,
                 "sql match regex sql block rule: test_rule",
                 () -> mgr.matchSql(sql, sqlHash, "root"));
-        ExceptionChecker.expectThrowsWithMsg(AnalysisException.class,
+        ExceptionChecker.expectThrowsWithMsg(DoNotFallbackException.class,
                 "sql match regex sql block rule: test_rule",
                 () -> mgr.matchSql(sql, sqlHash, "admin"));
         Config.sql_block_rule_ignore_admin = true;
         ExceptionChecker.expectThrowsNoException(() -> mgr.matchSql(sql, 
sqlHash, "root"));
         ExceptionChecker.expectThrowsNoException(() -> mgr.matchSql(sql, 
sqlHash, "admin"));
-        ExceptionChecker.expectThrowsWithMsg(AnalysisException.class,
+        ExceptionChecker.expectThrowsWithMsg(DoNotFallbackException.class,
                 "sql match regex sql block rule: test_rule",
                 () -> mgr.matchSql(sql, sqlHash, "other_user"));
         Config.sql_block_rule_ignore_admin = false;
diff --git 
a/regression-test/suites/sql_block_rule_p0/block_not_fall_back.groovy 
b/regression-test/suites/sql_block_rule_p0/block_not_fall_back.groovy
new file mode 100644
index 00000000000..01bb809cf7c
--- /dev/null
+++ b/regression-test/suites/sql_block_rule_p0/block_not_fall_back.groovy
@@ -0,0 +1,33 @@
+// 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("block_not_fall_back") {
+    sql "SET enable_fallback_to_original_planner=true;"
+    sql "drop SQL_BLOCK_RULE if exists rule_001"
+    // legacy parser not support "==", if fall back legacy planner, will 
report sytax error
+    sql """CREATE SQL_BLOCK_RULE rule_001
+    PROPERTIES (
+            "sql"="select 1==1",
+            "global" = "true",
+            "enable" = "true"
+    );"""
+
+    test {
+        sql "select 1==1;"
+        exception "sql match regex sql block rule: rule_001"
+    }
+    sql "drop SQL_BLOCK_RULE if exists rule_001"
+}
\ No newline at end of file


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

Reply via email to