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 223e7c7d596 [Enhancement] (nereids)implement showStagesCommand in 
nereids (#45373)
223e7c7d596 is described below

commit 223e7c7d5964b1a8be0bc96f7abfed999cd3c60d
Author: Sridhar R Manikarnike <sridhar.n...@gmail.com>
AuthorDate: Thu Jan 2 07:03:49 2025 +0530

    [Enhancement] (nereids)implement showStagesCommand in nereids (#45373)
    
    Issue Number: close #42722
---
 .../antlr4/org/apache/doris/nereids/DorisParser.g4 |   2 +-
 .../doris/nereids/parser/LogicalPlanBuilder.java   |   7 +
 .../apache/doris/nereids/trees/plans/PlanType.java |   1 +
 .../trees/plans/commands/ShowStagesCommand.java    | 141 +++++++++++++++++++++
 .../trees/plans/visitor/CommandVisitor.java        |   5 +
 .../nereids_p0/test_show_stages_command.groovy     |  30 +++++
 6 files changed, 185 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 907c25cfe2d..a39f1418dfb 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
@@ -283,6 +283,7 @@ supportedShowStatement
     | SHOW (WARNINGS | ERRORS) limitClause?                                    
     #showWarningErrors
     | SHOW COUNT LEFT_PAREN ASTERISK RIGHT_PAREN (WARNINGS | ERRORS)           
     #showWarningErrorCount
     | SHOW BACKENDS                                                            
     #showBackends
+    | SHOW STAGES                                                              
     #showStages
     | SHOW REPLICA DISTRIBUTION FROM baseTableRef                              
     #showReplicaDistribution
     | SHOW FULL? TRIGGERS ((FROM | IN) database=multipartIdentifier)? 
wildWhere?    #showTriggers    
     | SHOW TABLET DIAGNOSIS tabletId=INTEGER_VALUE                             
     #showDiagnoseTablet
@@ -339,7 +340,6 @@ lockTable
 unsupportedShowStatement
     : SHOW ROW POLICY (FOR (userIdentify | (ROLE role=identifier)))?           
     #showRowPolicy
     | SHOW STORAGE POLICY (USING (FOR policy=identifierOrText)?)?              
     #showStoragePolicy
-    | SHOW STAGES                                                              
     #showStages
     | SHOW STORAGE (VAULT | VAULTS)                                            
     #showStorageVault
     | SHOW OPEN TABLES ((FROM | IN) database=multipartIdentifier)? wildWhere?  
     #showOpenTables
     | SHOW TABLE STATUS ((FROM | IN) database=multipartIdentifier)? wildWhere? 
     #showTableStatus
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 82c8be68e48..65f30a2d4a4 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
@@ -308,6 +308,7 @@ import 
org.apache.doris.nereids.DorisParser.ShowRepositoriesContext;
 import org.apache.doris.nereids.DorisParser.ShowRolesContext;
 import org.apache.doris.nereids.DorisParser.ShowSmallFilesContext;
 import org.apache.doris.nereids.DorisParser.ShowSqlBlockRuleContext;
+import org.apache.doris.nereids.DorisParser.ShowStagesContext;
 import org.apache.doris.nereids.DorisParser.ShowStatusContext;
 import org.apache.doris.nereids.DorisParser.ShowStorageEnginesContext;
 import org.apache.doris.nereids.DorisParser.ShowSyncJobContext;
@@ -592,6 +593,7 @@ 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.ShowSmallFilesCommand;
 import org.apache.doris.nereids.trees.plans.commands.ShowSqlBlockRuleCommand;
+import org.apache.doris.nereids.trees.plans.commands.ShowStagesCommand;
 import org.apache.doris.nereids.trees.plans.commands.ShowStatusCommand;
 import org.apache.doris.nereids.trees.plans.commands.ShowStorageEnginesCommand;
 import org.apache.doris.nereids.trees.plans.commands.ShowSyncJobCommand;
@@ -5072,6 +5074,11 @@ public class LogicalPlanBuilder extends 
DorisParserBaseVisitor<Object> {
         return new CreateCatalogCommand(catalogName, ifNotExists, 
resourceName, comment, properties);
     }
 
+    @Override
+    public LogicalPlan visitShowStages(ShowStagesContext ctx) {
+        return new ShowStagesCommand();
+    }
+
     @Override
     public LogicalPlan visitRecoverDatabase(RecoverDatabaseContext ctx) {
         String dbName = ctx.name.getText();
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 c90734ce8a7..83bad56b93f 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
@@ -243,6 +243,7 @@ public enum PlanType {
     SHOW_REPOSITORIES_COMMAND,
     SHOW_ROLE_COMMAND,
     SHOW_SMALL_FILES_COMMAND,
+    SHOW_STAGES_COMMAND,
     SHOW_STATUS_COMMAND,
     SHOW_STORAGE_ENGINES_COMMAND,
     SHOW_SYNC_JOB_COMMAND,
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowStagesCommand.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowStagesCommand.java
new file mode 100644
index 00000000000..4b820df3b5a
--- /dev/null
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowStagesCommand.java
@@ -0,0 +1,141 @@
+// 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.RedirectStatus;
+import org.apache.doris.catalog.Column;
+import org.apache.doris.catalog.Env;
+import org.apache.doris.catalog.ScalarType;
+import org.apache.doris.cloud.datasource.CloudInternalCatalog;
+import org.apache.doris.cloud.proto.Cloud;
+import org.apache.doris.common.AnalysisException;
+import org.apache.doris.common.DdlException;
+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.gson.GsonBuilder;
+import org.apache.commons.lang3.StringUtils;
+
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Command for SHOW STAGES.
+ */
+public class ShowStagesCommand extends ShowCommand {
+
+    private static final String NAME_COL = "StageName";
+    private static final String ID_COL = "StageId";
+    private static final String ENDPOINT_COL = "Endpoint";
+    private static final String REGION_COL = "Region";
+    private static final String BUCKET_COL = "Bucket";
+    private static final String PREFIX_COL = "Prefix";
+    private static final String AK_COL = "AK";
+    private static final String SK_COL = "SK";
+    private static final String PROVIDER_COL = "Provider";
+    private static final String DEFAULT_PROP_COL = "DefaultProperties";
+    private static final String COMMENT = "Comment";
+    private static final String CREATE_TIME = "CreateTime";
+    private static final String ACCESS_TYPE = "AccessType";
+    private static final String ROLE_NAME = "RoleName";
+    private static final String ARN = "Arn";
+
+    private static final ShowResultSetMetaData META_DATA =
+            ShowResultSetMetaData.builder()
+                    .addColumn(new Column(NAME_COL, 
ScalarType.createVarchar(64)))
+                    .addColumn(new Column(ID_COL, 
ScalarType.createVarchar(64)))
+                    .addColumn(new Column(ENDPOINT_COL, 
ScalarType.createVarchar(128)))
+                    .addColumn(new Column(REGION_COL, 
ScalarType.createVarchar(64)))
+                    .addColumn(new Column(BUCKET_COL, 
ScalarType.createVarchar(64)))
+                    .addColumn(new Column(PREFIX_COL, 
ScalarType.createVarchar(128)))
+                    .addColumn(new Column(AK_COL, 
ScalarType.createVarchar(128)))
+                    .addColumn(new Column(SK_COL, 
ScalarType.createVarchar(128)))
+                    .addColumn(new Column(PROVIDER_COL, 
ScalarType.createVarchar(10)))
+                    .addColumn(new Column(DEFAULT_PROP_COL, 
ScalarType.createVarchar(512)))
+                    .addColumn(new Column(COMMENT, 
ScalarType.createVarchar(512)))
+                    .addColumn(new Column(CREATE_TIME, 
ScalarType.createVarchar(64)))
+                    .addColumn(new Column(ACCESS_TYPE, 
ScalarType.createVarchar(64)))
+                    .addColumn(new Column(ROLE_NAME, 
ScalarType.createVarchar(64)))
+                    .addColumn(new Column(ARN, ScalarType.createVarchar(64)))
+                    .build();
+
+    public ShowStagesCommand() {
+        super(PlanType.SHOW_STAGES_COMMAND);
+    }
+
+    @Override
+    public ShowResultSet doRun(ConnectContext ctx, StmtExecutor executor) 
throws Exception {
+        try {
+            List<Cloud.StagePB> stages = ((CloudInternalCatalog) 
Env.getCurrentInternalCatalog())
+                                            
.getStage(Cloud.StagePB.StageType.EXTERNAL, null, null, null);
+            if (stages == null) {
+                throw new AnalysisException("get stage err");
+            }
+            List<List<String>> results = new ArrayList<>();
+            for (Cloud.StagePB stage : stages) {
+                // todo(copy into): check priv
+                // if (!Env.getCurrentEnv().getAuth()
+                //         
.checkCloudPriv(ConnectContext.get().getCurrentUserIdentity(), stage.getName(),
+                //                 PrivPredicate.USAGE, 
ResourceTypeEnum.STAGE)) {
+                //     continue;
+                // }
+                List<String> result = new ArrayList<>();
+                result.add(stage.getName());
+                result.add(stage.getStageId());
+                result.add(stage.getObjInfo().getEndpoint());
+                result.add(stage.getObjInfo().getRegion());
+                result.add(stage.getObjInfo().getBucket());
+                result.add(stage.getObjInfo().getPrefix());
+                result.add(StringUtils.isEmpty(stage.getObjInfo().getAk()) ? 
"" : "**********");
+                result.add(StringUtils.isEmpty(stage.getObjInfo().getSk()) ? 
"" : "**********");
+                result.add(stage.getObjInfo().getProvider().name());
+                Map<String, String> propertiesMap = new HashMap<>();
+                propertiesMap.putAll(stage.getPropertiesMap());
+                result.add(new 
GsonBuilder().disableHtmlEscaping().create().toJson(propertiesMap));
+                result.add(stage.getComment());
+                result.add(new SimpleDateFormat("yyyy-MM-dd 
HH:mm:ss").format(new Date(stage.getCreateTime())));
+                result.add(stage.hasAccessType() ? stage.getAccessType().name()
+                        : (StringUtils.isEmpty(stage.getObjInfo().getSk()) ? 
"" : "AKSK"));
+                result.add(stage.getRoleName());
+                result.add(stage.getArn());
+                results.add(result);
+            }
+            return new ShowResultSet(META_DATA, results);
+        } catch (DdlException e) {
+            throw new AnalysisException(e.getMessage());
+        }
+    }
+
+    @Override
+    public <R, C> R accept(PlanVisitor<R, C> visitor, C context) {
+        return visitor.visitShowStagesCommand(this, context);
+    }
+
+    @Override
+    public RedirectStatus toRedirectStatus() {
+        return RedirectStatus.FORWARD_NO_SYNC;
+    }
+}
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 e7f9660ebef..8730aa3a2e6 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
@@ -129,6 +129,7 @@ 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.ShowSmallFilesCommand;
 import org.apache.doris.nereids.trees.plans.commands.ShowSqlBlockRuleCommand;
+import org.apache.doris.nereids.trees.plans.commands.ShowStagesCommand;
 import org.apache.doris.nereids.trees.plans.commands.ShowStatusCommand;
 import org.apache.doris.nereids.trees.plans.commands.ShowStorageEnginesCommand;
 import org.apache.doris.nereids.trees.plans.commands.ShowSyncJobCommand;
@@ -375,6 +376,10 @@ public interface CommandVisitor<R, C> {
         return visitCommand(dropCatalogRecycleBinCommand, context);
     }
 
+    default R visitShowStagesCommand(ShowStagesCommand showStagesCommand, C 
context) {
+        return visitCommand(showStagesCommand, context);
+    }
+
     default R visitUnsupportedCommand(UnsupportedCommand unsupportedCommand, C 
context) {
         return visitCommand(unsupportedCommand, context);
     }
diff --git a/regression-test/suites/nereids_p0/test_show_stages_command.groovy 
b/regression-test/suites/nereids_p0/test_show_stages_command.groovy
new file mode 100644
index 00000000000..d71368d3a37
--- /dev/null
+++ b/regression-test/suites/nereids_p0/test_show_stages_command.groovy
@@ -0,0 +1,30 @@
+// 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_show_stages_command", "nereids_p0") {
+    try {
+       if (!cloudMode)
+           return;
+        
+       // Check if stages can be listed
+        checkNereidsExecute("SHOW STAGES")
+    } catch (Exception e) {
+        logger.error("Test failed: ", e)
+        throw e
+    }
+}
+


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to