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 3b42e9cb8d4 [Enhancement] (nereids)implement 
alterDatabasePropertiesCommand in nereids (#49365)
3b42e9cb8d4 is described below

commit 3b42e9cb8d443d12d35eb73b1c105e7b58583089
Author: Sridhar R Manikarnike <sridhar.n...@gmail.com>
AuthorDate: Wed May 21 07:20:36 2025 +0530

    [Enhancement] (nereids)implement alterDatabasePropertiesCommand in nereids 
(#49365)
    
    Issue Number: close #42787
---
 .../antlr4/org/apache/doris/nereids/DorisParser.g4 |  6 +-
 .../main/java/org/apache/doris/catalog/Env.java    |  4 ++
 .../apache/doris/datasource/InternalCatalog.java   | 11 ++-
 .../doris/nereids/parser/LogicalPlanBuilder.java   | 15 ++++
 .../apache/doris/nereids/trees/plans/PlanType.java |  1 +
 .../commands/AlterDatabasePropertiesCommand.java   | 84 ++++++++++++++++++++++
 .../trees/plans/visitor/CommandVisitor.java        |  5 ++
 .../test_alter_database_properties_command.groovy  | 35 +++++++++
 8 files changed, 155 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 7101605fe8a..db440d303f3 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
@@ -274,6 +274,8 @@ supportedAlterStatement
         SET LEFT_PAREN propertyItemList RIGHT_PAREN                            
             #alterTableProperties
     | ALTER DATABASE name=identifier SET (DATA | REPLICA | TRANSACTION)
             QUOTA (quota=identifier | INTEGER_VALUE)                           
             #alterDatabaseSetQuota
+    | ALTER DATABASE name=identifier SET PROPERTIES
+            LEFT_PAREN propertyItemList RIGHT_PAREN                            
             #alterDatabaseProperties
     | ALTER SYSTEM RENAME COMPUTE GROUP name=identifier newName=identifier     
             #alterSystemRenameComputeGroup
     | ALTER REPOSITORY name=identifier properties=propertyClause?              
             #alterRepository
     | ALTER USER (IF EXISTS)? grantUserIdentify
@@ -661,9 +663,7 @@ privilegeList
     ;
 
 unsupportedAlterStatement
-    : ALTER DATABASE name=identifier SET PROPERTIES
-        LEFT_PAREN propertyItemList RIGHT_PAREN                                
     #alterDatabaseProperties
-    | ALTER RESOURCE name=identifierOrText properties=propertyClause?          
     #alterResource
+    : ALTER RESOURCE name=identifierOrText properties=propertyClause?          
     #alterResource
     | ALTER COLOCATE GROUP name=multipartIdentifier
         SET LEFT_PAREN propertyItemList RIGHT_PAREN                            
     #alterColocateGroup
     | ALTER ROUTINE LOAD FOR name=multipartIdentifier 
properties=propertyClause?
diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java 
b/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java
index e6d36394454..09becd66de4 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java
@@ -3472,6 +3472,10 @@ public class Env {
         getInternalCatalog().alterDatabaseProperty(stmt);
     }
 
+    public void alterDatabaseProperty(String dbName, Map<String, String> 
properties) throws DdlException {
+        getInternalCatalog().alterDatabaseProperty(dbName, properties);
+    }
+
     public void replayAlterDatabaseProperty(String dbName, Map<String, String> 
properties)
             throws MetaNotFoundException {
         getInternalCatalog().replayAlterDatabaseProperty(dbName, properties);
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java 
b/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java
index bee5e7440d7..4011853d6b5 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java
@@ -850,11 +850,9 @@ public class InternalCatalog implements 
CatalogIf<Database> {
         }
     }
 
-    public void alterDatabaseProperty(AlterDatabasePropertyStmt stmt) throws 
DdlException {
-        String dbName = stmt.getDbName();
+    public void alterDatabaseProperty(String dbName, Map<String, String> 
properties) throws DdlException {
         Database db = (Database) getDbOrDdlException(dbName);
         long dbId = db.getId();
-        Map<String, String> properties = stmt.getProperties();
 
         db.writeLockOrDdlException();
         try {
@@ -870,6 +868,13 @@ public class InternalCatalog implements 
CatalogIf<Database> {
         }
     }
 
+    public void alterDatabaseProperty(AlterDatabasePropertyStmt stmt) throws 
DdlException {
+        String dbName = stmt.getDbName();
+        Map<String, String> properties = stmt.getProperties();
+
+        alterDatabaseProperty(dbName, properties);
+    }
+
     public void replayAlterDatabaseProperty(String dbName, Map<String, String> 
properties)
             throws MetaNotFoundException {
         Database db = (Database) getDbOrMetaException(dbName);
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 331f1e95cd3..3bb6ea1b074 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
@@ -92,6 +92,7 @@ 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.AlterDatabasePropertiesContext;
 import org.apache.doris.nereids.DorisParser.AlterDatabaseRenameContext;
 import org.apache.doris.nereids.DorisParser.AlterDatabaseSetQuotaContext;
 import org.apache.doris.nereids.DorisParser.AlterMTMVContext;
@@ -562,6 +563,7 @@ 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.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.AlterRoleCommand;
 import org.apache.doris.nereids.trees.plans.commands.AlterSqlBlockRuleCommand;
@@ -5424,6 +5426,19 @@ public class LogicalPlanBuilder extends 
DorisParserBaseVisitor<Object> {
         return new ShowRestoreCommand(dbName, wildWhere, ctx.BRIEF() != null);
     }
 
+    @Override
+    public LogicalPlan 
visitAlterDatabaseProperties(AlterDatabasePropertiesContext ctx) {
+        String dbName = Optional.ofNullable(ctx.name)
+                .map(ParserRuleContext::getText)
+                .filter(s -> !s.isEmpty())
+                .orElseThrow(() -> new ParseException("Database name is empty 
or cannot be an empty string"));
+        Map<String, String> properties = ctx.propertyItemList() != null
+                ? 
Maps.newHashMap(visitPropertyItemList(ctx.propertyItemList()))
+                : Maps.newHashMap();
+
+        return new AlterDatabasePropertiesCommand(dbName, properties);
+    }
+
     @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 cb6c520c30e..feade0d7818 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
@@ -332,6 +332,7 @@ public enum PlanType {
     DROP_TABLE_COMMAND,
     ANALYZE_DATABASE,
     ANALYZE_TABLE,
+    ALTER_DATABASE_PROPERTIES_COMMAND,
     ALTER_SYSTEM,
     ALTER_SYSTEM_RENAME_COMPUTE_GROUP,
     ALTER_USER_COMMAND,
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/AlterDatabasePropertiesCommand.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/AlterDatabasePropertiesCommand.java
new file mode 100644
index 00000000000..deadc3cf8e8
--- /dev/null
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/AlterDatabasePropertiesCommand.java
@@ -0,0 +1,84 @@
+// 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.common.ErrorCode;
+import org.apache.doris.common.ErrorReport;
+import org.apache.doris.common.UserException;
+import org.apache.doris.common.util.InternalDatabaseUtil;
+import org.apache.doris.common.util.PropertyAnalyzer;
+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 com.google.common.base.Strings;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Command for ALTER DATABASE ... SET PROPERTIES in Nereids.
+ */
+public class AlterDatabasePropertiesCommand extends AlterCommand {
+
+    private final String dbName;
+    private final Map<String, String> properties;
+
+    public AlterDatabasePropertiesCommand(String databaseName, Map<String, 
String> properties) {
+        super(PlanType.ALTER_DATABASE_PROPERTIES_COMMAND);
+        this.dbName = databaseName;
+        this.properties = properties;
+    }
+
+    private void validate(ConnectContext ctx) throws UserException {
+        InternalDatabaseUtil.checkDatabase(dbName, ConnectContext.get());
+        if 
(!Env.getCurrentEnv().getAccessManager().checkGlobalPriv(ConnectContext.get(), 
PrivPredicate.ADMIN)) {
+            
ErrorReport.reportAnalysisException(ErrorCode.ERR_DBACCESS_DENIED_ERROR,
+                    ctx.getQualifiedUser(), dbName);
+        }
+
+        if (Strings.isNullOrEmpty(dbName)) {
+            ErrorReport.reportAnalysisException(ErrorCode.ERR_NO_DB_ERROR);
+        }
+
+        if (properties == null || properties.isEmpty()) {
+            throw new UserException("Properties is null or empty");
+        }
+
+        // clone properties for analyse
+        Map<String, String> analysisProperties = new HashMap<String, 
String>(properties);
+        PropertyAnalyzer.analyzeBinlogConfig(analysisProperties);
+    }
+
+    @Override
+    public void doRun(ConnectContext ctx, StmtExecutor executor) throws 
Exception {
+        validate(ctx);
+
+        Env.getCurrentEnv().alterDatabaseProperty(dbName, properties);
+    }
+
+    @Override
+    public <R, C> R accept(PlanVisitor<R, C> visitor, C context) {
+        return visitor.visitAlterDatabasePropertiesCommand(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 c64cda4565d..a052447c01b 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
@@ -33,6 +33,7 @@ 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.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.AlterRoleCommand;
@@ -748,6 +749,10 @@ public interface CommandVisitor<R, C> {
         return visitCommand(alterCatalogPropsCmd, context);
     }
 
+    default R 
visitAlterDatabasePropertiesCommand(AlterDatabasePropertiesCommand 
alterDatabasePropsCmd, C context) {
+        return visitCommand(alterDatabasePropsCmd, context);
+    }
+
     default R visitRecoverDatabaseCommand(RecoverDatabaseCommand 
recoverDatabaseCommand, C context) {
         return visitCommand(recoverDatabaseCommand, context);
     }
diff --git 
a/regression-test/suites/nereids_p0/test_alter_database_properties_command.groovy
 
b/regression-test/suites/nereids_p0/test_alter_database_properties_command.groovy
new file mode 100644
index 00000000000..c692774bcfa
--- /dev/null
+++ 
b/regression-test/suites/nereids_p0/test_alter_database_properties_command.groovy
@@ -0,0 +1,35 @@
+// 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_database_properties_command", "nereids_p0") {
+    def dbName = "test_alter_db_properties"
+
+    try {
+        sql """CREATE DATABASE IF NOT EXISTS ${dbName}"""
+
+        checkNereidsExecute("""SHOW DATABASES""")
+
+        checkNereidsExecute("""
+            ALTER DATABASE ${dbName} SET PROPERTIES ("replication_num" = "2", 
"compression" = "zstd")
+        """)
+
+    } finally {
+        // Clean up
+        sql """DROP DATABASE IF EXISTS ${dbName}"""
+    }
+}
+


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

Reply via email to