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 0fb89969e0c [Feat](Nereids) support show repositories command (#43907) 0fb89969e0c is described below commit 0fb89969e0ccbbc65bf18fbae732c31be0e7912c Author: GentleCold <gentlec...@qq.com> AuthorDate: Fri Nov 15 10:22:32 2024 +0800 [Feat](Nereids) support show repositories command (#43907) Issue Number: close #42765 --- .../antlr4/org/apache/doris/nereids/DorisParser.g4 | 2 +- .../doris/nereids/parser/LogicalPlanBuilder.java | 7 ++ .../apache/doris/nereids/trees/plans/PlanType.java | 1 + .../plans/commands/ShowRepositoriesCommand.java | 78 ++++++++++++++++++++++ .../trees/plans/visitor/CommandVisitor.java | 5 ++ .../repository/show_repositories_command.groovy | 54 +++++++++++++++ 6 files changed, 146 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 18e0860b987..68ca15cca7b 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 @@ -198,6 +198,7 @@ supportedShowStatement | SHOW VIEW (FROM |IN) tableName=multipartIdentifier ((FROM | IN) database=identifier)? #showView + | SHOW REPOSITORIES #showRepositories | SHOW ROLES #showRoles | SHOW PROC path=STRING_LITERAL #showProc | SHOW CREATE MATERIALIZED VIEW mvName=identifier @@ -301,7 +302,6 @@ unsupportedShowStatement | SHOW BACKENDS #showBackends | SHOW TRASH (ON backend=STRING_LITERAL)? #showTrash | SHOW FRONTENDS name=identifier? #showFrontends - | SHOW REPOSITORIES #showRepositories | SHOW SNAPSHOT ON repo=identifier wildWhere? #showSnapshot | SHOW ALL? GRANTS #showGrants | SHOW GRANTS FOR userIdentify #showGrantsForUser 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 7a318f12e77..5060dc3f915 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 @@ -201,6 +201,7 @@ import org.apache.doris.nereids.DorisParser.ShowCreateMaterializedViewContext; import org.apache.doris.nereids.DorisParser.ShowCreateProcedureContext; import org.apache.doris.nereids.DorisParser.ShowProcContext; import org.apache.doris.nereids.DorisParser.ShowProcedureStatusContext; +import org.apache.doris.nereids.DorisParser.ShowRepositoriesContext; import org.apache.doris.nereids.DorisParser.ShowRolesContext; import org.apache.doris.nereids.DorisParser.ShowVariablesContext; import org.apache.doris.nereids.DorisParser.ShowViewContext; @@ -438,6 +439,7 @@ import org.apache.doris.nereids.trees.plans.commands.ShowCreateMaterializedViewC import org.apache.doris.nereids.trees.plans.commands.ShowCreateProcedureCommand; import org.apache.doris.nereids.trees.plans.commands.ShowProcCommand; import org.apache.doris.nereids.trees.plans.commands.ShowProcedureStatusCommand; +import org.apache.doris.nereids.trees.plans.commands.ShowRepositoriesCommand; import org.apache.doris.nereids.trees.plans.commands.ShowRolesCommand; import org.apache.doris.nereids.trees.plans.commands.ShowVariablesCommand; import org.apache.doris.nereids.trees.plans.commands.ShowViewCommand; @@ -4070,6 +4072,11 @@ public class LogicalPlanBuilder extends DorisParserBaseVisitor<Object> { return new ShowViewCommand(databaseName, new TableNameInfo(tableNameParts)); } + @Override + public LogicalPlan visitShowRepositories(ShowRepositoriesContext ctx) { + return new ShowRepositoriesCommand(); + } + @Override public LogicalPlan visitShowRoles(ShowRolesContext ctx) { return new ShowRolesCommand(); 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 53fda041498..cb1eff3eb62 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 @@ -178,6 +178,7 @@ public enum PlanType { SHOW_CONFIG_COMMAND, SHOW_CREATE_MATERIALIZED_VIEW_COMMAND, SHOW_PROC_COMMAND, + SHOW_REPOSITORIES_COMMAND, SHOW_ROLE_COMMAND, SHOW_VARIABLES_COMMAND, SHOW_AUTHORS_COMMAND, diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowRepositoriesCommand.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowRepositoriesCommand.java new file mode 100644 index 00000000000..86ee7f1348d --- /dev/null +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowRepositoriesCommand.java @@ -0,0 +1,78 @@ +// 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.Column; +import org.apache.doris.catalog.Env; +import org.apache.doris.catalog.ScalarType; +import org.apache.doris.common.AnalysisException; +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.ShowResultSet; +import org.apache.doris.qe.ShowResultSetMetaData; +import org.apache.doris.qe.StmtExecutor; + +import com.google.common.collect.ImmutableList; + +import java.util.List; + +/** + * ShowRepositoriesCommand + */ +public class ShowRepositoriesCommand extends ShowCommand { + public static final ImmutableList<String> TITLE_NAMES = new ImmutableList.Builder<String>() + .add("RepoId").add("RepoName").add("CreateTime").add("IsReadOnly").add("Location") + .add("Broker").add("Type").add("ErrMsg") + .build(); + + public ShowRepositoriesCommand() { + super(PlanType.SHOW_REPOSITORIES_COMMAND); + } + + private void validate() throws AnalysisException { + // check auth + if (!Env.getCurrentEnv().getAccessManager().checkGlobalPriv(ConnectContext.get(), PrivPredicate.ADMIN)) { + ErrorReport.reportAnalysisException(ErrorCode.ERR_SPECIFIC_ACCESS_DENIED_ERROR, + PrivPredicate.ADMIN.getPrivs().toString()); + } + } + + public ShowResultSetMetaData getMetaData() { + ShowResultSetMetaData.Builder builder = ShowResultSetMetaData.builder(); + for (String title : TITLE_NAMES) { + builder.addColumn(new Column(title, ScalarType.createVarchar(30))); + } + return builder.build(); + } + + @Override + public ShowResultSet doRun(ConnectContext ctx, StmtExecutor executor) throws Exception { + validate(); + List<List<String>> repoInfos = Env.getCurrentEnv().getBackupHandler().getRepoMgr().getReposInfo(); + return new ShowResultSet(getMetaData(), repoInfos); + } + + @Override + public <R, C> R accept(PlanVisitor<R, C> visitor, C context) { + return visitor.visitShowRepositoriesCommand(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 bbd341c181d..5b4cff7dade 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 @@ -57,6 +57,7 @@ import org.apache.doris.nereids.trees.plans.commands.ShowCreateMaterializedViewC import org.apache.doris.nereids.trees.plans.commands.ShowCreateProcedureCommand; import org.apache.doris.nereids.trees.plans.commands.ShowProcCommand; import org.apache.doris.nereids.trees.plans.commands.ShowProcedureStatusCommand; +import org.apache.doris.nereids.trees.plans.commands.ShowRepositoriesCommand; import org.apache.doris.nereids.trees.plans.commands.ShowRolesCommand; import org.apache.doris.nereids.trees.plans.commands.ShowVariablesCommand; import org.apache.doris.nereids.trees.plans.commands.ShowViewCommand; @@ -253,6 +254,10 @@ public interface CommandVisitor<R, C> { return visitCommand(showViewCommand, context); } + default R visitShowRepositoriesCommand(ShowRepositoriesCommand showRepositoriesCommand, C context) { + return visitCommand(showRepositoriesCommand, context); + } + default R visitShowRolesCommand(ShowRolesCommand showRolesCommand, C context) { return visitCommand(showRolesCommand, 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 new file mode 100644 index 00000000000..43fadf3b1a8 --- /dev/null +++ b/regression-test/suites/nereids_p0/ddl/repository/show_repositories_command.groovy @@ -0,0 +1,54 @@ +// 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. + +import org.junit.Assert; + +suite("show_repositories_command") { + String ak = getS3AK() + String sk = getS3SK() + String endpoint = getS3Endpoint() + String region = getS3Region() + String bucket = context.config.otherConfigs.get("s3BucketName"); + String repoName = "test_show_repositories" + + //cloud-mode + if (isCloudMode()) { + return + } + + try_sql "DROP REPOSITORY `${repoName}`" + + // create S3 repo + sql """CREATE REPOSITORY `${repoName}` + WITH S3 + ON LOCATION "s3://${bucket}/${repoName}" + PROPERTIES + ( + "s3.endpoint" = "http://${endpoint}", + "s3.region" = "${region}", + "s3.access_key" = "${ak}", + "s3.secret_key" = "${sk}" + )""" + + def show_repo = checkNereidsExecuteWithResult("""SHOW REPOSITORIES;""").toString(); + assertTrue(show_repo.contains("${repoName}")) + + sql """DROP REPOSITORY `${repoName}`;""" + + def show_repo_after_drop = checkNereidsExecuteWithResult("""SHOW REPOSITORIES;""").toString(); + assertFalse(show_repo_after_drop.contains("${repoName}")) +} --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org