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 95fdd45600b [Enhancement] (nereids)implement DropEncryptKeyCommand in nereids (#44506) 95fdd45600b is described below commit 95fdd45600b4357a0ea8b6a0d1c0ac6182dd0500 Author: Vallish Pai <vallish...@gmail.com> AuthorDate: Tue Nov 26 13:35:46 2024 +0530 [Enhancement] (nereids)implement DropEncryptKeyCommand in nereids (#44506) Issue Number: close #42623 --- .../antlr4/org/apache/doris/nereids/DorisParser.g4 | 2 +- .../org/apache/doris/analysis/EncryptKeyName.java | 25 +++++++++ .../doris/nereids/parser/LogicalPlanBuilder.java | 9 +++ .../apache/doris/nereids/trees/plans/PlanType.java | 1 + .../plans/commands/DropEncryptkeyCommand.java | 65 ++++++++++++++++++++++ .../trees/plans/visitor/CommandVisitor.java | 5 ++ .../data/nereids_p0/test_nereids_encrypt_test.out | 8 +++ .../nereids_p0/test_nereids_encrypt_test.groovy | 29 ++++++++++ 8 files changed, 143 insertions(+), 1 deletion(-) 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 c662ee295b6..932f644fca4 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 @@ -199,6 +199,7 @@ supportedAlterStatement supportedDropStatement : DROP CATALOG RECYCLE BIN WHERE idType=STRING_LITERAL EQ id=INTEGER_VALUE #dropCatalogRecycleBin + | DROP ENCRYPTKEY (IF EXISTS)? name=multipartIdentifier #dropEncryptkey | DROP ROLE (IF EXISTS)? name=identifier #dropRole | DROP SQL_BLOCK_RULE (IF EXISTS)? identifierSeq #dropSqlBlockRule | DROP USER (IF EXISTS)? userIdentify #dropUser @@ -673,7 +674,6 @@ unsupportedDropStatement | DROP INDEX (IF EXISTS)? name=identifier ON tableName=multipartIdentifier #dropIndex | DROP RESOURCE (IF EXISTS)? name=identifierOrText #dropResource | DROP WORKLOAD POLICY (IF EXISTS)? name=identifierOrText #dropWorkloadPolicy - | DROP ENCRYPTKEY (IF EXISTS)? name=multipartIdentifier #dropEncryptkey | 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/analysis/EncryptKeyName.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/EncryptKeyName.java index 155f1753bf4..e76bfb7e5b2 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/EncryptKeyName.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/EncryptKeyName.java @@ -25,6 +25,7 @@ import org.apache.doris.common.FeNameFormat; import org.apache.doris.common.io.Text; import org.apache.doris.common.io.Writable; import org.apache.doris.persist.gson.GsonUtils; +import org.apache.doris.qe.ConnectContext; import com.google.common.base.Strings; import com.google.gson.annotations.SerializedName; @@ -34,6 +35,7 @@ import org.apache.logging.log4j.Logger; import java.io.DataInput; import java.io.DataOutput; import java.io.IOException; +import java.util.List; import java.util.Objects; public class EncryptKeyName implements Writable { @@ -52,6 +54,19 @@ public class EncryptKeyName implements Writable { } } + /** + * EncryptKeyName + * @param parts like [db1,keyName] or [keyName] + */ + public EncryptKeyName(List<String> parts) { + int size = parts.size(); + keyName = parts.get(size - 1); + keyName = keyName.toLowerCase(); + if (size >= 2) { + db = parts.get(size - 2); + } + } + public EncryptKeyName(String keyName) { this.db = null; this.keyName = keyName.toLowerCase(); @@ -67,6 +82,16 @@ public class EncryptKeyName implements Writable { } } + public void analyze(ConnectContext ctx) throws AnalysisException { + FeNameFormat.checkCommonName("EncryptKey", keyName); + if (db == null) { + db = ctx.getDatabase(); + if (Strings.isNullOrEmpty(db)) { + ErrorReport.reportAnalysisException(ErrorCode.ERR_NO_DB_ERROR); + } + } + } + public String getDb() { return db; } 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 dc0fe2aa4a1..320043e12b8 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 @@ -20,6 +20,7 @@ package org.apache.doris.nereids.parser; import org.apache.doris.analysis.ArithmeticExpr.Operator; import org.apache.doris.analysis.BrokerDesc; import org.apache.doris.analysis.ColumnNullableType; +import org.apache.doris.analysis.EncryptKeyName; import org.apache.doris.analysis.PassVar; import org.apache.doris.analysis.SetType; import org.apache.doris.analysis.StorageBackend; @@ -100,6 +101,7 @@ import org.apache.doris.nereids.DorisParser.DeleteContext; import org.apache.doris.nereids.DorisParser.DereferenceContext; import org.apache.doris.nereids.DorisParser.DropCatalogRecycleBinContext; import org.apache.doris.nereids.DorisParser.DropConstraintContext; +import org.apache.doris.nereids.DorisParser.DropEncryptkeyContext; import org.apache.doris.nereids.DorisParser.DropMTMVContext; import org.apache.doris.nereids.DorisParser.DropProcedureContext; import org.apache.doris.nereids.DorisParser.DropRoleContext; @@ -450,6 +452,7 @@ import org.apache.doris.nereids.trees.plans.commands.DeleteFromUsingCommand; import org.apache.doris.nereids.trees.plans.commands.DropCatalogRecycleBinCommand; import org.apache.doris.nereids.trees.plans.commands.DropCatalogRecycleBinCommand.IdType; import org.apache.doris.nereids.trees.plans.commands.DropConstraintCommand; +import org.apache.doris.nereids.trees.plans.commands.DropEncryptkeyCommand; import org.apache.doris.nereids.trees.plans.commands.DropJobCommand; import org.apache.doris.nereids.trees.plans.commands.DropMTMVCommand; import org.apache.doris.nereids.trees.plans.commands.DropProcedureCommand; @@ -4375,6 +4378,12 @@ public class LogicalPlanBuilder extends DorisParserBaseVisitor<Object> { return new DropRoleCommand(ctx.name.getText(), ctx.EXISTS() != null); } + @Override + public LogicalPlan visitDropEncryptkey(DropEncryptkeyContext ctx) { + List<String> nameParts = visitMultipartIdentifier(ctx.name); + return new DropEncryptkeyCommand(new EncryptKeyName(nameParts), ctx.EXISTS() != null); + } + @Override public LogicalPlan visitDropSqlBlockRule(DropSqlBlockRuleContext ctx) { return new DropSqlBlockRuleCommand(visitIdentifierSeq(ctx.identifierSeq()), ctx.EXISTS() != null); 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 04551da904b..1f7b838edfd 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 @@ -172,6 +172,7 @@ public enum PlanType { ALTER_STORAGE_VAULT, ALTER_WORKLOAD_GROUP_COMMAND, DROP_CATALOG_RECYCLE_BIN_COMMAND, + DROP_ENCRYPTKEY_COMMAND, UNSET_VARIABLE_COMMAND, UNSET_DEFAULT_STORAGE_VAULT_COMMAND, UNSUPPORTED_COMMAND, diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/DropEncryptkeyCommand.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/DropEncryptkeyCommand.java new file mode 100644 index 00000000000..4c163d342d6 --- /dev/null +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/DropEncryptkeyCommand.java @@ -0,0 +1,65 @@ +// 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.analysis.EncryptKeyName; +import org.apache.doris.catalog.Database; +import org.apache.doris.catalog.EncryptKeySearchDesc; +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; + +/** + * drop encrypt key command + */ +public class DropEncryptkeyCommand extends DropCommand { + private final boolean ifExists; + private final EncryptKeyName encryptKeyName; + + /** + * constructor + */ + public DropEncryptkeyCommand(EncryptKeyName encryptKeyName, boolean ifExists) { + super(PlanType.DROP_ENCRYPTKEY_COMMAND); + this.encryptKeyName = encryptKeyName; + this.ifExists = ifExists; + } + + @Override + public void doRun(ConnectContext ctx, StmtExecutor executor) throws Exception { + // check operation privilege + if (!Env.getCurrentEnv().getAccessManager().checkGlobalPriv(ConnectContext.get(), PrivPredicate.ADMIN)) { + ErrorReport.reportAnalysisException(ErrorCode.ERR_SPECIFIC_ACCESS_DENIED_ERROR, "ADMIN"); + } + // analyze encryptkey name + encryptKeyName.analyze(ctx); + EncryptKeySearchDesc encryptKeySearchDesc = new EncryptKeySearchDesc(encryptKeyName); + Database db = Env.getCurrentInternalCatalog().getDbOrDdlException(encryptKeyName.getDb()); + db.dropEncryptKey(encryptKeySearchDesc, ifExists); + } + + @Override + public <R, C> R accept(PlanVisitor<R, C> visitor, C context) { + return visitor.visitDropEncryptKeyCommand(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 13eeef18264..6b801524fb2 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 @@ -39,6 +39,7 @@ import org.apache.doris.nereids.trees.plans.commands.DeleteFromCommand; import org.apache.doris.nereids.trees.plans.commands.DeleteFromUsingCommand; import org.apache.doris.nereids.trees.plans.commands.DropCatalogRecycleBinCommand; import org.apache.doris.nereids.trees.plans.commands.DropConstraintCommand; +import org.apache.doris.nereids.trees.plans.commands.DropEncryptkeyCommand; import org.apache.doris.nereids.trees.plans.commands.DropJobCommand; import org.apache.doris.nereids.trees.plans.commands.DropMTMVCommand; import org.apache.doris.nereids.trees.plans.commands.DropProcedureCommand; @@ -422,6 +423,10 @@ public interface CommandVisitor<R, C> { return visitCommand(dropRoleCommand, context); } + default R visitDropEncryptKeyCommand(DropEncryptkeyCommand dropEncryptkeyCommand, C context) { + return visitCommand(dropEncryptkeyCommand, context); + } + default R visitDropSqlBlockRuleCommand(DropSqlBlockRuleCommand dropSqlBlockRuleCommand, C context) { return visitCommand(dropSqlBlockRuleCommand, context); } diff --git a/regression-test/data/nereids_p0/test_nereids_encrypt_test.out b/regression-test/data/nereids_p0/test_nereids_encrypt_test.out new file mode 100644 index 00000000000..7984f572e8f --- /dev/null +++ b/regression-test/data/nereids_p0/test_nereids_encrypt_test.out @@ -0,0 +1,8 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !check_encrypt_1 -- +test_nereids_encrypt_test_db.test_nereids_encrypt_test_key ABCD123456789 + +-- !check_encrypt_2 -- + +-- !check_encrypt_3 -- + diff --git a/regression-test/suites/nereids_p0/test_nereids_encrypt_test.groovy b/regression-test/suites/nereids_p0/test_nereids_encrypt_test.groovy new file mode 100644 index 00000000000..2fab616580f --- /dev/null +++ b/regression-test/suites/nereids_p0/test_nereids_encrypt_test.groovy @@ -0,0 +1,29 @@ +// 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("test_nereids_encrypt_test") { + def dbName="test_nereids_encrypt_test_db" + def encryptkeyName="test_nereids_encrypt_test_key" + sql """ create database IF NOT EXISTS ${dbName}; """ + sql """ use ${dbName}; """ + checkNereidsExecute("drop encryptkey if exists ${encryptkeyName}") + sql """CREATE ENCRYPTKEY ${encryptkeyName} AS "ABCD123456789";""" + qt_check_encrypt_1("SHOW ENCRYPTKEYS FROM ${dbName}") + checkNereidsExecute("drop encryptkey ${encryptkeyName}") + qt_check_encrypt_2("SHOW ENCRYPTKEYS FROM ${dbName}") + checkNereidsExecute("drop encryptkey if exists ${encryptkeyName}") + qt_check_encrypt_3("SHOW ENCRYPTKEYS FROM ${dbName}") +} \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org