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 5768118bfa [Improvement](multi-catalog) add show create catalog stmt
(#14938)
5768118bfa is described below
commit 5768118bfa18cee1bec5749bc299c95bbd5abfb9
Author: Yulei-Yang <[email protected]>
AuthorDate: Fri Dec 9 08:56:55 2022 +0800
[Improvement](multi-catalog) add show create catalog stmt (#14938)
---
.../Create/CREATE-CATALOG.md | 4 +-
.../Show-Statements/SHOW-CREATE-CATALOG.md | 63 ++++++++++++++++
docs/sidebars.json | 1 +
.../Create/CREATE-CATALOG.md | 4 +-
.../Show-Statements/SHOW-CREATE-CATALOG.md | 64 +++++++++++++++++
fe/fe-core/src/main/cup/sql_parser.cup | 4 ++
.../doris/analysis/ShowCreateCatalogStmt.java | 84 ++++++++++++++++++++++
.../org/apache/doris/datasource/CatalogMgr.java | 28 ++++++++
.../java/org/apache/doris/qe/ShowExecutor.java | 11 +++
.../apache/doris/datasource/CatalogMgrTest.java | 27 +++++++
10 files changed, 286 insertions(+), 4 deletions(-)
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 e2669590c6..acf435eb06 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
@@ -54,8 +54,8 @@ CREATE CATALOG [IF NOT EXISTS] catalog_name
CREATE CATALOG hive PROPERTIES (
"type"="hms",
'hive.metastore.uris' = 'thrift://172.21.0.1:7004',
- 'dfs.nameservices'='service1',
- 'dfs.ha.namenodes. service1'='nn1,nn2',
+ 'dfs.nameservices'='HDFS8000871',
+ 'dfs.ha.namenodes.HDFS8000871'='nn1,nn2',
'dfs.namenode.rpc-address.HDFS8000871.nn1'='172.21.0.2:4007',
'dfs.namenode.rpc-address.HDFS8000871.nn2'='172.21.0.3:4007',
'dfs.client.failover.proxy.provider.HDFS8000871'='org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider'
diff --git
a/docs/en/docs/sql-manual/sql-reference/Show-Statements/SHOW-CREATE-CATALOG.md
b/docs/en/docs/sql-manual/sql-reference/Show-Statements/SHOW-CREATE-CATALOG.md
new file mode 100644
index 0000000000..180fbe5112
--- /dev/null
+++
b/docs/en/docs/sql-manual/sql-reference/Show-Statements/SHOW-CREATE-CATALOG.md
@@ -0,0 +1,63 @@
+---
+{
+ "title": "SHOW-CREATE-CATALOG",
+ "language": "zh-CN"
+}
+---
+
+<!--
+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.
+-->
+
+## SHOW-CREATE-CATALOG
+
+### Name
+
+<version since="1.2">
+
+SHOW CREATE CATALOG
+
+</version>
+
+### Description
+
+This statement shows the creating statement of a doris catalog.
+
+grammar:
+
+```sql
+SHOW CREATE CATALOG catalog_name;
+```
+
+illustrate:
+- `catalog_name`: The name of the catalog which exist in doris.
+
+### Example
+
+1. View the creating statement of the hive catalog in doris
+
+ ```sql
+ SHOW CREATE CATALOG hive;
+ ```
+
+### Keywords
+
+ SHOW, CREATE, CATALOG
+
+### Best Practice
+
diff --git a/docs/sidebars.json b/docs/sidebars.json
index b5cce77f2d..a565ef094c 100644
--- a/docs/sidebars.json
+++ b/docs/sidebars.json
@@ -859,6 +859,7 @@
"sql-manual/sql-reference/Show-Statements/SHOW-CATALOGS",
"sql-manual/sql-reference/Show-Statements/SHOW-CREATE-TABLE",
"sql-manual/sql-reference/Show-Statements/SHOW-CHARSET",
+
"sql-manual/sql-reference/Show-Statements/SHOW-CREATE-CATALOG",
"sql-manual/sql-reference/Show-Statements/SHOW-CREATE-DATABASE",
"sql-manual/sql-reference/Show-Statements/SHOW-CREATE-MATERIALIZED-VIEW",
"sql-manual/sql-reference/Show-Statements/SHOW-CREATE-ROUTINE-LOAD",
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 dd8af3a7e9..5e9ccb09dc 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
@@ -58,8 +58,8 @@ CREATE CATALOG [IF NOT EXISTS] catalog_name
CREATE CATALOG hive PROPERTIES (
"type"="hms",
'hive.metastore.uris' = 'thrift://172.21.0.1:7004',
- 'dfs.nameservices'='service1',
- 'dfs.ha.namenodes. service1'='nn1,nn2',
+ 'dfs.nameservices'='HDFS8000871',
+ 'dfs.ha.namenodes.HDFS8000871'='nn1,nn2',
'dfs.namenode.rpc-address.HDFS8000871.nn1'='172.21.0.2:4007',
'dfs.namenode.rpc-address.HDFS8000871.nn2'='172.21.0.3:4007',
'dfs.client.failover.proxy.provider.HDFS8000871'='org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider'
diff --git
a/docs/zh-CN/docs/sql-manual/sql-reference/Show-Statements/SHOW-CREATE-CATALOG.md
b/docs/zh-CN/docs/sql-manual/sql-reference/Show-Statements/SHOW-CREATE-CATALOG.md
new file mode 100644
index 0000000000..b72ca20be3
--- /dev/null
+++
b/docs/zh-CN/docs/sql-manual/sql-reference/Show-Statements/SHOW-CREATE-CATALOG.md
@@ -0,0 +1,64 @@
+---
+{
+ "title": "SHOW-CREATE-CATALOG",
+ "language": "zh-CN"
+}
+---
+
+<!--
+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.
+-->
+
+## SHOW-CREATE-CATALOG
+
+### Name
+
+<version since="1.2">
+
+SHOW CREATE CATALOG
+
+</version>
+
+### Description
+
+该语句查看doris数据目录的创建语句。
+
+语法:
+
+```sql
+SHOW CREATE CATALOG catalog_name;
+```
+
+说明:
+
+- `catalog_name`: 为doris中存在的数据目录的名称。
+
+### Example
+
+1. 查看doris中hive数据目录的创建语句
+
+ ```sql
+ SHOW CREATE CATALOG hive;
+ ```
+
+### Keywords
+
+ SHOW, CREATE, CATALOG
+
+### Best Practice
+
diff --git a/fe/fe-core/src/main/cup/sql_parser.cup
b/fe/fe-core/src/main/cup/sql_parser.cup
index 8fb5b854da..ab637b3a65 100644
--- a/fe/fe-core/src/main/cup/sql_parser.cup
+++ b/fe/fe-core/src/main/cup/sql_parser.cup
@@ -3415,6 +3415,10 @@ show_param ::=
{:
RESULT = new ShowCreateDbStmt(db);
:}
+ | KW_CREATE KW_CATALOG ident:catalogName
+ {:
+ RESULT = new ShowCreateCatalogStmt(catalogName);
+ :}
/* Create Function */
| KW_CREATE KW_FUNCTION function_name:functionName LPAREN
func_args_def:args RPAREN opt_db:dbName
{:
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowCreateCatalogStmt.java
b/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowCreateCatalogStmt.java
new file mode 100644
index 0000000000..8e32289e10
--- /dev/null
+++
b/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowCreateCatalogStmt.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.analysis;
+
+import org.apache.doris.catalog.Column;
+import org.apache.doris.catalog.Env;
+import org.apache.doris.catalog.ScalarType;
+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.Util;
+import org.apache.doris.mysql.privilege.PrivPredicate;
+import org.apache.doris.qe.ConnectContext;
+import org.apache.doris.qe.ShowResultSetMetaData;
+
+import com.google.common.base.Strings;
+
+// Show create catalog statement
+// Syntax:
+// SHOW CREATE CATALOG catalogName
+public class ShowCreateCatalogStmt extends ShowStmt {
+ private static final ShowResultSetMetaData META_DATA =
+ ShowResultSetMetaData.builder()
+ .addColumn(new Column("Catalog",
ScalarType.createVarchar(20)))
+ .addColumn(new Column("Create Catalog",
ScalarType.createVarchar(30)))
+ .build();
+
+ private String catalog;
+
+ public ShowCreateCatalogStmt(String catalog) {
+ this.catalog = catalog;
+ }
+
+ public String getCatalog() {
+ return catalog;
+ }
+
+ @Override
+ public void analyze(Analyzer analyzer) throws AnalysisException,
UserException {
+ Util.checkCatalogEnabled();
+
+ super.analyze(analyzer);
+ if (Strings.isNullOrEmpty(catalog)) {
+
ErrorReport.reportAnalysisException(ErrorCode.ERR_WRONG_CATALOG_NAME, catalog);
+ }
+
+ if (!Env.getCurrentEnv().getAuth()
+ .checkCtlPriv(ConnectContext.get(), catalog,
PrivPredicate.SHOW)) {
+
ErrorReport.reportAnalysisException(ErrorCode.ERR_CATALOG_ACCESS_DENIED,
+ ConnectContext.get().getQualifiedUser(), catalog);
+ }
+ }
+
+ @Override
+ public String toSql() {
+ return "SHOW CREATE CATALOG `" + catalog + "`";
+ }
+
+ @Override
+ public String toString() {
+ return toSql();
+ }
+
+ @Override
+ public ShowResultSetMetaData getMetaData() {
+ return META_DATA;
+ }
+}
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 244aff98d8..45bbab0e4e 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
@@ -23,10 +23,12 @@ import org.apache.doris.analysis.CreateCatalogStmt;
import org.apache.doris.analysis.DropCatalogStmt;
import org.apache.doris.analysis.RefreshCatalogStmt;
import org.apache.doris.analysis.ShowCatalogStmt;
+import org.apache.doris.analysis.ShowCreateCatalogStmt;
import org.apache.doris.catalog.DatabaseIf;
import org.apache.doris.catalog.Env;
import org.apache.doris.catalog.external.ExternalDatabase;
import org.apache.doris.catalog.external.ExternalTable;
+import org.apache.doris.cluster.ClusterNamespace;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.CaseSensibility;
import org.apache.doris.common.DdlException;
@@ -36,6 +38,7 @@ import org.apache.doris.common.PatternMatcher;
import org.apache.doris.common.UserException;
import org.apache.doris.common.io.Text;
import org.apache.doris.common.io.Writable;
+import org.apache.doris.common.util.PrintableMap;
import org.apache.doris.mysql.privilege.PrivPredicate;
import org.apache.doris.persist.OperationType;
import org.apache.doris.persist.gson.GsonPostProcessable;
@@ -382,6 +385,31 @@ public class CatalogMgr implements Writable,
GsonPostProcessable {
return new ShowResultSet(showStmt.getMetaData(), rows);
}
+ public ShowResultSet showCreateCatalog(ShowCreateCatalogStmt showStmt)
throws AnalysisException {
+ List<List<String>> rows = Lists.newArrayList();
+ readLock();
+ try {
+ CatalogIf catalog = nameToCatalog.get(showStmt.getCatalog());
+ if (catalog == null) {
+ throw new AnalysisException("No catalog found with name " +
showStmt.getCatalog());
+ }
+ StringBuilder sb = new StringBuilder();
+ sb.append("CREATE CATALOG
`").append(ClusterNamespace.getNameFromFullName(showStmt.getCatalog()))
+ .append("`");
+ if (catalog.getProperties().size() > 0) {
+ sb.append(" PROPERTIES (\n");
+ sb.append(new PrintableMap<>(catalog.getProperties(), "=",
true, true, false));
+ sb.append("\n);");
+ }
+
+
rows.add(Lists.newArrayList(ClusterNamespace.getNameFromFullName(showStmt.getCatalog()),
sb.toString()));
+ } finally {
+ readUnlock();
+ }
+
+ return new ShowResultSet(showStmt.getMetaData(), rows);
+ }
+
/**
* Refresh the catalog meta and write the meta log.
*/
diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/ShowExecutor.java
b/fe/fe-core/src/main/java/org/apache/doris/qe/ShowExecutor.java
index 0eb3656f08..408c6c2891 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/qe/ShowExecutor.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/qe/ShowExecutor.java
@@ -38,6 +38,7 @@ import org.apache.doris.analysis.ShowClusterStmt;
import org.apache.doris.analysis.ShowCollationStmt;
import org.apache.doris.analysis.ShowColumnStatsStmt;
import org.apache.doris.analysis.ShowColumnStmt;
+import org.apache.doris.analysis.ShowCreateCatalogStmt;
import org.apache.doris.analysis.ShowCreateDbStmt;
import org.apache.doris.analysis.ShowCreateFunctionStmt;
import org.apache.doris.analysis.ShowCreateMaterializedViewStmt;
@@ -374,6 +375,8 @@ public class ShowExecutor {
handleShowPolicy();
} else if (stmt instanceof ShowCatalogStmt) {
handleShowCatalogs();
+ } else if (stmt instanceof ShowCreateCatalogStmt) {
+ handleShowCreateCatalog();
} else if (stmt instanceof ShowAnalyzeStmt) {
handleShowAnalyze();
} else if (stmt instanceof AdminCopyTabletStmt) {
@@ -2302,6 +2305,14 @@ public class ShowExecutor {
resultSet = Env.getCurrentEnv().getCatalogMgr().showCatalogs(showStmt,
ctx.getCurrentCatalog().getName());
}
+ // Show create catalog
+ private void handleShowCreateCatalog() throws AnalysisException {
+ ShowCreateCatalogStmt showStmt = (ShowCreateCatalogStmt) stmt;
+
+ resultSet =
Env.getCurrentEnv().getCatalogMgr().showCreateCatalog(showStmt);
+ }
+
+
private void handleShowAnalyze() throws AnalysisException {
// TODO: Support later
}
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 cf1305b102..1cc7928e87 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
@@ -25,6 +25,7 @@ import org.apache.doris.analysis.CreateUserStmt;
import org.apache.doris.analysis.DropCatalogStmt;
import org.apache.doris.analysis.GrantStmt;
import org.apache.doris.analysis.ShowCatalogStmt;
+import org.apache.doris.analysis.ShowCreateCatalogStmt;
import org.apache.doris.analysis.SwitchStmt;
import org.apache.doris.analysis.UserIdentity;
import org.apache.doris.catalog.Column;
@@ -217,6 +218,15 @@ public class CatalogMgrTest extends TestWithFeService {
}
}
+ String showCreateCatalog = "SHOW CREATE CATALOG my_catalog";
+ ShowCreateCatalogStmt showCreateStmt = (ShowCreateCatalogStmt)
parseAndAnalyzeStmt(showCreateCatalog);
+ showResultSet = mgr.showCreateCatalog(showCreateStmt);
+
+ Assert.assertEquals(1, showResultSet.getResultRows().size());
+ List<String> result = showResultSet.getResultRows().get(0);
+ Assertions.assertEquals("my_catalog", result.get(0));
+ Assertions.assertTrue(result.get(1).startsWith("CREATE CATALOG
`my_catalog` PROPERTIES ("));
+
testCatalogMgrPersist();
String dropCatalogSql = "DROP CATALOG " + MY_CATALOG;
@@ -358,6 +368,23 @@ public class CatalogMgrTest extends TestWithFeService {
Assert.assertEquals(e.getMessage(),
"errCode = 2, detailMessage = Access denied for user
'default_cluster:user2' to catalog 'iceberg'");
}
+
+ //test show create catalog: have permission to hive, have no
permission to iceberg;
+ ShowCreateCatalogStmt user2ShowCreateHive = (ShowCreateCatalogStmt)
parseAndAnalyzeStmt(
+ "show create catalog hive;", user2Ctx);
+ List<List<String>> user2ShowCreateHiveResult =
env.getCatalogMgr().showCreateCatalog(user2ShowCreateHive)
+ .getResultRows();
+ Assert.assertTrue(
+ user2ShowCreateHiveResult.stream().map(l ->
l.get(0)).anyMatch(c -> c.equals("hive")));
+ try {
+ env.getCatalogMgr()
+ .showCreateCatalog(
+ (ShowCreateCatalogStmt) parseAndAnalyzeStmt("show
create catalog iceberg;", user2Ctx));
+ Assert.fail("");
+ } catch (AnalysisException e) {
+ Assert.assertEquals(e.getMessage(),
+ "errCode = 2, detailMessage = Access denied for user
'default_cluster:user2' to catalog 'iceberg'");
+ }
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]