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 5a938791d98 [Enhancement] (nereids)implement 
alterCatalogPropertiesCommand in nereids (#45164)
5a938791d98 is described below

commit 5a938791d988f7b85aeeb6a1b0b77a2c7b0b56ae
Author: Sridhar R Manikarnike <sridhar.n...@gmail.com>
AuthorDate: Tue Mar 4 08:08:23 2025 +0530

    [Enhancement] (nereids)implement alterCatalogPropertiesCommand in nereids 
(#45164)
    
    Issue Number: close #42789
---
 .../antlr4/org/apache/doris/nereids/DorisParser.g4 |   4 +-
 .../org/apache/doris/datasource/CatalogMgr.java    |  23 ++++++---
 .../doris/nereids/parser/LogicalPlanBuilder.java   |   9 ++++
 .../apache/doris/nereids/trees/plans/PlanType.java |   1 +
 .../plans/commands/AlterCatalogCommentCommand.java |   1 +
 ...and.java => AlterCatalogPropertiesCommand.java} |  29 +++++------
 .../trees/plans/visitor/CommandVisitor.java        |   5 ++
 .../test_alter_catalog_properties_command.out      | Bin 0 -> 493 bytes
 .../test_alter_catalog_properties_command.groovy   |  55 +++++++++++++++++++++
 9 files changed, 101 insertions(+), 26 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 74b73f0c023..c6e479c4483 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
@@ -229,6 +229,8 @@ supportedAlterStatement
     | ALTER ROLE role=identifier commentSpec                                   
             #alterRole
     | ALTER WORKLOAD GROUP name=identifierOrText
         properties=propertyClause?                                             
             #alterWorkloadGroup
+    | ALTER CATALOG name=identifier SET PROPERTIES
+        LEFT_PAREN propertyItemList RIGHT_PAREN                                
             #alterCatalogProperties        
     | ALTER WORKLOAD POLICY name=identifierOrText
         properties=propertyClause?                                             
             #alterWorkloadPolicy
     | ALTER SQL_BLOCK_RULE name=identifier properties=propertyClause?          
             #alterSqlBlockRule
@@ -619,8 +621,6 @@ privilegeList
 unsupportedAlterStatement
     : ALTER DATABASE name=identifier SET PROPERTIES
         LEFT_PAREN propertyItemList RIGHT_PAREN                                
     #alterDatabaseProperties
-    | ALTER CATALOG name=identifier SET PROPERTIES
-        LEFT_PAREN propertyItemList RIGHT_PAREN                                
     #alterCatalogProperties
     | ALTER RESOURCE name=identifierOrText properties=propertyClause?          
     #alterResource
     | ALTER COLOCATE GROUP name=multipartIdentifier
         SET LEFT_PAREN propertyItemList RIGHT_PAREN                            
     #alterColocateGroup
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/datasource/CatalogMgr.java 
b/fe/fe-core/src/main/java/org/apache/doris/datasource/CatalogMgr.java
index 80c568b0b56..ca8d3147bc9 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/datasource/CatalogMgr.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/datasource/CatalogMgr.java
@@ -377,19 +377,21 @@ public class CatalogMgr implements Writable, 
GsonPostProcessable {
     /**
      * Modify the catalog property and write the meta log.
      */
-    public void alterCatalogProps(AlterCatalogPropertyStmt stmt) throws 
UserException {
+    public void alterCatalogProps(String catalogName, Map<String, String> 
newProperties) throws UserException {
         writeLock();
         try {
-            CatalogIf catalog = nameToCatalog.get(stmt.getCatalogName());
+            CatalogIf catalog = nameToCatalog.get(catalogName);
             if (catalog == null) {
-                throw new DdlException("No catalog found with name: " + 
stmt.getCatalogName());
+                throw new DdlException("No catalog found with name: " + 
catalogName);
             }
             Map<String, String> oldProperties = catalog.getProperties();
-            if (stmt.getNewProperties().containsKey("type") && 
!catalog.getType()
-                    .equalsIgnoreCase(stmt.getNewProperties().get("type"))) {
-                throw new DdlException("Can't modify the type of catalog 
property with name: " + stmt.getCatalogName());
+            if (newProperties.containsKey("type") && !catalog.getType()
+                    .equalsIgnoreCase(newProperties.get("type"))) {
+                throw new DdlException("Can't modify the type of catalog 
property with name: " + catalogName);
             }
-            CatalogLog log = CatalogFactory.createCatalogLog(catalog.getId(), 
stmt);
+            CatalogLog log = new CatalogLog();
+            log.setCatalogId(catalog.getId());
+            log.setNewProps(newProperties);
             replayAlterCatalogProps(log, oldProperties, false);
             
Env.getCurrentEnv().getEditLog().logCatalogLog(OperationType.OP_ALTER_CATALOG_PROPS,
 log);
         } finally {
@@ -397,6 +399,13 @@ public class CatalogMgr implements Writable, 
GsonPostProcessable {
         }
     }
 
+    /**
+     * Modify the catalog property and write the meta log.
+     */
+    public void alterCatalogProps(AlterCatalogPropertyStmt stmt) throws 
UserException {
+        alterCatalogProps(stmt.getCatalogName(), stmt.getNewProperties());
+    }
+
     /**
      * List all catalog or get the special catalog with a name.
      */
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 a8db953f76d..9a95767aeec 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
@@ -76,6 +76,7 @@ import 
org.apache.doris.nereids.DorisParser.AggStateDataTypeContext;
 import org.apache.doris.nereids.DorisParser.AliasQueryContext;
 import org.apache.doris.nereids.DorisParser.AliasedQueryContext;
 import org.apache.doris.nereids.DorisParser.AlterCatalogCommentContext;
+import org.apache.doris.nereids.DorisParser.AlterCatalogPropertiesContext;
 import org.apache.doris.nereids.DorisParser.AlterCatalogRenameContext;
 import org.apache.doris.nereids.DorisParser.AlterDatabaseRenameContext;
 import org.apache.doris.nereids.DorisParser.AlterDatabaseSetQuotaContext;
@@ -516,6 +517,7 @@ import 
org.apache.doris.nereids.trees.plans.commands.AdminRebalanceDiskCommand;
 import 
org.apache.doris.nereids.trees.plans.commands.AdminSetTableStatusCommand;
 import 
org.apache.doris.nereids.trees.plans.commands.AdminShowReplicaStatusCommand;
 import 
org.apache.doris.nereids.trees.plans.commands.AlterCatalogCommentCommand;
+import 
org.apache.doris.nereids.trees.plans.commands.AlterCatalogPropertiesCommand;
 import org.apache.doris.nereids.trees.plans.commands.AlterCatalogRenameCommand;
 import org.apache.doris.nereids.trees.plans.commands.AlterMTMVCommand;
 import org.apache.doris.nereids.trees.plans.commands.AlterRoleCommand;
@@ -5382,6 +5384,13 @@ public class LogicalPlanBuilder extends 
DorisParserBaseVisitor<Object> {
         return new ShowWarningErrorsCommand(isWarning, limit);
     }
 
+    @Override
+    public LogicalPlan 
visitAlterCatalogProperties(AlterCatalogPropertiesContext ctx) {
+        String catalogName = stripQuotes(ctx.name.getText());
+        Map<String, String> properties = 
visitPropertyItemList(ctx.propertyItemList());
+        return new AlterCatalogPropertiesCommand(catalogName, properties);
+    }
+
     @Override
     public RecoverTableCommand visitRecoverTable(RecoverTableContext ctx) {
         List<String> dbTblNameParts = visitMultipartIdentifier(ctx.name);
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 bf7b10a1063..8269058a47b 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
@@ -158,6 +158,7 @@ public enum PlanType {
     DROP_JOB_COMMAND,
     RESUME_JOB_COMMAND,
     ALTER_MTMV_COMMAND,
+    ALTER_CATALOG_PROPERTIES_COMMAND,
     ADD_CONSTRAINT_COMMAND,
     ADMIN_COMPACT_TABLE_COMMAND,
     DROP_CONSTRAINT_COMMAND,
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/AlterCatalogCommentCommand.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/AlterCatalogCommentCommand.java
index eafe1f7c2c1..474f3f6f3c8 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/AlterCatalogCommentCommand.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/AlterCatalogCommentCommand.java
@@ -42,6 +42,7 @@ public class AlterCatalogCommentCommand extends 
AlterCatalogCommand {
 
     @Override
     public void doRun(ConnectContext ctx, StmtExecutor executor) throws 
Exception {
+        validate(ctx);
         // Validate the catalog name
         if (Strings.isNullOrEmpty(comment)) {
             throw new AnalysisException("New comment is not set.");
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/AlterCatalogCommentCommand.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/AlterCatalogPropertiesCommand.java
similarity index 61%
copy from 
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/AlterCatalogCommentCommand.java
copy to 
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/AlterCatalogPropertiesCommand.java
index eafe1f7c2c1..042a552f2d1 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/AlterCatalogCommentCommand.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/AlterCatalogPropertiesCommand.java
@@ -18,41 +18,36 @@
 package org.apache.doris.nereids.trees.plans.commands;
 
 import org.apache.doris.catalog.Env;
-import org.apache.doris.common.AnalysisException;
+import org.apache.doris.common.util.PropertyAnalyzer;
 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 com.google.common.base.Strings;
-
+import java.util.Map;
 import java.util.Objects;
 
 /**
- * Represents the command for ALTER CATALOG MODIFY COMMENT.
+ * Represents the command for ALTER CATALOG ... SET PROPERTIES.
  */
-public class AlterCatalogCommentCommand extends AlterCatalogCommand {
-
-    private final String comment;
+public class AlterCatalogPropertiesCommand extends AlterCatalogCommand {
+    private final Map<String, String> newProperties;
 
-    public AlterCatalogCommentCommand(String catalogName, String comment) {
-        super(PlanType.ALTER_CATALOG_COMMENT_COMMAND, catalogName);
-        this.comment = Objects.requireNonNull(comment, "Comment cannot be 
null");
+    public AlterCatalogPropertiesCommand(String catalogName, Map<String, 
String> properties) {
+        super(PlanType.ALTER_CATALOG_PROPERTIES_COMMAND, catalogName);
+        this.newProperties = Objects.requireNonNull(properties, "Properties 
cannot be null");
     }
 
     @Override
     public void doRun(ConnectContext ctx, StmtExecutor executor) throws 
Exception {
-        // Validate the catalog name
-        if (Strings.isNullOrEmpty(comment)) {
-            throw new AnalysisException("New comment is not set.");
-        }
+        validate(ctx);
+        PropertyAnalyzer.checkCatalogProperties(newProperties, true);
 
-        // Fetch and modify the catalog's comment
-        Env.getCurrentEnv().getCatalogMgr().alterCatalogComment(catalogName, 
comment);
+        Env.getCurrentEnv().getCatalogMgr().alterCatalogProps(catalogName, 
newProperties);
     }
 
     @Override
     public <R, C> R accept(PlanVisitor<R, C> visitor, C context) {
-        return visitor.visitAlterCatalogCommentCommand(this, context);
+        return visitor.visitAlterCatalogPropertiesCommand(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 c990a7c496c..2d4b5e321bc 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
@@ -26,6 +26,7 @@ import 
org.apache.doris.nereids.trees.plans.commands.AdminRebalanceDiskCommand;
 import 
org.apache.doris.nereids.trees.plans.commands.AdminSetTableStatusCommand;
 import 
org.apache.doris.nereids.trees.plans.commands.AdminShowReplicaStatusCommand;
 import 
org.apache.doris.nereids.trees.plans.commands.AlterCatalogCommentCommand;
+import 
org.apache.doris.nereids.trees.plans.commands.AlterCatalogPropertiesCommand;
 import org.apache.doris.nereids.trees.plans.commands.AlterCatalogRenameCommand;
 import org.apache.doris.nereids.trees.plans.commands.AlterJobStatusCommand;
 import org.apache.doris.nereids.trees.plans.commands.AlterMTMVCommand;
@@ -618,6 +619,10 @@ public interface CommandVisitor<R, C> {
         return visitCommand(whiteListCommand, context);
     }
 
+    default R visitAlterCatalogPropertiesCommand(AlterCatalogPropertiesCommand 
alterCatalogPropsCmd, C context) {
+        return visitCommand(alterCatalogPropsCmd, context);
+    }
+
     default R visitRecoverDatabaseCommand(RecoverDatabaseCommand 
recoverDatabaseCommand, C context) {
         return visitCommand(recoverDatabaseCommand, context);
     }
diff --git 
a/regression-test/data/nereids_p0/test_alter_catalog_properties_command.out 
b/regression-test/data/nereids_p0/test_alter_catalog_properties_command.out
new file mode 100644
index 00000000000..6695bc26bda
Binary files /dev/null and 
b/regression-test/data/nereids_p0/test_alter_catalog_properties_command.out 
differ
diff --git 
a/regression-test/suites/nereids_p0/test_alter_catalog_properties_command.groovy
 
b/regression-test/suites/nereids_p0/test_alter_catalog_properties_command.groovy
new file mode 100644
index 00000000000..72bd89d11b7
--- /dev/null
+++ 
b/regression-test/suites/nereids_p0/test_alter_catalog_properties_command.groovy
@@ -0,0 +1,55 @@
+// 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_catalog_properties_command", "nereids_p0") {
+    def catalogName = "test_alter_catalog_properties"
+    def catalogProperties = "\"type\"=\"es\", 
\"hosts\"=\"http://127.0.0.1:9200\"";
+    def newProperties = "\"type\"=\"es\", 
\"hosts\"=\"http://192.168.0.1:9200\"";
+
+    try {
+        // Drop catalog if it already exists
+        sql("DROP CATALOG IF EXISTS ${catalogName}")
+
+        // Create a new catalog
+        sql(
+            """
+            CREATE CATALOG ${catalogName} 
+            COMMENT 'Catalog for property test'
+            PROPERTIES (${catalogProperties})
+            """
+        )
+        // Verify the catalog was created
+        checkNereidsExecute("""SHOW CREATE CATALOG ${catalogName}""")
+        qt_cmd("""SHOW CREATE CATALOG ${catalogName}""")
+
+        // Alter the catalog properties
+        checkNereidsExecute(
+            """
+            ALTER CATALOG ${catalogName} SET PROPERTIES (${newProperties})
+            """
+        )
+
+        // Verify the properties were changed
+        checkNereidsExecute("""SHOW CREATE CATALOG ${catalogName}""")
+        qt_cmd("""SHOW CREATE CATALOG ${catalogName}""")
+
+    } finally {
+        // Clean up
+        sql("DROP CATALOG IF EXISTS ${catalogName}")
+    }
+}
+


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

Reply via email to