This is an automated email from the ASF dual-hosted git repository.
starocean999 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new e54c5de2204 [Enhancement] (nereids)implement DropSqlBlockRuleCommand
in nereids (#44302)
e54c5de2204 is described below
commit e54c5de220478565e85abf43e18ffadd5223b215
Author: Vallish Pai <[email protected]>
AuthorDate: Wed Nov 20 15:00:27 2024 +0530
[Enhancement] (nereids)implement DropSqlBlockRuleCommand in nereids (#44302)
Issue Number: close #42624
---
.../antlr4/org/apache/doris/nereids/DorisParser.g4 | 2 +-
.../apache/doris/blockrule/SqlBlockRuleMgr.java | 7 ++-
.../doris/nereids/parser/LogicalPlanBuilder.java | 7 +++
.../apache/doris/nereids/trees/plans/PlanType.java | 1 +
.../plans/commands/DropSqlBlockRuleCommand.java | 60 ++++++++++++++++++++++
.../trees/plans/visitor/CommandVisitor.java | 5 ++
.../data/sql_block_rule_p0/test_sql_block_rule.out | 8 ++-
.../sql_block_rule_p0/test_sql_block_rule.groovy | 23 ++++++++-
8 files changed, 107 insertions(+), 6 deletions(-)
diff --git a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4
b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4
index 948b0d5599f..97932c3bb2a 100644
--- a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4
+++ b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4
@@ -193,6 +193,7 @@ supportedAlterStatement
supportedDropStatement
: DROP CATALOG RECYCLE BIN WHERE idType=STRING_LITERAL EQ id=INTEGER_VALUE
#dropCatalogRecycleBin
| DROP ROLE (IF EXISTS)? name=identifier
#dropRole
+ | DROP SQL_BLOCK_RULE (IF EXISTS)? identifierSeq
#dropSqlBlockRule
;
supportedShowStatement
@@ -671,7 +672,6 @@ unsupportedDropStatement
| DROP WORKLOAD GROUP (IF EXISTS)? name=identifierOrText
#dropWorkloadGroup
| DROP WORKLOAD POLICY (IF EXISTS)? name=identifierOrText
#dropWorkloadPolicy
| DROP ENCRYPTKEY (IF EXISTS)? name=multipartIdentifier
#dropEncryptkey
- | DROP SQL_BLOCK_RULE (IF EXISTS)? identifierSeq
#dropSqlBlockRule
| DROP ROW POLICY (IF EXISTS)? policyName=identifier
ON tableName=multipartIdentifier
(FOR (userIdentify | ROLE roleName=identifier))?
#dropRowPolicy
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 c6dd0af4210..aa3b844f3e3 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
@@ -203,12 +203,15 @@ public class SqlBlockRuleMgr implements Writable {
* Drop SqlBlockRule for drop stmt.
**/
public void dropSqlBlockRule(DropSqlBlockRuleStmt stmt) throws
DdlException {
+ dropSqlBlockRule(stmt.getRuleNames(), stmt.isIfExists());
+ }
+
+ public void dropSqlBlockRule(List<String> ruleNames, boolean isIfExists)
throws DdlException {
writeLock();
try {
- List<String> ruleNames = stmt.getRuleNames();
for (String ruleName : ruleNames) {
if (!existRule(ruleName)) {
- if (stmt.isIfExists()) {
+ if (isIfExists) {
continue;
}
throw new DdlException("the sql block rule " + ruleName +
" not exist");
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
index 6b5e0b129c0..36b25e474df 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
@@ -101,6 +101,7 @@ import
org.apache.doris.nereids.DorisParser.DropConstraintContext;
import org.apache.doris.nereids.DorisParser.DropMTMVContext;
import org.apache.doris.nereids.DorisParser.DropProcedureContext;
import org.apache.doris.nereids.DorisParser.DropRoleContext;
+import org.apache.doris.nereids.DorisParser.DropSqlBlockRuleContext;
import org.apache.doris.nereids.DorisParser.ElementAtContext;
import org.apache.doris.nereids.DorisParser.ExceptContext;
import org.apache.doris.nereids.DorisParser.ExceptOrReplaceContext;
@@ -438,6 +439,7 @@ import
org.apache.doris.nereids.trees.plans.commands.DropConstraintCommand;
import org.apache.doris.nereids.trees.plans.commands.DropMTMVCommand;
import org.apache.doris.nereids.trees.plans.commands.DropProcedureCommand;
import org.apache.doris.nereids.trees.plans.commands.DropRoleCommand;
+import org.apache.doris.nereids.trees.plans.commands.DropSqlBlockRuleCommand;
import org.apache.doris.nereids.trees.plans.commands.ExplainCommand;
import
org.apache.doris.nereids.trees.plans.commands.ExplainCommand.ExplainLevel;
import org.apache.doris.nereids.trees.plans.commands.ExportCommand;
@@ -4248,6 +4250,11 @@ public class LogicalPlanBuilder extends
DorisParserBaseVisitor<Object> {
return new DropRoleCommand(ctx.name.getText(), ctx.EXISTS() != null);
}
+ @Override
+ public LogicalPlan visitDropSqlBlockRule(DropSqlBlockRuleContext ctx) {
+ return new
DropSqlBlockRuleCommand(visitIdentifierSeq(ctx.identifierSeq()), ctx.EXISTS()
!= null);
+ }
+
@Override
public LogicalPlan visitShowTableId(ShowTableIdContext ctx) {
long tableId = -1;
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/PlanType.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/PlanType.java
index 06a32bb3102..e040d18b82f 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/PlanType.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/PlanType.java
@@ -177,6 +177,7 @@ public enum PlanType {
REFRESH_CATALOG_COMMAND,
PREPARED_COMMAND,
EXECUTE_COMMAND,
+ DROP_SQL_BLOCK_RULE_COMMAND,
SHOW_BACKENDS_COMMAND,
SHOW_BLOCK_RULE_COMMAND,
SHOW_CONFIG_COMMAND,
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/DropSqlBlockRuleCommand.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/DropSqlBlockRuleCommand.java
new file mode 100644
index 00000000000..37ce9104a44
--- /dev/null
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/DropSqlBlockRuleCommand.java
@@ -0,0 +1,60 @@
+// 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.
+
+package org.apache.doris.nereids.trees.plans.commands;
+
+import org.apache.doris.catalog.Env;
+import org.apache.doris.common.ErrorCode;
+import org.apache.doris.common.ErrorReport;
+import org.apache.doris.mysql.privilege.PrivPredicate;
+import org.apache.doris.nereids.trees.plans.PlanType;
+import org.apache.doris.nereids.trees.plans.visitor.PlanVisitor;
+import org.apache.doris.qe.ConnectContext;
+import org.apache.doris.qe.StmtExecutor;
+
+import java.util.List;
+
+/**
+ * drop sql block rule command
+ */
+public class DropSqlBlockRuleCommand extends DropCommand {
+ private final boolean ifExists;
+ private List<String> ruleNames;
+
+ /**
+ * constructor
+ */
+ public DropSqlBlockRuleCommand(List<String> ruleNames, boolean ifExists) {
+ super(PlanType.DROP_SQL_BLOCK_RULE_COMMAND);
+ this.ruleNames = ruleNames;
+ this.ifExists = ifExists;
+ }
+
+ @Override
+ public void doRun(ConnectContext ctx, StmtExecutor executor) throws
Exception {
+ // check auth
+ if
(!Env.getCurrentEnv().getAccessManager().checkGlobalPriv(ConnectContext.get(),
PrivPredicate.ADMIN)) {
+
ErrorReport.reportAnalysisException(ErrorCode.ERR_SPECIFIC_ACCESS_DENIED_ERROR,
"ADMIN");
+ }
+ Env.getCurrentEnv().getSqlBlockRuleMgr().dropSqlBlockRule(ruleNames,
ifExists);
+ }
+
+ @Override
+ public <R, C> R accept(PlanVisitor<R, C> visitor, C context) {
+ return visitor.visitDropSqlBlockRuleCommand(this, context);
+ }
+}
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/visitor/CommandVisitor.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/visitor/CommandVisitor.java
index 5b77c5b5be0..9bffb5a376e 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/visitor/CommandVisitor.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/visitor/CommandVisitor.java
@@ -38,6 +38,7 @@ import
org.apache.doris.nereids.trees.plans.commands.DropConstraintCommand;
import org.apache.doris.nereids.trees.plans.commands.DropMTMVCommand;
import org.apache.doris.nereids.trees.plans.commands.DropProcedureCommand;
import org.apache.doris.nereids.trees.plans.commands.DropRoleCommand;
+import org.apache.doris.nereids.trees.plans.commands.DropSqlBlockRuleCommand;
import org.apache.doris.nereids.trees.plans.commands.ExplainCommand;
import org.apache.doris.nereids.trees.plans.commands.ExportCommand;
import org.apache.doris.nereids.trees.plans.commands.LoadCommand;
@@ -357,6 +358,10 @@ public interface CommandVisitor<R, C> {
return visitCommand(dropRoleCommand, context);
}
+ default R visitDropSqlBlockRuleCommand(DropSqlBlockRuleCommand
dropSqlBlockRuleCommand, C context) {
+ return visitCommand(dropSqlBlockRuleCommand, context);
+ }
+
default R visitShowTableIdCommand(ShowTableIdCommand showTableIdCommand, C
context) {
return visitCommand(showTableIdCommand, context);
}
diff --git a/regression-test/data/sql_block_rule_p0/test_sql_block_rule.out
b/regression-test/data/sql_block_rule_p0/test_sql_block_rule.out
index 373ec1348d1..c43c5201772 100644
--- a/regression-test/data/sql_block_rule_p0/test_sql_block_rule.out
+++ b/regression-test/data/sql_block_rule_p0/test_sql_block_rule.out
@@ -5,5 +5,11 @@ test_rule_sql SELECT abcd FROM table_2 NULL 0
0 0 true true
-- !select2 --
test_rule_sql SELECT abcd FROM table_2 NULL 0 0 0
true true
--- !select3 --
+-- !select3_notexist --
+
+-- !select4_exist --
+test_rule_sql SELECT \\* FROM table_2 NULL 0 0 0 true
true
+test_rule_sql1 SELECT \\* FROM table_2 NULL 0 0 0 true
true
+
+-- !select5_not_exist --
diff --git
a/regression-test/suites/sql_block_rule_p0/test_sql_block_rule.groovy
b/regression-test/suites/sql_block_rule_p0/test_sql_block_rule.groovy
index e0243e35a09..13b83d272de 100644
--- a/regression-test/suites/sql_block_rule_p0/test_sql_block_rule.groovy
+++ b/regression-test/suites/sql_block_rule_p0/test_sql_block_rule.groovy
@@ -92,8 +92,27 @@ suite("test_sql_block_rule", "nonConcurrent") {
SHOW SQL_BLOCK_RULE FOR test_rule_sql
"""
+ checkNereidsExecute("DROP SQL_BLOCK_RULE if exists test_rule_sql")
+
+ qt_select3_notexist """
+ SHOW SQL_BLOCK_RULE
+ """
+
sql """
- DROP SQL_BLOCK_RULE if exists test_rule_sql
+ CREATE SQL_BLOCK_RULE if not exists test_rule_sql
+ PROPERTIES("sql"="SELECT \\\\* FROM table_2", "global"=
"true", "enable"= "true")
+ """
+ sql """
+ CREATE SQL_BLOCK_RULE if not exists test_rule_sql1
+ PROPERTIES("sql"="SELECT \\\\* FROM table_2", "global"=
"true", "enable"= "true")
+ """
+
+ qt_select4_exist """
+ SHOW SQL_BLOCK_RULE
+ """
+
+ sql """
+ DROP SQL_BLOCK_RULE if exists test_rule_sql,test_rule_sql1
"""
sql """
@@ -110,7 +129,7 @@ suite("test_sql_block_rule", "nonConcurrent") {
exception "sql hits sql block rule: test_rule_num, reach tablet_num :
1"
}
*/
- qt_select3 """
+ qt_select5_not_exist """
SHOW SQL_BLOCK_RULE
"""
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]