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 4b3c2b393fe [Enhancement] (nereids)implement alterResourceCommand in 
nereids (#49173)
4b3c2b393fe is described below

commit 4b3c2b393fe52fea06f7907a8b72522e1321c6c5
Author: Sridhar R Manikarnike <[email protected]>
AuthorDate: Wed May 28 07:10:32 2025 +0530

    [Enhancement] (nereids)implement alterResourceCommand in nereids (#49173)
    
    
    Issue Number: close #42791
---
 .../antlr4/org/apache/doris/nereids/DorisParser.g4 |  4 +-
 .../java/org/apache/doris/catalog/ResourceMgr.java | 12 ++-
 .../doris/nereids/parser/LogicalPlanBuilder.java   | 11 +++
 .../apache/doris/nereids/trees/plans/PlanType.java |  1 +
 .../trees/plans/commands/AlterResourceCommand.java | 89 ++++++++++++++++++++++
 .../trees/plans/visitor/CommandVisitor.java        |  5 ++
 .../nereids_p0/test_alter_resource_nereids.groovy  | 50 ++++++++++++
 7 files changed, 166 insertions(+), 6 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 c731fca9cc0..79e42b48b51 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
@@ -280,6 +280,7 @@ supportedAlterStatement
     | ALTER DATABASE name=identifier SET PROPERTIES
             LEFT_PAREN propertyItemList RIGHT_PAREN                            
             #alterDatabaseProperties
     | ALTER SYSTEM RENAME COMPUTE GROUP name=identifier newName=identifier     
             #alterSystemRenameComputeGroup
+    | ALTER RESOURCE name=identifierOrText properties=propertyClause?          
             #alterResource
     | ALTER REPOSITORY name=identifier properties=propertyClause?              
             #alterRepository
     | ALTER USER (IF EXISTS)? grantUserIdentify
         passwordOption (COMMENT STRING_LITERAL)?                               
             #alterUser
@@ -666,8 +667,7 @@ privilegeList
     ;
 
 unsupportedAlterStatement
-    : ALTER RESOURCE name=identifierOrText properties=propertyClause?          
     #alterResource
-    | ALTER COLOCATE GROUP name=multipartIdentifier
+    : ALTER COLOCATE GROUP name=multipartIdentifier
         SET LEFT_PAREN propertyItemList RIGHT_PAREN                            
     #alterColocateGroup
     | ALTER ROUTINE LOAD FOR name=multipartIdentifier 
properties=propertyClause?
             (FROM type=identifier LEFT_PAREN propertyItemList RIGHT_PAREN)?    
     #alterRoutineLoad
diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/ResourceMgr.java 
b/fe/fe-core/src/main/java/org/apache/doris/catalog/ResourceMgr.java
index 8e4c1265b53..0e169a0bc86 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/catalog/ResourceMgr.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/ResourceMgr.java
@@ -179,10 +179,7 @@ public class ResourceMgr implements Writable {
         nameToResource.remove(operationLog.getName());
     }
 
-    public void alterResource(AlterResourceStmt stmt) throws DdlException {
-        String resourceName = stmt.getResourceName();
-        Map<String, String> properties = stmt.getProperties();
-
+    public void alterResource(String resourceName, Map<String, String> 
properties) throws DdlException {
         if (!nameToResource.containsKey(resourceName)) {
             throw new DdlException("Resource(" + resourceName + ") dose not 
exist.");
         }
@@ -195,6 +192,13 @@ public class ResourceMgr implements Writable {
         LOG.info("Alter resource success. Resource: {}", resource);
     }
 
+    public void alterResource(AlterResourceStmt stmt) throws DdlException {
+        String resourceName = stmt.getResourceName();
+        Map<String, String> properties = stmt.getProperties();
+
+        alterResource(resourceName, properties);
+    }
+
     public void replayAlterResource(Resource resource) {
         nameToResource.put(resource.getName(), resource);
     }
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 591708e53e1..029207c458c 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
@@ -98,6 +98,7 @@ import 
org.apache.doris.nereids.DorisParser.AlterDatabaseSetQuotaContext;
 import org.apache.doris.nereids.DorisParser.AlterMTMVContext;
 import org.apache.doris.nereids.DorisParser.AlterMultiPartitionClauseContext;
 import org.apache.doris.nereids.DorisParser.AlterRepositoryContext;
+import org.apache.doris.nereids.DorisParser.AlterResourceContext;
 import org.apache.doris.nereids.DorisParser.AlterRoleContext;
 import org.apache.doris.nereids.DorisParser.AlterSqlBlockRuleContext;
 import org.apache.doris.nereids.DorisParser.AlterStoragePolicyContext;
@@ -568,6 +569,7 @@ import 
org.apache.doris.nereids.trees.plans.commands.AlterCatalogRenameCommand;
 import org.apache.doris.nereids.trees.plans.commands.AlterColumnStatsCommand;
 import 
org.apache.doris.nereids.trees.plans.commands.AlterDatabasePropertiesCommand;
 import org.apache.doris.nereids.trees.plans.commands.AlterMTMVCommand;
+import org.apache.doris.nereids.trees.plans.commands.AlterResourceCommand;
 import org.apache.doris.nereids.trees.plans.commands.AlterRoleCommand;
 import org.apache.doris.nereids.trees.plans.commands.AlterSqlBlockRuleCommand;
 import org.apache.doris.nereids.trees.plans.commands.AlterStoragePolicyCommand;
@@ -5304,6 +5306,15 @@ public class LogicalPlanBuilder extends 
DorisParserBaseVisitor<Object> {
         return new ShowViewCommand(databaseName, new 
TableNameInfo(tableNameParts));
     }
 
+    @Override
+    public LogicalPlan visitAlterResource(AlterResourceContext ctx) {
+        String resourceName = visitIdentifierOrText(ctx.identifierOrText());
+        Map<String, String> properties = 
visitPropertyClause(ctx.propertyClause()) == null ? Maps.newHashMap()
+                : Maps.newHashMap(visitPropertyClause(ctx.propertyClause()));
+
+        return new AlterResourceCommand(resourceName, properties);
+    }
+
     @Override
     public LogicalPlan visitShowBackends(ShowBackendsContext ctx) {
         return new ShowBackendsCommand();
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 908b5b2cd7e..9c8ffccd501 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
@@ -234,6 +234,7 @@ public enum PlanType {
     ALTER_CATALOG_COMMENT_COMMAND,
     ALTER_SQL_BLOCK_RULE_COMMAND,
     ALTER_REPOSITORY_COMMAND,
+    ALTER_RESOURCE_COMMAND,
     SHOW_ANALYZE_COMMAND,
     SHOW_QUEUED_ANALYZE_JOBS_COMMAND,
     SHOW_BACKENDS_COMMAND,
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/AlterResourceCommand.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/AlterResourceCommand.java
new file mode 100644
index 00000000000..576e8ee2027
--- /dev/null
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/AlterResourceCommand.java
@@ -0,0 +1,89 @@
+// 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.catalog.Resource;
+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.StmtExecutor;
+
+import java.util.Map;
+
+/**
+ * Command for ALTER RESOURCE in Nereids.
+ */
+public class AlterResourceCommand extends AlterCommand implements 
NeedAuditEncryption {
+    private static final String TYPE = "type";
+    private final String resourceName;
+    private final Map<String, String> properties;
+
+    public AlterResourceCommand(String resourceName, Map<String, String> 
properties) {
+        super(PlanType.ALTER_RESOURCE_COMMAND);
+        this.resourceName = resourceName;
+        this.properties = properties;
+    }
+
+    private void validate(ConnectContext ctx) throws AnalysisException {
+        // check auth
+        if 
(!Env.getCurrentEnv().getAccessManager().checkGlobalPriv(ConnectContext.get(), 
PrivPredicate.ADMIN)) {
+            
ErrorReport.reportAnalysisException(ErrorCode.ERR_SPECIFIC_ACCESS_DENIED_ERROR, 
"ADMIN");
+        }
+
+        if (properties == null || properties.isEmpty()) {
+            throw new AnalysisException("Resource properties can't be null");
+        }
+
+        // check type in properties
+        if (properties.containsKey(TYPE)) {
+            throw new AnalysisException("Can not change resource type.");
+        }
+
+        // check resource existence
+        Resource resource = 
Env.getCurrentEnv().getResourceMgr().getResource(resourceName);
+        if (resource == null) {
+            throw new AnalysisException("Unknown resource: " + resourceName);
+        }
+        // check properties
+        resource.checkProperties(properties);
+    }
+
+    @Override
+    public void doRun(ConnectContext ctx, StmtExecutor executor) throws 
Exception {
+        validate(ctx);
+
+        // Modify the resource with new properties
+        Env.getCurrentEnv().getResourceMgr().alterResource(resourceName, 
properties);
+    }
+
+    @Override
+    public <R, C> R accept(PlanVisitor<R, C> visitor, C context) {
+        return visitor.visitAlterResourceCommand(this, context);
+    }
+
+    @Override
+    public boolean needAuditEncryption() {
+        return true;
+    }
+}
+
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 0a44c15de4a..eb0895faed9 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
@@ -36,6 +36,7 @@ import 
org.apache.doris.nereids.trees.plans.commands.AlterColumnStatsCommand;
 import 
org.apache.doris.nereids.trees.plans.commands.AlterDatabasePropertiesCommand;
 import org.apache.doris.nereids.trees.plans.commands.AlterJobStatusCommand;
 import org.apache.doris.nereids.trees.plans.commands.AlterMTMVCommand;
+import org.apache.doris.nereids.trees.plans.commands.AlterResourceCommand;
 import org.apache.doris.nereids.trees.plans.commands.AlterRoleCommand;
 import org.apache.doris.nereids.trees.plans.commands.AlterSqlBlockRuleCommand;
 import org.apache.doris.nereids.trees.plans.commands.AlterStoragePolicyCommand;
@@ -378,6 +379,10 @@ public interface CommandVisitor<R, C> {
         return visitCommand(dropDictionaryCommand, context);
     }
 
+    default R visitAlterResourceCommand(AlterResourceCommand 
alterResourceCommand, C context) {
+        return visitCommand(alterResourceCommand, context);
+    }
+
     default R visitDropJobCommand(DropJobCommand dropJobCommand, C context) {
         return visitCommand(dropJobCommand, context);
     }
diff --git 
a/regression-test/suites/nereids_p0/test_alter_resource_nereids.groovy 
b/regression-test/suites/nereids_p0/test_alter_resource_nereids.groovy
new file mode 100644
index 00000000000..4ba50971e37
--- /dev/null
+++ b/regression-test/suites/nereids_p0/test_alter_resource_nereids.groovy
@@ -0,0 +1,50 @@
+// 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_alter_resource_nereids", "query,storage_policy") {
+    String resourceName = "test_alter_resource";
+    try {
+        // Drop existing storage policy and resource if they exist before 
creating new ones
+        try_sql("DROP RESOURCE IF EXISTS ${resourceName}")
+        // Create a new resource to be used in the storage policy
+        sql """
+            CREATE RESOURCE IF NOT EXISTS "${resourceName}"
+            PROPERTIES(
+                "type"="s3",
+                "AWS_ENDPOINT" = "${getS3Endpoint()}",
+                "AWS_REGION" = "${getS3Region()}",
+                "AWS_ROOT_PATH" = "regression/cooldown",
+                "AWS_ACCESS_KEY" = "${getS3AK()}",
+                "AWS_SECRET_KEY" = "${getS3SK()}",
+                "AWS_MAX_CONNECTIONS" = "50",
+                "AWS_REQUEST_TIMEOUT_MS" = "3000",
+                "AWS_CONNECTION_TIMEOUT_MS" = "1000",
+                "AWS_BUCKET" = "${getS3BucketName()}",
+                "s3_validity_check" = "false"
+            );
+        """
+
+        checkNereidsExecute("""
+               ALTER RESOURCE ${resourceName} PROPERTIES 
("s3.connection.maximum" = "100")
+       """)
+    } catch (Exception e) {
+        log.error("Failed to execute ALTER RESOURCE command", e)
+        throw e
+    } finally {
+        try_sql("DROP RESOURCE IF EXISTS ${resourceName}")
+    }
+}


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

Reply via email to