From 34801a8fa6d2fcab5b7d4004e7db7dce87b32d22 Mon Sep 17 00:00:00 2001 From: Vallish Date: Wed, 4 Dec 2024 14:45:50 +0000 Subject: [PATCH] [Enhancement] (nereids)implement DropRepositoryCommand in nereids --- be/src/clucene | 2 +- .../org/apache/doris/nereids/DorisParser.g4 | 3 +- .../apache/doris/backup/BackupHandler.java | 7 +- .../nereids/parser/LogicalPlanBuilder.java | 7 ++ .../doris/nereids/trees/plans/PlanType.java | 1 + .../plans/commands/AlterRoleCommand.java | 3 - .../plans/commands/DropRepositoryCommand.java | 67 +++++++++++++++++++ .../plans/commands/ShowGrantsCommand.java | 3 - .../commands/ShowPartitionIdCommand.java | 3 - .../trees/plans/commands/ShowProcCommand.java | 4 -- .../plans/commands/ShowRolesCommand.java | 4 -- .../plans/commands/ShowTableIdCommand.java | 3 - .../trees/plans/visitor/CommandVisitor.java | 13 ++-- .../show_repositories_command.groovy | 2 +- 14 files changed, 94 insertions(+), 28 deletions(-) create mode 100644 fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/DropRepositoryCommand.java diff --git a/be/src/clucene b/be/src/clucene index a506dbb6c523aa6..48fa9cc4ec32b40 160000 --- a/be/src/clucene +++ b/be/src/clucene @@ -1 +1 @@ -Subproject commit a506dbb6c523aa65044eb1c527a066d236172543 +Subproject commit 48fa9cc4ec32b40bf3b02338d0a1b2cdbc6408cf 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 1fb5897066f0216..b9c393bd6397a0c 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 @@ -216,6 +216,8 @@ supportedDropStatement | DROP FILE name=STRING_LITERAL ((FROM | IN) database=identifier)? properties=propertyClause #dropFile | DROP WORKLOAD POLICY (IF EXISTS)? name=identifierOrText #dropWorkloadPolicy + | DROP REPOSITORY name=identifier #dropRepository + ; supportedShowStatement @@ -684,7 +686,6 @@ unsupportedDropStatement functionIdentifier LEFT_PAREN functionArguments? RIGHT_PAREN #dropFunction | DROP TABLE (IF EXISTS)? name=multipartIdentifier FORCE? #dropTable | DROP VIEW (IF EXISTS)? name=multipartIdentifier #dropView - | DROP REPOSITORY name=identifier #dropRepository | DROP INDEX (IF EXISTS)? name=identifier ON tableName=multipartIdentifier #dropIndex | DROP RESOURCE (IF EXISTS)? name=identifierOrText #dropResource | DROP ROW POLICY (IF EXISTS)? policyName=identifier diff --git a/fe/fe-core/src/main/java/org/apache/doris/backup/BackupHandler.java b/fe/fe-core/src/main/java/org/apache/doris/backup/BackupHandler.java index d70544add98747d..6a12eee3a78cb38 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/backup/BackupHandler.java +++ b/fe/fe-core/src/main/java/org/apache/doris/backup/BackupHandler.java @@ -281,9 +281,14 @@ public void alterRepository(AlterRepositoryStmt stmt) throws DdlException { // handle drop repository stmt public void dropRepository(DropRepositoryStmt stmt) throws DdlException { + dropRepository(stmt.getRepoName()); + } + + // handle drop repository stmt + public void dropRepository(String repoName) throws DdlException { tryLock(); try { - Repository repo = repoMgr.getRepo(stmt.getRepoName()); + Repository repo = repoMgr.getRepo(repoName); if (repo == null) { ErrorReport.reportDdlException(ErrorCode.ERR_COMMON_ERROR, "Repository does 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 9866b410c8fbb01..e0832dcf2f84f22 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 @@ -118,6 +118,7 @@ import org.apache.doris.nereids.DorisParser.DropFileContext; import org.apache.doris.nereids.DorisParser.DropMTMVContext; import org.apache.doris.nereids.DorisParser.DropProcedureContext; +import org.apache.doris.nereids.DorisParser.DropRepositoryContext; import org.apache.doris.nereids.DorisParser.DropRoleContext; import org.apache.doris.nereids.DorisParser.DropSqlBlockRuleContext; import org.apache.doris.nereids.DorisParser.DropUserContext; @@ -507,6 +508,7 @@ 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; +import org.apache.doris.nereids.trees.plans.commands.DropRepositoryCommand; 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.DropUserCommand; @@ -4860,6 +4862,11 @@ public LogicalPlan visitDropFile(DropFileContext ctx) { return new DropFileCommand(stripQuotes(ctx.name.getText()), dbName, properties); } + @Override + public LogicalPlan visitDropRepository(DropRepositoryContext ctx) { + return new DropRepositoryCommand(stripQuotes(ctx.name.getText())); + } + @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 969b51ee99afe44..9e424542eabf774 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 @@ -168,6 +168,7 @@ public enum PlanType { CREATE_PROCEDURE_COMMAND, DROP_PROCEDURE_COMMAND, DROP_ROLE_COMMAND, + DROP_REPOSITOORY_COMMAND, SHOW_PROCEDURE_COMMAND, SHOW_CREATE_PROCEDURE_COMMAND, CREATE_VIEW_COMMAND, diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/AlterRoleCommand.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/AlterRoleCommand.java index fe8d0fd5db95a1b..9f2d4ba22745eac 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/AlterRoleCommand.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/AlterRoleCommand.java @@ -27,14 +27,11 @@ import org.apache.doris.qe.StmtExecutor; import com.google.common.base.Strings; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; /** * alter role command */ public class AlterRoleCommand extends AlterCommand { - public static final Logger LOG = LogManager.getLogger(AlterRoleCommand.class); private final String role; private final String comment; diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/DropRepositoryCommand.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/DropRepositoryCommand.java new file mode 100644 index 000000000000000..4fef49c39937ed1 --- /dev/null +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/DropRepositoryCommand.java @@ -0,0 +1,67 @@ +// 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.DdlException; +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 org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +/** + * drop repository command + */ +public class DropRepositoryCommand extends DropCommand { + public static final Logger LOG = LogManager.getLogger(DropRepositoryCommand.class); + private final String repoName; + + /** + * constructor + */ + public DropRepositoryCommand(String repoName) { + super(PlanType.DROP_REPOSITOORY_COMMAND); + this.repoName = repoName; + } + + @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().getBackupHandler().dropRepository(repoName); + } + + @Override + public R accept(PlanVisitor visitor, C context) { + return visitor.visitDropRepositoryCommand(this, context); + } + + @Override + protected void checkSupportedInCloudMode(ConnectContext ctx) throws DdlException { + LOG.info("DropRepositoryCommand not supported in cloud mode"); + throw new DdlException("Unsupported operation"); + } +} diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowGrantsCommand.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowGrantsCommand.java index f877f42b83599f5..6d52d374fa7ae4f 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowGrantsCommand.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowGrantsCommand.java @@ -34,8 +34,6 @@ import org.apache.doris.qe.StmtExecutor; import com.google.common.base.Preconditions; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import java.util.List; @@ -43,7 +41,6 @@ * show grants command */ public class ShowGrantsCommand extends ShowCommand { - public static final Logger LOG = LogManager.getLogger(ShowGrantsCommand.class); private static final ShowResultSetMetaData META_DATA; private final boolean isAll; private UserIdentity userIdent; // if not given will update with self. diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowPartitionIdCommand.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowPartitionIdCommand.java index fb7e5cdf9683309..47977a8e896a371 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowPartitionIdCommand.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowPartitionIdCommand.java @@ -35,8 +35,6 @@ import org.apache.doris.qe.StmtExecutor; import com.google.common.collect.Lists; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import java.util.ArrayList; import java.util.List; @@ -45,7 +43,6 @@ * show partition command */ public class ShowPartitionIdCommand extends ShowCommand { - public static final Logger LOG = LogManager.getLogger(ShowPartitionIdCommand.class); private final long partitionId; /** diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowProcCommand.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowProcCommand.java index da2fb38c4d8d80b..fc865a07457ab62 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowProcCommand.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowProcCommand.java @@ -35,16 +35,12 @@ import org.apache.doris.qe.ShowResultSetMetaData; import org.apache.doris.qe.StmtExecutor; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - import java.util.List; /** * show proc command */ public class ShowProcCommand extends ShowCommand { - public static final Logger LOG = LogManager.getLogger(ShowProcCommand.class); private final String path; /** diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowRolesCommand.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowRolesCommand.java index 7cbb5f934cabba6..4ca4c051cdbf8f3 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowRolesCommand.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowRolesCommand.java @@ -30,16 +30,12 @@ import org.apache.doris.qe.ShowResultSetMetaData; import org.apache.doris.qe.StmtExecutor; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - import java.util.List; /** * show roles command */ public class ShowRolesCommand extends ShowCommand { - public static final Logger LOG = LogManager.getLogger(ShowRolesCommand.class); private static final ShowResultSetMetaData META_DATA; static { diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowTableIdCommand.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowTableIdCommand.java index 3acd6c7992c4dfa..59e1834215a40fb 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowTableIdCommand.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowTableIdCommand.java @@ -33,8 +33,6 @@ import org.apache.doris.qe.StmtExecutor; import com.google.common.collect.Lists; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import java.util.ArrayList; import java.util.List; @@ -43,7 +41,6 @@ * show table id command */ public class ShowTableIdCommand extends ShowCommand { - public static final Logger LOG = LogManager.getLogger(ShowTableIdCommand.class); private final long tableId; /** 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 0d8c24086a6bb30..177b2858afd3b10 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 @@ -55,6 +55,7 @@ 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; +import org.apache.doris.nereids.trees.plans.commands.DropRepositoryCommand; 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.DropUserCommand; @@ -501,12 +502,16 @@ default R visitShowLoadProfileCommand(ShowLoadProfileCommand showLoadProfileComm return visitCommand(showLoadProfileCommand, context); } - default R visitAlterSqlBlockRuleCommand(AlterSqlBlockRuleCommand dropRoleCommand, C context) { - return visitCommand(dropRoleCommand, context); + default R visitAlterSqlBlockRuleCommand(AlterSqlBlockRuleCommand cmd, C context) { + return visitCommand(cmd, context); } - default R visitCreateSqlBlockRuleCommand(CreateSqlBlockRuleCommand dropRoleCommand, C context) { - return visitCommand(dropRoleCommand, context); + default R visitCreateSqlBlockRuleCommand(CreateSqlBlockRuleCommand cmd, C context) { + return visitCommand(cmd, context); + } + + default R visitDropRepositoryCommand(DropRepositoryCommand cmd, C context) { + return visitCommand(cmd, context); } default R visitCreateRoleCommand(CreateRoleCommand createRoleCommand, C context) { diff --git a/regression-test/suites/nereids_p0/ddl/repository/show_repositories_command.groovy b/regression-test/suites/nereids_p0/ddl/repository/show_repositories_command.groovy index 43fadf3b1a86d8d..5d3520109002d3a 100644 --- a/regression-test/suites/nereids_p0/ddl/repository/show_repositories_command.groovy +++ b/regression-test/suites/nereids_p0/ddl/repository/show_repositories_command.groovy @@ -47,7 +47,7 @@ suite("show_repositories_command") { def show_repo = checkNereidsExecuteWithResult("""SHOW REPOSITORIES;""").toString(); assertTrue(show_repo.contains("${repoName}")) - sql """DROP REPOSITORY `${repoName}`;""" + checkNereidsExecute("DROP REPOSITORY `${repoName}`;") def show_repo_after_drop = checkNereidsExecuteWithResult("""SHOW REPOSITORIES;""").toString(); assertFalse(show_repo_after_drop.contains("${repoName}"))