Skip to content

Commit

Permalink
[Enhancement] (nereids)implement DropRepositoryCommand in nereids
Browse files Browse the repository at this point in the history
  • Loading branch information
Vallishp committed Dec 4, 2024
1 parent d22bd83 commit 34801a8
Show file tree
Hide file tree
Showing 14 changed files with 94 additions and 28 deletions.
2 changes: 1 addition & 1 deletion be/src/clucene
Submodule clucene updated 642 files
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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, C> R accept(PlanVisitor<R, C> 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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,13 @@
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;

/**
* 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}"))
Expand Down

0 comments on commit 34801a8

Please sign in to comment.