This is an automated email from the ASF dual-hosted git repository.
morningman 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 d1f59a40253 [fix](catalog)fix when modifying comments in property, it
will modify the comments in the catalog (#24857)
d1f59a40253 is described below
commit d1f59a4025399f02bdc04d89800779cfc3bc3aad
Author: zhangdong <[email protected]>
AuthorDate: Wed Oct 11 23:16:19 2023 +0800
[fix](catalog)fix when modifying comments in property, it will modify the
comments in the catalog (#24857)
- fix when modifying comments in property, it will modify the comments in
the catalog
- add `alter catalog modify comment` to modify comment for catalog
- abstract some logic of `alter catalog` to parent class
---
.../Alter/ALTER-CATALOG.md | 15 +++++++
.../Create/CREATE-CATALOG.md | 4 +-
.../Alter/ALTER-CATALOG.md | 15 +++++++
.../Create/CREATE-CATALOG.md | 4 +-
fe/fe-core/src/main/cup/sql_parser.cup | 4 ++
.../doris/analysis/AlterCatalogCommentStmt.java | 49 ++++++++++++++++++++++
.../doris/analysis/AlterCatalogNameStmt.java | 26 +-----------
.../doris/analysis/AlterCatalogPropertyStmt.java | 33 +--------------
...rCatalogNameStmt.java => AlterCatalogStmt.java} | 40 ++++--------------
.../apache/doris/datasource/CatalogFactory.java | 8 ++--
.../org/apache/doris/datasource/CatalogIf.java | 3 ++
.../org/apache/doris/datasource/CatalogMgr.java | 34 +++++++++++++++
.../apache/doris/datasource/ExternalCatalog.java | 6 ---
.../org/apache/doris/journal/JournalEntity.java | 1 +
.../java/org/apache/doris/persist/EditLog.java | 5 +++
.../org/apache/doris/persist/OperationType.java | 2 +
.../main/java/org/apache/doris/qe/DdlExecutor.java | 3 ++
.../apache/doris/datasource/CatalogMgrTest.java | 19 ++++++++-
.../external_table_p0/test_catalog_ddl.groovy | 47 +++++++++++++++++++++
19 files changed, 215 insertions(+), 103 deletions(-)
diff --git
a/docs/en/docs/sql-manual/sql-reference/Data-Definition-Statements/Alter/ALTER-CATALOG.md
b/docs/en/docs/sql-manual/sql-reference/Data-Definition-Statements/Alter/ALTER-CATALOG.md
index 207986f9efc..b20b3366363 100644
---
a/docs/en/docs/sql-manual/sql-reference/Data-Definition-Statements/Alter/ALTER-CATALOG.md
+++
b/docs/en/docs/sql-manual/sql-reference/Data-Definition-Statements/Alter/ALTER-CATALOG.md
@@ -61,6 +61,15 @@ illustrate:
- property `type` cannot be modified.
- properties of builtin catalog `internal` cannot be modified.
+3) Modify comment for the catalog
+
+```sql
+ALTER CATALOG catalog_name MODIFY COMMENT "new catalog comment";
+```
+
+illustrate:
+- The builtin catalog `internal` cannot be modified
+
### Example
1. rename catalog ctlg_hive to hive
@@ -75,6 +84,12 @@ ALTER CATALOG ctlg_hive RENAME hive;
ALTER CATALOG hive SET PROPERTIES
('hive.metastore.uris'='thrift://172.21.0.1:9083');
```
+4. modify comment of catalog hive
+
+```sql
+ALTER CATALOG hive MODIFY COMMENT "new catalog comment";
+```
+
### Keywords
ALTER,CATALOG,RENAME,PROPERTY
diff --git
a/docs/en/docs/sql-manual/sql-reference/Data-Definition-Statements/Create/CREATE-CATALOG.md
b/docs/en/docs/sql-manual/sql-reference/Data-Definition-Statements/Create/CREATE-CATALOG.md
index 429686e848d..c3d59ccc4a3 100644
---
a/docs/en/docs/sql-manual/sql-reference/Data-Definition-Statements/Create/CREATE-CATALOG.md
+++
b/docs/en/docs/sql-manual/sql-reference/Data-Definition-Statements/Create/CREATE-CATALOG.md
@@ -37,7 +37,7 @@ This statement is used to create an external catalog
Syntax:
```sql
-CREATE CATALOG [IF NOT EXISTS] catalog_name
+CREATE CATALOG [IF NOT EXISTS] catalog_name [comment]
PROPERTIES ("key"="value", ...);
```
@@ -46,7 +46,7 @@ CREATE CATALOG [IF NOT EXISTS] catalog_name
1. Create catalog hive
```sql
- CREATE CATALOG hive PROPERTIES (
+ CREATE CATALOG hive comment 'hive catalog' PROPERTIES (
'type'='hms',
'hive.metastore.uris' = 'thrift://127.0.0.1:7004',
'dfs.nameservices'='HANN',
diff --git
a/docs/zh-CN/docs/sql-manual/sql-reference/Data-Definition-Statements/Alter/ALTER-CATALOG.md
b/docs/zh-CN/docs/sql-manual/sql-reference/Data-Definition-Statements/Alter/ALTER-CATALOG.md
index ceff0e82d57..71f289c61bb 100644
---
a/docs/zh-CN/docs/sql-manual/sql-reference/Data-Definition-Statements/Alter/ALTER-CATALOG.md
+++
b/docs/zh-CN/docs/sql-manual/sql-reference/Data-Definition-Statements/Alter/ALTER-CATALOG.md
@@ -60,6 +60,15 @@ ALTER CATALOG catalog_name SET PROPERTIES ('key1' = 'value1'
[, 'key' = 'value2'
- 不可更改数据目录类型,即 `type` 属性
- 不可更改内置数据目录 `internal` 的属性
+3) 修改数据目录注释
+
+```sql
+ALTER CATALOG catalog_name MODIFY COMMENT "new catalog comment";
+```
+
+注意:
+- `internal` 是内置数据目录,不允许修改注释
+
### Example
1. 将数据目录 ctlg_hive 重命名为 hive
@@ -74,6 +83,12 @@ ALTER CATALOG ctlg_hive RENAME hive;
ALTER CATALOG hive SET PROPERTIES
('hive.metastore.uris'='thrift://172.21.0.1:9083');
```
+4. 更改名为 hive 数据目录的注释
+
+```sql
+ALTER CATALOG hive MODIFY COMMENT "new catalog comment";
+```
+
### Keywords
ALTER,CATALOG,RENAME,PROPERTY
diff --git
a/docs/zh-CN/docs/sql-manual/sql-reference/Data-Definition-Statements/Create/CREATE-CATALOG.md
b/docs/zh-CN/docs/sql-manual/sql-reference/Data-Definition-Statements/Create/CREATE-CATALOG.md
index 17d0d77dc14..a192237d8cc 100644
---
a/docs/zh-CN/docs/sql-manual/sql-reference/Data-Definition-Statements/Create/CREATE-CATALOG.md
+++
b/docs/zh-CN/docs/sql-manual/sql-reference/Data-Definition-Statements/Create/CREATE-CATALOG.md
@@ -37,7 +37,7 @@ CREATE CATALOG
语法:
```sql
-CREATE CATALOG [IF NOT EXISTS] catalog_name
+CREATE CATALOG [IF NOT EXISTS] catalog_name [comment]
PROPERTIES ("key"="value", ...);
```
@@ -50,7 +50,7 @@ CREATE CATALOG [IF NOT EXISTS] catalog_name
1. 新建数据目录 hive
```sql
- CREATE CATALOG hive PROPERTIES (
+ CREATE CATALOG hive comment 'hive catalog' PROPERTIES (
'type'='hms',
'hive.metastore.uris' = 'thrift://127.0.0.1:7004',
'dfs.nameservices'='HANN',
diff --git a/fe/fe-core/src/main/cup/sql_parser.cup
b/fe/fe-core/src/main/cup/sql_parser.cup
index b79f2a5849c..5675e11b495 100644
--- a/fe/fe-core/src/main/cup/sql_parser.cup
+++ b/fe/fe-core/src/main/cup/sql_parser.cup
@@ -1345,6 +1345,10 @@ alter_stmt ::=
{:
RESULT = new AlterCatalogPropertyStmt(catalogName, map);
:}
+ | KW_ALTER KW_CATALOG ident:catalogName KW_MODIFY KW_COMMENT
STRING_LITERAL:comment
+ {:
+ RESULT = new AlterCatalogCommentStmt(catalogName, comment);
+ :}
| KW_ALTER KW_RESOURCE ident_or_text:resourceName opt_properties:properties
{:
RESULT = new AlterResourceStmt(resourceName, properties);
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterCatalogCommentStmt.java
b/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterCatalogCommentStmt.java
new file mode 100644
index 00000000000..cfc52f077d7
--- /dev/null
+++
b/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterCatalogCommentStmt.java
@@ -0,0 +1,49 @@
+// 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.analysis;
+
+import org.apache.doris.common.AnalysisException;
+import org.apache.doris.common.UserException;
+
+import com.google.common.base.Strings;
+
+public class AlterCatalogCommentStmt extends AlterCatalogStmt {
+ private final String comment;
+
+ public AlterCatalogCommentStmt(String catalogName, String comment) {
+ super(catalogName);
+ this.comment = comment;
+ }
+
+ public String getComment() {
+ return comment;
+ }
+
+ @Override
+ public void analyze(Analyzer analyzer) throws UserException {
+ super.analyze(analyzer);
+ if (Strings.isNullOrEmpty(comment)) {
+ throw new AnalysisException("New comment is not set.");
+ }
+ }
+
+ @Override
+ public String toSql() {
+ return "ALTER CATALOG " + catalogName + " MODIFY COMMENT " + comment;
+ }
+}
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterCatalogNameStmt.java
b/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterCatalogNameStmt.java
index 183a74604e1..f3c363fd5eb 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterCatalogNameStmt.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterCatalogNameStmt.java
@@ -17,35 +17,24 @@
package org.apache.doris.analysis;
-import org.apache.doris.catalog.Env;
import org.apache.doris.common.AnalysisException;
-import org.apache.doris.common.ErrorCode;
-import org.apache.doris.common.ErrorReport;
import org.apache.doris.common.FeNameFormat;
import org.apache.doris.common.UserException;
-import org.apache.doris.common.util.Util;
import org.apache.doris.datasource.InternalCatalog;
-import org.apache.doris.mysql.privilege.PrivPredicate;
-import org.apache.doris.qe.ConnectContext;
import com.google.common.base.Strings;
/**
* Statement for alter the catalog name.
*/
-public class AlterCatalogNameStmt extends DdlStmt {
- private final String catalogName;
+public class AlterCatalogNameStmt extends AlterCatalogStmt {
private final String newCatalogName;
public AlterCatalogNameStmt(String catalogName, String newCatalogName) {
- this.catalogName = catalogName;
+ super(catalogName);
this.newCatalogName = newCatalogName;
}
- public String getCatalogName() {
- return catalogName;
- }
-
public String getNewCatalogName() {
return newCatalogName;
}
@@ -53,17 +42,6 @@ public class AlterCatalogNameStmt extends DdlStmt {
@Override
public void analyze(Analyzer analyzer) throws UserException {
super.analyze(analyzer);
- Util.checkCatalogAllRules(catalogName);
-
- if (catalogName.equals(InternalCatalog.INTERNAL_CATALOG_NAME)) {
- throw new AnalysisException("Internal catalog can't be alter.");
- }
-
- if (!Env.getCurrentEnv().getAccessManager().checkCtlPriv(
- ConnectContext.get(), catalogName, PrivPredicate.ALTER)) {
-
ErrorReport.reportAnalysisException(ErrorCode.ERR_CATALOG_ACCESS_DENIED,
- analyzer.getQualifiedUser(), catalogName);
- }
if (Strings.isNullOrEmpty(newCatalogName)) {
throw new AnalysisException("New catalog name is not set");
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterCatalogPropertyStmt.java
b/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterCatalogPropertyStmt.java
index 0689809011c..95480f325f5 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterCatalogPropertyStmt.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterCatalogPropertyStmt.java
@@ -17,40 +17,21 @@
package org.apache.doris.analysis;
-import org.apache.doris.catalog.Env;
-import org.apache.doris.common.AnalysisException;
-import org.apache.doris.common.ErrorCode;
-import org.apache.doris.common.ErrorReport;
import org.apache.doris.common.UserException;
import org.apache.doris.common.util.PrintableMap;
import org.apache.doris.common.util.PropertyAnalyzer;
-import org.apache.doris.common.util.Util;
-import org.apache.doris.datasource.InternalCatalog;
-import org.apache.doris.mysql.privilege.PrivPredicate;
-import org.apache.doris.qe.ConnectContext;
import java.util.Map;
/**
* Statement for alter the catalog property.
*/
-public class AlterCatalogPropertyStmt extends DdlStmt {
- private final String catalogName;
- private final String comment;
+public class AlterCatalogPropertyStmt extends AlterCatalogStmt {
private final Map<String, String> newProperties;
public AlterCatalogPropertyStmt(String catalogName, Map<String, String>
newProperties) {
- this.catalogName = catalogName;
+ super(catalogName);
this.newProperties = newProperties;
- this.comment = newProperties.getOrDefault("comment", "");
- }
-
- public String getCatalogName() {
- return catalogName;
- }
-
- public String getComment() {
- return comment;
}
public Map<String, String> getNewProperties() {
@@ -60,16 +41,6 @@ public class AlterCatalogPropertyStmt extends DdlStmt {
@Override
public void analyze(Analyzer analyzer) throws UserException {
super.analyze(analyzer);
- Util.checkCatalogAllRules(catalogName);
- if (!Env.getCurrentEnv().getAccessManager().checkCtlPriv(
- ConnectContext.get(), catalogName, PrivPredicate.ALTER)) {
-
ErrorReport.reportAnalysisException(ErrorCode.ERR_CATALOG_ACCESS_DENIED,
- analyzer.getQualifiedUser(), catalogName);
- }
-
- if (catalogName.equals(InternalCatalog.INTERNAL_CATALOG_NAME)) {
- throw new AnalysisException("Internal catalog can't be alter.");
- }
PropertyAnalyzer.checkCatalogProperties(newProperties, true);
}
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterCatalogNameStmt.java
b/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterCatalogStmt.java
similarity index 67%
copy from
fe/fe-core/src/main/java/org/apache/doris/analysis/AlterCatalogNameStmt.java
copy to fe/fe-core/src/main/java/org/apache/doris/analysis/AlterCatalogStmt.java
index 183a74604e1..98f3f4e690d 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterCatalogNameStmt.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterCatalogStmt.java
@@ -21,61 +21,35 @@ import org.apache.doris.catalog.Env;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.ErrorCode;
import org.apache.doris.common.ErrorReport;
-import org.apache.doris.common.FeNameFormat;
import org.apache.doris.common.UserException;
import org.apache.doris.common.util.Util;
import org.apache.doris.datasource.InternalCatalog;
import org.apache.doris.mysql.privilege.PrivPredicate;
import org.apache.doris.qe.ConnectContext;
-import com.google.common.base.Strings;
+public class AlterCatalogStmt extends DdlStmt {
+ protected final String catalogName;
-/**
- * Statement for alter the catalog name.
- */
-public class AlterCatalogNameStmt extends DdlStmt {
- private final String catalogName;
- private final String newCatalogName;
-
- public AlterCatalogNameStmt(String catalogName, String newCatalogName) {
+ public AlterCatalogStmt(String catalogName) {
this.catalogName = catalogName;
- this.newCatalogName = newCatalogName;
- }
-
- public String getCatalogName() {
- return catalogName;
- }
-
- public String getNewCatalogName() {
- return newCatalogName;
}
@Override
public void analyze(Analyzer analyzer) throws UserException {
super.analyze(analyzer);
Util.checkCatalogAllRules(catalogName);
-
- if (catalogName.equals(InternalCatalog.INTERNAL_CATALOG_NAME)) {
- throw new AnalysisException("Internal catalog can't be alter.");
- }
-
if (!Env.getCurrentEnv().getAccessManager().checkCtlPriv(
ConnectContext.get(), catalogName, PrivPredicate.ALTER)) {
ErrorReport.reportAnalysisException(ErrorCode.ERR_CATALOG_ACCESS_DENIED,
analyzer.getQualifiedUser(), catalogName);
}
- if (Strings.isNullOrEmpty(newCatalogName)) {
- throw new AnalysisException("New catalog name is not set");
- }
- if (newCatalogName.equals(InternalCatalog.INTERNAL_CATALOG_NAME)) {
- throw new AnalysisException("Cannot alter a catalog into a
build-in name.");
+ if (catalogName.equals(InternalCatalog.INTERNAL_CATALOG_NAME)) {
+ throw new AnalysisException("Internal catalog can't be alter.");
}
- FeNameFormat.checkCommonName("catalog", newCatalogName);
}
- @Override
- public String toSql() {
- return "ALTER CATALOG " + catalogName + " RENAME " + newCatalogName;
+ public String getCatalogName() {
+ return catalogName;
}
}
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/datasource/CatalogFactory.java
b/fe/fe-core/src/main/java/org/apache/doris/datasource/CatalogFactory.java
index 07a03ed8616..d3dd3fa5fbe 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/datasource/CatalogFactory.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/datasource/CatalogFactory.java
@@ -17,6 +17,7 @@
package org.apache.doris.datasource;
+import org.apache.doris.analysis.AlterCatalogCommentStmt;
import org.apache.doris.analysis.AlterCatalogNameStmt;
import org.apache.doris.analysis.AlterCatalogPropertyStmt;
import org.apache.doris.analysis.CreateCatalogStmt;
@@ -55,16 +56,15 @@ public class CatalogFactory {
} else if (stmt instanceof AlterCatalogPropertyStmt) {
log.setCatalogId(catalogId);
log.setNewProps(((AlterCatalogPropertyStmt)
stmt).getNewProperties());
- String newComment = ((AlterCatalogPropertyStmt) stmt).getComment();
- if (!Strings.isNullOrEmpty(newComment)) {
- log.setComment(newComment);
- }
} else if (stmt instanceof AlterCatalogNameStmt) {
log.setCatalogId(catalogId);
log.setNewCatalogName(((AlterCatalogNameStmt)
stmt).getNewCatalogName());
} else if (stmt instanceof RefreshCatalogStmt) {
log.setCatalogId(catalogId);
log.setInvalidCache(((RefreshCatalogStmt) stmt).isInvalidCache());
+ } else if (stmt instanceof AlterCatalogCommentStmt) {
+ log.setCatalogId(catalogId);
+ log.setComment(((AlterCatalogCommentStmt) stmt).getComment());
} else {
throw new RuntimeException("Unknown stmt for catalog manager " +
stmt.getClass().getSimpleName());
}
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/datasource/CatalogIf.java
b/fe/fe-core/src/main/java/org/apache/doris/datasource/CatalogIf.java
index 63718419ae4..e75eab8e216 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/datasource/CatalogIf.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/datasource/CatalogIf.java
@@ -154,6 +154,9 @@ public interface CatalogIf<T extends DatabaseIf> {
String getComment();
+ default void setComment(String comment) {
+ }
+
default long getLastUpdateTime() {
return -1L;
}
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 0dc49e01f75..73a02c1f0b5 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
@@ -17,6 +17,7 @@
package org.apache.doris.datasource;
+import org.apache.doris.analysis.AlterCatalogCommentStmt;
import org.apache.doris.analysis.AlterCatalogNameStmt;
import org.apache.doris.analysis.AlterCatalogPropertyStmt;
import org.apache.doris.analysis.CreateCatalogStmt;
@@ -332,6 +333,24 @@ 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 {
+ writeLock();
+ try {
+ CatalogIf catalog = nameToCatalog.get(stmt.getCatalogName());
+ if (catalog == null) {
+ throw new DdlException("No catalog found with name: " +
stmt.getCatalogName());
+ }
+ CatalogLog log = CatalogFactory.createCatalogLog(catalog.getId(),
stmt);
+ replayAlterCatalogComment(log);
+
Env.getCurrentEnv().getEditLog().logCatalogLog(OperationType.OP_ALTER_CATALOG_COMMENT,
log);
+ } finally {
+ writeUnlock();
+ }
+ }
+
/**
* Modify the catalog property and write the meta log.
*/
@@ -558,6 +577,21 @@ public class CatalogMgr implements Writable,
GsonPostProcessable {
}
}
+ /**
+ * Reply for alter catalog comment event.
+ */
+ public void replayAlterCatalogComment(CatalogLog log) {
+ writeLock();
+ try {
+ CatalogIf catalog = idToCatalog.get(log.getCatalogId());
+ if (catalog != null) {
+ catalog.setComment(log.getComment());
+ }
+ } finally {
+ writeUnlock();
+ }
+ }
+
public List<CatalogIf> listCatalogs() {
return nameToCatalog.values().stream().collect(Collectors.toList());
}
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/datasource/ExternalCatalog.java
b/fe/fe-core/src/main/java/org/apache/doris/datasource/ExternalCatalog.java
index 0e8233bcf22..987ef2614c1 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/datasource/ExternalCatalog.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/datasource/ExternalCatalog.java
@@ -413,7 +413,6 @@ public abstract class ExternalCatalog
@Override
public void modifyCatalogProps(Map<String, String> props) {
- modifyComment(props);
catalogProperty.modifyCatalogProps(props);
notifyPropertiesUpdated(props);
}
@@ -426,11 +425,6 @@ public abstract class ExternalCatalog
catalogProperty.rollBackCatalogProps(props);
}
- private void modifyComment(Map<String, String> props) {
- setComment(props.getOrDefault("comment", comment));
- props.remove("comment");
- }
-
public long getLastUpdateTime() {
return lastUpdateTime;
}
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/journal/JournalEntity.java
b/fe/fe-core/src/main/java/org/apache/doris/journal/JournalEntity.java
index ac933de5442..d47c9f66190 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/journal/JournalEntity.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/journal/JournalEntity.java
@@ -734,6 +734,7 @@ public class JournalEntity implements Writable {
case OperationType.OP_CREATE_CATALOG:
case OperationType.OP_DROP_CATALOG:
case OperationType.OP_ALTER_CATALOG_NAME:
+ case OperationType.OP_ALTER_CATALOG_COMMENT:
case OperationType.OP_ALTER_CATALOG_PROPS:
case OperationType.OP_REFRESH_CATALOG: {
data = CatalogLog.read(in);
diff --git a/fe/fe-core/src/main/java/org/apache/doris/persist/EditLog.java
b/fe/fe-core/src/main/java/org/apache/doris/persist/EditLog.java
index 04b846996ce..a81775e4ec4 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/persist/EditLog.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/persist/EditLog.java
@@ -921,6 +921,11 @@ public class EditLog {
env.getCatalogMgr().replayAlterCatalogName(log);
break;
}
+ case OperationType.OP_ALTER_CATALOG_COMMENT: {
+ CatalogLog log = (CatalogLog) journal.getData();
+ env.getCatalogMgr().replayAlterCatalogComment(log);
+ break;
+ }
case OperationType.OP_ALTER_CATALOG_PROPS: {
CatalogLog log = (CatalogLog) journal.getData();
env.getCatalogMgr().replayAlterCatalogProps(log, null,
true);
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/persist/OperationType.java
b/fe/fe-core/src/main/java/org/apache/doris/persist/OperationType.java
index c2d82bdabe5..db7d7a28a20 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/persist/OperationType.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/persist/OperationType.java
@@ -341,6 +341,8 @@ public class OperationType {
public static final short OP_DELETE_TABLE_STATS = 457;
+ public static final short OP_ALTER_CATALOG_COMMENT = 458;
+
/**
* Get opcode name by op code.
**/
diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/DdlExecutor.java
b/fe/fe-core/src/main/java/org/apache/doris/qe/DdlExecutor.java
index 2af8feda27a..8e62b436b86 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/qe/DdlExecutor.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/qe/DdlExecutor.java
@@ -29,6 +29,7 @@ import org.apache.doris.analysis.AdminSetPartitionVersionStmt;
import org.apache.doris.analysis.AdminSetReplicaStatusStmt;
import org.apache.doris.analysis.AdminSetReplicaVersionStmt;
import org.apache.doris.analysis.AdminSetTableStatusStmt;
+import org.apache.doris.analysis.AlterCatalogCommentStmt;
import org.apache.doris.analysis.AlterCatalogNameStmt;
import org.apache.doris.analysis.AlterCatalogPropertyStmt;
import org.apache.doris.analysis.AlterColocateGroupStmt;
@@ -336,6 +337,8 @@ public class DdlExecutor {
env.getCatalogMgr().dropCatalog((DropCatalogStmt) ddlStmt);
} else if (ddlStmt instanceof AlterCatalogNameStmt) {
env.getCatalogMgr().alterCatalogName((AlterCatalogNameStmt)
ddlStmt);
+ } else if (ddlStmt instanceof AlterCatalogCommentStmt) {
+ env.getCatalogMgr().alterCatalogComment((AlterCatalogCommentStmt)
ddlStmt);
} else if (ddlStmt instanceof AlterCatalogPropertyStmt) {
env.getCatalogMgr().alterCatalogProps((AlterCatalogPropertyStmt)
ddlStmt);
} else if (ddlStmt instanceof CleanLabelStmt) {
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/datasource/CatalogMgrTest.java
b/fe/fe-core/src/test/java/org/apache/doris/datasource/CatalogMgrTest.java
index 09fc1bb1a00..95d1826017d 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/datasource/CatalogMgrTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/datasource/CatalogMgrTest.java
@@ -17,6 +17,7 @@
package org.apache.doris.datasource;
+import org.apache.doris.analysis.AlterCatalogCommentStmt;
import org.apache.doris.analysis.AlterCatalogNameStmt;
import org.apache.doris.analysis.AlterCatalogPropertyStmt;
import org.apache.doris.analysis.CreateCatalogStmt;
@@ -773,6 +774,22 @@ public class CatalogMgrTest extends TestWithFeService {
String alterComment = "ALTER CATALOG hive_c SET PROPERTIES"
+ " (\"comment\" = \"alter comment\");";
mgr.alterCatalogProps((AlterCatalogPropertyStmt)
parseAndAnalyzeStmt(alterComment));
-
Assertions.assertEquals(env.getCatalogMgr().getCatalog("hive_c").getComment(),
"alter comment");
+ // we do not set `comment` auto by `comment in properties`
+ Assertions.assertEquals("create",
env.getCatalogMgr().getCatalog("hive_c").getComment());
+ }
+
+ @Test
+ public void testAlterCatalogComment() throws Exception {
+ ConnectContext rootCtx = createDefaultCtx();
+ CreateCatalogStmt catalogWithComment = (CreateCatalogStmt)
parseAndAnalyzeStmt(
+ "create catalog hive_c1 comment 'create' properties('type' =
'hms', 'hive.metastore.uris' = 'thrift://192.168.0.1:9083');",
+ rootCtx);
+ env.getCatalogMgr().createCatalog(catalogWithComment);
+ Assertions.assertEquals("create",
env.getCatalogMgr().getCatalog("hive_c1").getComment());
+
+ String alterComment = "ALTER CATALOG hive_c1 MODIFY COMMENT
'new_comment';";
+ mgr.alterCatalogComment((AlterCatalogCommentStmt)
parseAndAnalyzeStmt(alterComment));
+ // we do not set `comment` auto by `comment in properties`
+ Assertions.assertEquals("new_comment",
env.getCatalogMgr().getCatalog("hive_c1").getComment());
}
}
diff --git a/regression-test/suites/external_table_p0/test_catalog_ddl.groovy
b/regression-test/suites/external_table_p0/test_catalog_ddl.groovy
new file mode 100644
index 00000000000..b236567e8bd
--- /dev/null
+++ b/regression-test/suites/external_table_p0/test_catalog_ddl.groovy
@@ -0,0 +1,47 @@
+// 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_catalog_ddl", "p0,external,external_docker") {
+ String catalog1 = "test_ddl_ctr1";
+ // This is only for testing catalog ddl syntax
+ sql """drop catalog if exists ${catalog1};"""
+
+ sql """
+ create catalog if not exists ${catalog1} comment 'create_comment'
properties(
+ "type"="es",
+ "hosts"="http://10.10.10.10:8888",
+ "nodes_discovery"="false",
+ "enable_keyword_sniff"="true"
+ );
+ """
+
+ def result = sql """show create catalog ${catalog1};"""
+ assertEquals(result.size(), 1)
+ assertTrue(result[0][1].contains("COMMENT \"create_comment\""))
+
+ // can not update comment by property
+ sql """ALTER CATALOG ${catalog1} SET PROPERTIES ("comment" =
"prop_comment");"""
+ result = sql """show create catalog ${catalog1};"""
+ assertEquals(result.size(), 1)
+ assertTrue(result[0][1].contains("COMMENT \"create_comment\""))
+
+ //update comment
+ sql """ALTER CATALOG ${catalog1} MODIFY COMMENT "alter_comment";"""
+ result = sql """show create catalog ${catalog1};"""
+ assertEquals(result.size(), 1)
+ assertTrue(result[0][1].contains("COMMENT \"alter_comment\""))
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]