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 f2432586297 [Enhancement] (nereids)implement showStorageVaultCommand 
in nereids (#44805)
f2432586297 is described below

commit f243258629743ca69916c6554cac439b36be066c
Author: Sridhar R Manikarnike <[email protected]>
AuthorDate: Mon May 26 07:26:54 2025 +0530

    [Enhancement] (nereids)implement showStorageVaultCommand in nereids (#44805)
    
    Issue Number: close #42723
---
 .../antlr4/org/apache/doris/nereids/DorisParser.g4 |  4 +-
 .../doris/nereids/parser/LogicalPlanBuilder.java   |  7 ++
 .../apache/doris/nereids/trees/plans/PlanType.java |  1 +
 .../plans/commands/ShowStorageVaultCommand.java    | 96 ++++++++++++++++++++++
 .../trees/plans/visitor/CommandVisitor.java        |  5 ++
 .../show/test_show_storage_vault_command.groovy    | 34 ++++++++
 6 files changed, 145 insertions(+), 2 deletions(-)

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 2ae8b987f14..7c8421e259c 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
@@ -334,6 +334,7 @@ supportedShowStatement
         (FROM |IN) tableName=multipartIdentifier
         ((FROM | IN) database=identifier)?                                     
     #showView
     | SHOW PLUGINS                                                             
     #showPlugins
+    | SHOW STORAGE (VAULT | VAULTS)                                            
     #showStorageVault    
     | SHOW REPOSITORIES                                                        
     #showRepositories
     | SHOW ENCRYPTKEYS ((FROM | IN) database=multipartIdentifier)?
         (LIKE STRING_LITERAL)?                                                 
     #showEncryptKeys
@@ -459,8 +460,7 @@ lockTable
     ;
 
 unsupportedShowStatement
-    : SHOW STORAGE (VAULT | VAULTS)                                            
     #showStorageVault
-    | SHOW CREATE MATERIALIZED VIEW name=multipartIdentifier                   
     #showMaterializedView
+    : SHOW CREATE MATERIALIZED VIEW name=multipartIdentifier                   
     #showMaterializedView
     | SHOW CREATE statementScope? FUNCTION functionIdentifier
         LEFT_PAREN functionArguments? RIGHT_PAREN
         ((FROM | IN) database=multipartIdentifier)?                            
     #showCreateFunction
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 4992f880395..10350209606 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
@@ -381,6 +381,7 @@ 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.ShowStoragePolicyContext;
+import org.apache.doris.nereids.DorisParser.ShowStorageVaultContext;
 import org.apache.doris.nereids.DorisParser.ShowSyncJobContext;
 import org.apache.doris.nereids.DorisParser.ShowTableCreationContext;
 import org.apache.doris.nereids.DorisParser.ShowTableIdContext;
@@ -739,6 +740,7 @@ 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.ShowStoragePolicyCommand;
+import org.apache.doris.nereids.trees.plans.commands.ShowStorageVaultCommand;
 import org.apache.doris.nereids.trees.plans.commands.ShowSyncJobCommand;
 import org.apache.doris.nereids.trees.plans.commands.ShowTableCommand;
 import org.apache.doris.nereids.trees.plans.commands.ShowTableCreationCommand;
@@ -4714,6 +4716,11 @@ public class LogicalPlanBuilder extends 
DorisParserBaseVisitor<Object> {
         return new SetTransactionCommand();
     }
 
+    @Override
+    public LogicalPlan visitShowStorageVault(ShowStorageVaultContext ctx) {
+        return new ShowStorageVaultCommand();
+    }
+
     @Override
     public SetUserPropertiesCommand 
visitSetUserProperties(SetUserPropertiesContext ctx) {
         String user = ctx.user != null ? stripQuotes(ctx.user.getText()) : 
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 689301bafdc..337fe0d3bdc 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
@@ -289,6 +289,7 @@ public enum PlanType {
     SHOW_STATUS_COMMAND,
     SHOW_STORAGE_ENGINES_COMMAND,
     SHOW_STORAGE_POLICY_COMMAND,
+    SHOW_STORAGE_VAULT_COMMAND,
     SHOW_SYNC_JOB_COMMAND,
     SHOW_TABLE_ID_COMMAND,
     SHOW_TABLETS,
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowStorageVaultCommand.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowStorageVaultCommand.java
new file mode 100644
index 00000000000..f5e08e24f4c
--- /dev/null
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowStorageVaultCommand.java
@@ -0,0 +1,96 @@
+// 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.UserIdentity;
+import org.apache.doris.catalog.Env;
+import org.apache.doris.catalog.StorageVault;
+import org.apache.doris.cloud.catalog.CloudEnv;
+import org.apache.doris.cloud.proto.Cloud;
+import org.apache.doris.cloud.rpc.MetaServiceProxy;
+import org.apache.doris.common.AnalysisException;
+import org.apache.doris.common.Config;
+import org.apache.doris.common.FeConstants;
+import org.apache.doris.mysql.privilege.AccessControllerManager;
+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 org.apache.doris.rpc.RpcException;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * Represents the command for SHOW STORAGE VAULT or SHOW STORAGE VAULTS.
+ */
+public class ShowStorageVaultCommand extends ShowCommand {
+
+    public ShowStorageVaultCommand() {
+        super(PlanType.SHOW_STORAGE_VAULT_COMMAND);
+    }
+
+    private void validate() throws AnalysisException {
+        if (Config.isNotCloudMode()) {
+            throw new AnalysisException("Storage Vault is only supported for 
cloud mode");
+        }
+        if (!FeConstants.runningUnitTest) {
+            // In legacy cloud mode, some s3 back-ended storage does need to 
use storage vault.
+            if (!((CloudEnv) Env.getCurrentEnv()).getEnableStorageVault()) {
+                throw new AnalysisException("Your cloud instance doesn't 
support storage vault");
+            }
+        }
+    }
+
+    @Override
+    public ShowResultSet doRun(ConnectContext ctx, StmtExecutor executor) 
throws Exception {
+        validate();
+        // [vault name, vault id, vault properties, isDefault]
+        List<List<String>> rows;
+        try {
+            Cloud.GetObjStoreInfoResponse resp = MetaServiceProxy.getInstance()
+                    
.getObjStoreInfo(Cloud.GetObjStoreInfoRequest.newBuilder().build());
+            AccessControllerManager accessManager = 
Env.getCurrentEnv().getAccessManager();
+            UserIdentity user = ctx.getCurrentUserIdentity();
+            rows = resp.getStorageVaultList().stream()
+                    .filter(storageVault -> 
accessManager.checkStorageVaultPriv(user, storageVault.getName(),
+                            PrivPredicate.USAGE))
+                    .map(StorageVault::convertToShowStorageVaultProperties)
+                    .collect(Collectors.toList());
+            if (resp.hasDefaultStorageVaultId()) {
+                StorageVault.setDefaultVaultToShowVaultResult(rows, 
resp.getDefaultStorageVaultId());
+            }
+        } catch (RpcException e) {
+            throw new AnalysisException(e.getMessage());
+        }
+        return new ShowResultSet(StorageVault.STORAGE_VAULT_META_DATA, rows);
+    }
+
+    @Override
+    public <R, C> R accept(PlanVisitor<R, C> visitor, C context) {
+        return visitor.visitShowStorageVaultCommand(this, context);
+    }
+
+    @Override
+    public ShowResultSetMetaData getMetaData() {
+        return StorageVault.STORAGE_VAULT_META_DATA;
+    }
+}
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 daca3653242..b07b3fb79a3 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
@@ -200,6 +200,7 @@ 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.ShowStoragePolicyCommand;
+import org.apache.doris.nereids.trees.plans.commands.ShowStorageVaultCommand;
 import org.apache.doris.nereids.trees.plans.commands.ShowSyncJobCommand;
 import org.apache.doris.nereids.trees.plans.commands.ShowTableCommand;
 import org.apache.doris.nereids.trees.plans.commands.ShowTableCreationCommand;
@@ -408,6 +409,10 @@ public interface CommandVisitor<R, C> {
         return visitCommand(resumeMTMVCommand, context);
     }
 
+    default R visitShowStorageVaultCommand(ShowStorageVaultCommand 
showStorageVaultCommand, C context) {
+        return visitCommand(showStorageVaultCommand, context);
+    }
+
     default R visitShowCreateMTMVCommand(ShowCreateMTMVCommand 
showCreateMTMVCommand, C context) {
         return visitCommand(showCreateMTMVCommand, context);
     }
diff --git 
a/regression-test/suites/nereids_p0/show/test_show_storage_vault_command.groovy 
b/regression-test/suites/nereids_p0/show/test_show_storage_vault_command.groovy
new file mode 100644
index 00000000000..535cb680ca1
--- /dev/null
+++ 
b/regression-test/suites/nereids_p0/show/test_show_storage_vault_command.groovy
@@ -0,0 +1,34 @@
+// 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_storage_vault_command", "query,storage_vault,cloud") {
+    try {
+        if (!isCloudMode() || !enableStoragevault())
+            return;
+        // Execute the SHOW STORAGE VAULT command and verify the output
+        checkNereidsExecute("SHOW STORAGE VAULT")
+        String tmp = sql """SHOW STORAGE VAULT"""
+        log.info("Result of Show Vault is ", tmp)
+
+        // Execute the SHOW STORAGE VAULTS command and verify the output
+        checkNereidsExecute("SHOW STORAGE VAULTS")
+    } catch (Exception e) {
+        // Log any exceptions that occur during testing
+        log.error("Failed to execute SHOW STORAGE VAULT command", e)
+        throw e
+    }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to