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 b0ab7f1c9eb [Enhancement] (nereids)implement
alterCatalogCommentCommand in nereids (#45160)
b0ab7f1c9eb is described below
commit b0ab7f1c9eb83f853c06bc792dd28e612aea38cc
Author: Sridhar R Manikarnike <[email protected]>
AuthorDate: Mon Dec 16 12:03:45 2024 +0530
[Enhancement] (nereids)implement alterCatalogCommentCommand in nereids
(#45160)
Issue Number: close #42790
---
.../antlr4/org/apache/doris/nereids/DorisParser.g4 | 2 +-
.../org/apache/doris/datasource/CatalogMgr.java | 20 +++++---
.../doris/nereids/parser/LogicalPlanBuilder.java | 9 ++++
.../apache/doris/nereids/trees/plans/PlanType.java | 1 +
.../trees/plans/commands/AlterCatalogCommand.java | 58 ++++++++++++++++++++++
.../plans/commands/AlterCatalogCommentCommand.java | 58 ++++++++++++++++++++++
.../trees/plans/visitor/CommandVisitor.java | 5 ++
.../test_alter_catalog_comment_command.out | 7 +++
.../test_alter_catalog_comment_command.groovy | 54 ++++++++++++++++++++
9 files changed, 206 insertions(+), 8 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 274a354b63b..044ed7771a4 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
@@ -206,6 +206,7 @@ supportedAlterStatement
| ALTER WORKLOAD POLICY name=identifierOrText
properties=propertyClause?
#alterWorkloadPolicy
| ALTER SQL_BLOCK_RULE name=identifier properties=propertyClause?
#alterSqlBlockRule
+ | ALTER CATALOG name=identifier MODIFY COMMENT comment=STRING_LITERAL
#alterCatalogComment
;
supportedDropStatement
@@ -582,7 +583,6 @@ unsupportedAlterStatement
| ALTER CATALOG name=identifier RENAME newName=identifier
#alterCatalogRename
| ALTER CATALOG name=identifier SET PROPERTIES
LEFT_PAREN propertyItemList RIGHT_PAREN
#alterCatalogProperties
- | ALTER CATALOG name=identifier MODIFY COMMENT comment=STRING_LITERAL
#alterCatalogComment
| 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 1d1a44be7b4..070d31c071e 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
@@ -314,17 +314,16 @@ public class CatalogMgr implements Writable,
GsonPostProcessable {
}
}
- /**
- * Modify the catalog comment to a new one and write the meta log.
- */
- public void alterCatalogComment(AlterCatalogCommentStmt stmt) throws
UserException {
+ public void alterCatalogComment(String catalogName, String comment) 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);
}
- CatalogLog log = CatalogFactory.createCatalogLog(catalog.getId(),
stmt);
+ CatalogLog log = new CatalogLog();
+ log.setCatalogId(catalog.getId());
+ log.setComment(comment);
replayAlterCatalogComment(log);
Env.getCurrentEnv().getEditLog().logCatalogLog(OperationType.OP_ALTER_CATALOG_COMMENT,
log);
} finally {
@@ -332,6 +331,13 @@ public class CatalogMgr implements Writable,
GsonPostProcessable {
}
}
+ /**
+ * Modify the catalog comment to a new one and write the meta log.
+ */
+ public void alterCatalogComment(AlterCatalogCommentStmt stmt) throws
UserException {
+ alterCatalogComment(stmt.getCatalogName(), stmt.getComment());
+ }
+
/**
* Modify the catalog property and write the meta log.
*/
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 56de50d620e..e6fee894b41 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
@@ -60,6 +60,7 @@ import org.apache.doris.nereids.DorisParser.AggClauseContext;
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.AlterMTMVContext;
import org.apache.doris.nereids.DorisParser.AlterRoleContext;
import org.apache.doris.nereids.DorisParser.AlterSqlBlockRuleContext;
@@ -482,6 +483,7 @@ import
org.apache.doris.nereids.trees.plans.commands.AdminCheckTabletsCommand;
import org.apache.doris.nereids.trees.plans.commands.AdminCleanTrashCommand;
import org.apache.doris.nereids.trees.plans.commands.AdminCompactTableCommand;
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.AlterMTMVCommand;
import org.apache.doris.nereids.trees.plans.commands.AlterRoleCommand;
import org.apache.doris.nereids.trees.plans.commands.AlterSqlBlockRuleCommand;
@@ -4824,6 +4826,13 @@ public class LogicalPlanBuilder extends
DorisParserBaseVisitor<Object> {
return new ShowWhiteListCommand();
}
+ @Override
+ public LogicalPlan visitAlterCatalogComment(AlterCatalogCommentContext
ctx) {
+ String catalogName = stripQuotes(ctx.name.getText());
+ String comment = stripQuotes(ctx.comment.getText());
+ return new AlterCatalogCommentCommand(catalogName, comment);
+ }
+
@Override
public LogicalPlan visitShowDynamicPartition(ShowDynamicPartitionContext
ctx) {
String dbName = 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 204d4b07111..e8ce4b3e2d8 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
@@ -200,6 +200,7 @@ public enum PlanType {
DROP_USER_COMMAND,
DROP_WORKLOAD_GROUP_NAME,
DROP_WORKLOAD_POLICY_COMMAND,
+ ALTER_CATALOG_COMMENT_COMMAND,
ALTER_SQL_BLOCK_RULE_COMMAND,
SHOW_BACKENDS_COMMAND,
SHOW_BLOCK_RULE_COMMAND,
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/AlterCatalogCommand.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/AlterCatalogCommand.java
new file mode 100644
index 00000000000..83ef02e8890
--- /dev/null
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/AlterCatalogCommand.java
@@ -0,0 +1,58 @@
+// 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.util.Util;
+import org.apache.doris.datasource.InternalCatalog;
+import org.apache.doris.mysql.privilege.PrivPredicate;
+import org.apache.doris.nereids.trees.plans.PlanType;
+import org.apache.doris.qe.ConnectContext;
+
+import java.util.Objects;
+
+/**
+ * Base class for AlterCatalog commands.
+ */
+public abstract class AlterCatalogCommand extends AlterCommand {
+ protected final String catalogName;
+
+ public AlterCatalogCommand(PlanType type, String catalogName) {
+ super(type);
+ this.catalogName = Objects.requireNonNull(catalogName, "Catalog name
cannot be null");
+ }
+
+ protected void validate(ConnectContext ctx) throws Exception {
+ Util.checkCatalogAllRules(catalogName);
+
+ if (!Env.getCurrentEnv().getAccessManager().checkCtlPriv(ctx,
catalogName, PrivPredicate.ALTER)) {
+
ErrorReport.reportAnalysisException(ErrorCode.ERR_CATALOG_ACCESS_DENIED,
+ ctx.getQualifiedUser(), catalogName);
+ }
+
+ if (catalogName.equals(InternalCatalog.INTERNAL_CATALOG_NAME)) {
+ throw new Exception("Internal catalog cannot be altered.");
+ }
+ }
+
+ public String getCatalogName() {
+ return catalogName;
+ }
+}
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
new file mode 100644
index 00000000000..eafe1f7c2c1
--- /dev/null
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/AlterCatalogCommentCommand.java
@@ -0,0 +1,58 @@
+// 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.AnalysisException;
+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.Objects;
+
+/**
+ * Represents the command for ALTER CATALOG MODIFY COMMENT.
+ */
+public class AlterCatalogCommentCommand extends AlterCatalogCommand {
+
+ private final String comment;
+
+ public AlterCatalogCommentCommand(String catalogName, String comment) {
+ super(PlanType.ALTER_CATALOG_COMMENT_COMMAND, catalogName);
+ this.comment = Objects.requireNonNull(comment, "Comment 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.");
+ }
+
+ // Fetch and modify the catalog's comment
+ Env.getCurrentEnv().getCatalogMgr().alterCatalogComment(catalogName,
comment);
+ }
+
+ @Override
+ public <R, C> R accept(PlanVisitor<R, C> visitor, C context) {
+ return visitor.visitAlterCatalogCommentCommand(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 e2ac1c863e2..0341ed2f57d 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
@@ -22,6 +22,7 @@ import
org.apache.doris.nereids.trees.plans.commands.AdminCheckTabletsCommand;
import org.apache.doris.nereids.trees.plans.commands.AdminCleanTrashCommand;
import org.apache.doris.nereids.trees.plans.commands.AdminCompactTableCommand;
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.AlterJobStatusCommand;
import org.apache.doris.nereids.trees.plans.commands.AlterMTMVCommand;
import org.apache.doris.nereids.trees.plans.commands.AlterRoleCommand;
@@ -324,6 +325,10 @@ public interface CommandVisitor<R, C> {
return visitCommand(alterViewCommand, context);
}
+ default R visitAlterCatalogCommentCommand(AlterCatalogCommentCommand
alterCatalogCommentCommand, C context) {
+ return visitCommand(alterCatalogCommentCommand, context);
+ }
+
default R visitDropCatalogRecycleBinCommand(DropCatalogRecycleBinCommand
dropCatalogRecycleBinCommand, C context) {
return visitCommand(dropCatalogRecycleBinCommand, context);
}
diff --git
a/regression-test/data/nereids_p0/test_alter_catalog_comment_command.out
b/regression-test/data/nereids_p0/test_alter_catalog_comment_command.out
new file mode 100644
index 00000000000..646f4cb2781
--- /dev/null
+++ b/regression-test/data/nereids_p0/test_alter_catalog_comment_command.out
@@ -0,0 +1,7 @@
+-- This file is automatically generated. You should know what you did if you
want to edit this
+-- !cmd --
+test_alter_catalog_comment \nCREATE CATALOG
`test_alter_catalog_comment`\nCOMMENT "Initial catalog comment"\n PROPERTIES
(\n"type" = "es",\n"hosts" = "http://127.0.0.1:9200"\n);
+
+-- !cmd --
+test_alter_catalog_comment \nCREATE CATALOG
`test_alter_catalog_comment`\nCOMMENT "Updated catalog comment"\n PROPERTIES
(\n"type" = "es",\n"hosts" = "http://127.0.0.1:9200"\n);
+
diff --git
a/regression-test/suites/nereids_p0/test_alter_catalog_comment_command.groovy
b/regression-test/suites/nereids_p0/test_alter_catalog_comment_command.groovy
new file mode 100644
index 00000000000..389675aff9a
--- /dev/null
+++
b/regression-test/suites/nereids_p0/test_alter_catalog_comment_command.groovy
@@ -0,0 +1,54 @@
+// 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_comment_command", "nereids_p0") {
+ def catalogName = "test_alter_catalog_comment"
+ def catalogProperties = "\"type\"=\"es\",
\"hosts\"=\"http://127.0.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 'Initial catalog comment'
+ PROPERTIES (${catalogProperties})
+ """
+ )
+ // Verify the catalog was created
+ checkNereidsExecute("""show create catalog ${catalogName}""")
+ qt_cmd("""show create catalog ${catalogName}""")
+
+
+ // Alter the catalog comment
+ checkNereidsExecute(
+ """
+ ALTER CATALOG ${catalogName} MODIFY COMMENT 'Updated catalog
comment'
+ """
+ )
+ // Verify the comment was 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: [email protected]
For additional commands, e-mail: [email protected]