[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`.
This commit is contained in:
wuwenchi
2024-08-21 09:18:38 +08:00
committed by GitHub
parent 27ba2542e2
commit 28ce116b17
5 changed files with 111 additions and 2 deletions

View File

@ -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("'");
}

View File

@ -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;

View File

@ -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", "");
}
}

View File

@ -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("`");