This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-2.1
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.1 by this push:
new 28ce116b172 [improvement](iceberg)add some description for show create
for 2.1 #39179 (#39644)
28ce116b172 is described below
commit 28ce116b17246ac825fffa89d462bd835f63c883
Author: wuwenchi <[email protected]>
AuthorDate: Wed Aug 21 09:18:38 2024 +0800
[improvement](iceberg)add some description for show create for 2.1 #39179
(#39644)
## Proposed changes
bp: #39179
1. add `location` and `properties` for `show create table`.
2. add `location` for `show create database`.
---
.../main/java/org/apache/doris/catalog/Env.java | 18 +++++-
.../java/org/apache/doris/catalog/TableIf.java | 3 +-
.../iceberg/IcebergExternalDatabase.java | 11 ++++
.../java/org/apache/doris/qe/ShowExecutor.java | 8 +++
.../iceberg/test_iceberg_show_create.groovy | 73 ++++++++++++++++++++++
5 files changed, 111 insertions(+), 2 deletions(-)
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 f5e41a1bf1c..73e1218bd73 100755
--- 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
@@ -138,6 +138,7 @@ import org.apache.doris.datasource.es.EsExternalCatalog;
import org.apache.doris.datasource.es.EsRepository;
import org.apache.doris.datasource.hive.HiveTransactionMgr;
import org.apache.doris.datasource.hive.event.MetastoreEventsProcessor;
+import org.apache.doris.datasource.iceberg.IcebergExternalTable;
import org.apache.doris.deploy.DeployManager;
import org.apache.doris.deploy.impl.AmbariDeployManager;
import org.apache.doris.deploy.impl.K8sDeployManager;
@@ -311,6 +312,7 @@ import java.util.Collection;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@@ -3764,6 +3766,20 @@ public class Env {
sb.append("\"table\" =
\"").append(jdbcTable.getJdbcTable()).append("\",\n");
sb.append("\"table_type\" =
\"").append(jdbcTable.getJdbcTypeName()).append("\"");
sb.append("\n)");
+ } else if (table.getType() == TableType.ICEBERG_EXTERNAL_TABLE) {
+ addTableComment(table, sb);
+ org.apache.iceberg.Table icebergTable = ((IcebergExternalTable)
table).getIcebergTable();
+ sb.append("\nLOCATION
'").append(icebergTable.location()).append("'");
+ sb.append("\nPROPERTIES (");
+ Iterator<Entry<String, String>> iterator =
icebergTable.properties().entrySet().iterator();
+ while (iterator.hasNext()) {
+ Entry<String, String> prop = iterator.next();
+ sb.append("\n \"").append(prop.getKey()).append("\" =
\"").append(prop.getValue()).append("\"");
+ if (iterator.hasNext()) {
+ sb.append(",");
+ }
+ }
+ sb.append("\n)");
}
createTableStmt.add(sb + ";");
@@ -6186,7 +6202,7 @@ public class Env {
AgentTaskExecutor.submit(batchTask);
}
- private static void addTableComment(Table table, StringBuilder sb) {
+ private static void addTableComment(TableIf table, StringBuilder sb) {
if (StringUtils.isNotBlank(table.getComment())) {
sb.append("\nCOMMENT
'").append(table.getComment(true)).append("'");
}
diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/TableIf.java
b/fe/fe-core/src/main/java/org/apache/doris/catalog/TableIf.java
index a3535c739cf..be8f1fe6f94 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/catalog/TableIf.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/TableIf.java
@@ -427,7 +427,8 @@ public interface TableIf {
* Doris table type.
*/
enum TableType {
- MYSQL, ODBC, OLAP, SCHEMA, INLINE_VIEW, VIEW, BROKER, ELASTICSEARCH,
HIVE, ICEBERG, @Deprecated HUDI, JDBC,
+ MYSQL, ODBC, OLAP, SCHEMA, INLINE_VIEW, VIEW, BROKER, ELASTICSEARCH,
HIVE,
+ @Deprecated ICEBERG, @Deprecated HUDI, JDBC,
TABLE_VALUED_FUNCTION, HMS_EXTERNAL_TABLE, ES_EXTERNAL_TABLE,
MATERIALIZED_VIEW, JDBC_EXTERNAL_TABLE,
ICEBERG_EXTERNAL_TABLE, TEST_EXTERNAL_TABLE, PAIMON_EXTERNAL_TABLE,
MAX_COMPUTE_EXTERNAL_TABLE,
HUDI_EXTERNAL_TABLE;
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/datasource/iceberg/IcebergExternalDatabase.java
b/fe/fe-core/src/main/java/org/apache/doris/datasource/iceberg/IcebergExternalDatabase.java
index 16ac6b01d40..f56183972e3 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/datasource/iceberg/IcebergExternalDatabase.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/datasource/iceberg/IcebergExternalDatabase.java
@@ -21,6 +21,11 @@ import org.apache.doris.datasource.ExternalCatalog;
import org.apache.doris.datasource.ExternalDatabase;
import org.apache.doris.datasource.InitDatabaseLog;
+import org.apache.iceberg.catalog.Namespace;
+import org.apache.iceberg.catalog.SupportsNamespaces;
+
+import java.util.Map;
+
public class IcebergExternalDatabase extends
ExternalDatabase<IcebergExternalTable> {
public IcebergExternalDatabase(ExternalCatalog extCatalog, Long id, String
name) {
@@ -31,4 +36,10 @@ public class IcebergExternalDatabase extends
ExternalDatabase<IcebergExternalTab
protected IcebergExternalTable buildTableForInit(String tableName, long
tblId, ExternalCatalog catalog) {
return new IcebergExternalTable(tblId, tableName, name,
(IcebergExternalCatalog) extCatalog);
}
+
+ public String getLocation() {
+ Map<String, String> props = ((SupportsNamespaces)
((IcebergExternalCatalog) getCatalog()).getCatalog())
+ .loadNamespaceMetadata(Namespace.of(name));
+ return props.getOrDefault("location", "");
+ }
}
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 5529f3a6a9f..f8d73108b17 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
@@ -184,6 +184,8 @@ import org.apache.doris.datasource.InternalCatalog;
import org.apache.doris.datasource.hive.HMSExternalCatalog;
import org.apache.doris.datasource.hive.HMSExternalTable;
import org.apache.doris.datasource.hive.HiveMetaStoreClientHelper;
+import org.apache.doris.datasource.iceberg.IcebergExternalCatalog;
+import org.apache.doris.datasource.iceberg.IcebergExternalDatabase;
import org.apache.doris.datasource.maxcompute.MaxComputeExternalCatalog;
import org.apache.doris.job.manager.JobManager;
import org.apache.doris.load.DeleteHandler;
@@ -1008,6 +1010,12 @@ public class ShowExecutor {
.append(" LOCATION '")
.append(db.getLocationUri())
.append("'");
+ } else if (catalog instanceof IcebergExternalCatalog) {
+ IcebergExternalDatabase db = (IcebergExternalDatabase)
catalog.getDbOrAnalysisException(showStmt.getDb());
+ sb.append("CREATE DATABASE `").append(showStmt.getDb()).append("`")
+ .append(" LOCATION '")
+ .append(db.getLocation())
+ .append("'");
} else {
DatabaseIf db = catalog.getDbOrAnalysisException(showStmt.getDb());
sb.append("CREATE DATABASE
`").append(ClusterNamespace.getNameFromFullName(showStmt.getDb())).append("`");
diff --git
a/regression-test/suites/external_table_p0/iceberg/test_iceberg_show_create.groovy
b/regression-test/suites/external_table_p0/iceberg/test_iceberg_show_create.groovy
new file mode 100644
index 00000000000..8065998fa71
--- /dev/null
+++
b/regression-test/suites/external_table_p0/iceberg/test_iceberg_show_create.groovy
@@ -0,0 +1,73 @@
+// 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_iceberg_show_create",
"p0,external,doris,external_docker,external_docker_doris") {
+ String enabled = context.config.otherConfigs.get("enableIcebergTest")
+ if (enabled == null || !enabled.equalsIgnoreCase("true")) {
+ logger.info("disable iceberg test.")
+ return
+ }
+
+ String rest_port = context.config.otherConfigs.get("iceberg_rest_uri_port")
+ String minio_port = context.config.otherConfigs.get("iceberg_minio_port")
+ String externalEnvIp = context.config.otherConfigs.get("externalEnvIp")
+ String catalog_name = "test_iceberg_show_create"
+
+ sql """drop catalog if exists ${catalog_name}"""
+ sql """
+ CREATE CATALOG ${catalog_name} PROPERTIES (
+ 'type'='iceberg',
+ 'iceberg.catalog.type'='rest',
+ 'uri' = 'http://${externalEnvIp}:${rest_port}',
+ "s3.access_key" = "admin",
+ "s3.secret_key" = "password",
+ "s3.endpoint" = "http://${externalEnvIp}:${minio_port}",
+ "s3.region" = "us-east-1"
+ );"""
+
+ sql """ switch ${catalog_name} """
+
+ String db1 = "test_db1"
+ String db2 = "test_db2"
+ String tb1 = "test_tb1"
+
+ sql """ drop table if exists ${db1}.${tb1} """
+ sql """ drop database if exists ${db1} """
+ sql """ drop database if exists ${db2} """
+
+ sql """ create database ${db1} properties
('location'='s3a://warehouse/wh/${db1}') """
+ sql """ create database ${db2} """
+
+ String result = ""
+ result = sql "show create database ${db1}"
+ logger.info("${result}")
+
assertTrue(result.toString().containsIgnoreCase("s3a://warehouse/wh/${db1}"))
+
+ result = sql "show create database ${db2}"
+ logger.info("${result}")
+
assertTrue(result.toString().containsIgnoreCase("s3a://warehouse/wh/${db2}"))
+
+ sql """ create table ${db1}.${tb1} (id int) """
+ result = sql "show create table ${db1}.${tb1}"
+ logger.info("${result}")
+
assertTrue(result.toString().containsIgnoreCase("s3a://warehouse/wh/${db1}/${tb1}"))
+
+ sql """ drop table ${db1}.${tb1} """
+ sql """ drop database ${db1} """
+ sql """ drop database ${db2} """
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]