morningman commented on a change in pull request #7391:
URL: https://github.com/apache/incubator-doris/pull/7391#discussion_r784607570
##########
File path: fe/fe-core/src/main/java/org/apache/doris/common/FeMetaVersion.java
##########
@@ -222,6 +222,8 @@
public static final int VERSION_104 = 104;
// change replica to replica allocation
public static final int VERSION_105 = 105;
+ // add iceberg database
+ public static final int VERSION_106 = 106;
// note: when increment meta version, should assign the latest version to
VERSION_CURRENT
- public static final int VERSION_CURRENT = VERSION_105;
+ public static final int VERSION_CURRENT = VERSION_106;
Review comment:
Remove this
##########
File path:
fe/fe-core/src/main/java/org/apache/doris/external/iceberg/IcebergTableCreationRecordMgr.java
##########
@@ -0,0 +1,232 @@
+// 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.external.iceberg;
+
+import org.apache.doris.catalog.Catalog;
+import org.apache.doris.catalog.Database;
+import org.apache.doris.catalog.IcebergProperty;
+import org.apache.doris.catalog.IcebergTable;
+import org.apache.doris.common.Config;
+import org.apache.doris.common.ErrorCode;
+import org.apache.doris.common.ErrorReport;
+import org.apache.doris.common.property.PropertySchema;
+import org.apache.doris.common.util.MasterDaemon;
+
+import com.google.common.collect.Maps;
+
+import org.apache.iceberg.catalog.TableIdentifier;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.PriorityQueue;
+import java.util.Queue;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+/**
+ * Manager for Iceberg automatic creation table records
+ * used to create iceberg tables and show table creation records
+ */
+public class IcebergTableCreationRecordMgr extends MasterDaemon {
+ private static final Logger LOG =
LogManager.getLogger(IcebergTableCreationRecordMgr.class);
+
+ private static final String SUCCESS = "success";
+ private static final String FAIL = "fail";
+
+ // database -> table identifier -> properties
+ // used to create table
+ private Map<Database, Map<TableIdentifier, IcebergProperty>>
dbToTableIdentifiers = Maps.newConcurrentMap();
+ // table creation records, used for show stmt
+ // db -> table -> create msg
+ private Map<String, Map<String, IcebergTableCreationRecord>>
dbToTableToCreationRecord = Maps.newConcurrentMap();
+
+ private Queue<IcebergTableCreationRecord> tableCreationRecordQueue = new
PriorityQueue<>(new TableCreationComparator());
+ private ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
+
+
+ public IcebergTableCreationRecordMgr() {
+ super("iceberg_table_creation_record_mgr",
Config.iceberg_table_creation_interval_second * 1000);
+ }
+
+ public void registerTable(Database db, TableIdentifier identifier,
IcebergProperty icebergProperty) {
+ if (dbToTableIdentifiers.containsKey(db)) {
+ dbToTableIdentifiers.get(db).put(identifier, icebergProperty);
+ } else {
+ Map<TableIdentifier, IcebergProperty> identifierToProperties =
Maps.newConcurrentMap();
+ identifierToProperties.put(identifier, icebergProperty);
+ dbToTableIdentifiers.put(db, identifierToProperties);
+ }
+ LOG.info("Register a new table[{}] to database[{}]",
identifier.name(), db.getFullName());
+ }
+
+ public void deregisterdb(Database db) {
Review comment:
```suggestion
public void deregisterDb(Database db) {
```
##########
File path: docs/zh-CN/sql-reference/sql-statements/Data Manipulation/SHOW TABLE
CREATION.md
##########
@@ -0,0 +1,53 @@
+---
+{
+ "title": "SHOW TABLE CREATION",
+ "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 TABLE CREATION
+
+## Description
+
+ 该语句用于展示指定的 Iceberg Database 建表任务的执行情况
+ 语法:
+ SHOW TABLE CREATION [FROM db_name] [LIKE table_name_wild];
+
+ 说明:
+ 1) 如果不指定 db_name,使用当前默认 db
+ 2) 如果使用 LIKE,则会匹配表名中包含 table_name_wild 的建表任务
+
+## example
+
+ 1. 展示默认 Iceberg db 中所有的建表任务
Review comment:
Add an result example to explain the show result
##########
File path:
fe/fe-core/src/main/java/org/apache/doris/external/iceberg/IcebergTableCreationRecordMgr.java
##########
@@ -0,0 +1,232 @@
+// 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.external.iceberg;
+
+import org.apache.doris.catalog.Catalog;
+import org.apache.doris.catalog.Database;
+import org.apache.doris.catalog.IcebergProperty;
+import org.apache.doris.catalog.IcebergTable;
+import org.apache.doris.common.Config;
+import org.apache.doris.common.ErrorCode;
+import org.apache.doris.common.ErrorReport;
+import org.apache.doris.common.property.PropertySchema;
+import org.apache.doris.common.util.MasterDaemon;
+
+import com.google.common.collect.Maps;
+
+import org.apache.iceberg.catalog.TableIdentifier;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.PriorityQueue;
+import java.util.Queue;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+/**
+ * Manager for Iceberg automatic creation table records
+ * used to create iceberg tables and show table creation records
+ */
+public class IcebergTableCreationRecordMgr extends MasterDaemon {
+ private static final Logger LOG =
LogManager.getLogger(IcebergTableCreationRecordMgr.class);
+
+ private static final String SUCCESS = "success";
+ private static final String FAIL = "fail";
+
+ // database -> table identifier -> properties
+ // used to create table
+ private Map<Database, Map<TableIdentifier, IcebergProperty>>
dbToTableIdentifiers = Maps.newConcurrentMap();
+ // table creation records, used for show stmt
+ // db -> table -> create msg
+ private Map<String, Map<String, IcebergTableCreationRecord>>
dbToTableToCreationRecord = Maps.newConcurrentMap();
+
+ private Queue<IcebergTableCreationRecord> tableCreationRecordQueue = new
PriorityQueue<>(new TableCreationComparator());
+ private ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
+
+
+ public IcebergTableCreationRecordMgr() {
+ super("iceberg_table_creation_record_mgr",
Config.iceberg_table_creation_interval_second * 1000);
+ }
+
+ public void registerTable(Database db, TableIdentifier identifier,
IcebergProperty icebergProperty) {
+ if (dbToTableIdentifiers.containsKey(db)) {
+ dbToTableIdentifiers.get(db).put(identifier, icebergProperty);
+ } else {
+ Map<TableIdentifier, IcebergProperty> identifierToProperties =
Maps.newConcurrentMap();
+ identifierToProperties.put(identifier, icebergProperty);
+ dbToTableIdentifiers.put(db, identifierToProperties);
+ }
+ LOG.info("Register a new table[{}] to database[{}]",
identifier.name(), db.getFullName());
+ }
+
+ public void deregisterdb(Database db) {
+ dbToTableIdentifiers.remove(db);
+ dbToTableToCreationRecord.remove(db.getFullName());
+ LOG.info("DeRegister database[{}]", db.getFullName());
+ }
+
+ public void deregisterTable(Database db, IcebergTable table) {
+ if (dbToTableIdentifiers.containsKey(db)) {
+ TableIdentifier identifier =
TableIdentifier.of(table.getIcebergDb(), table.getIcebergTbl());
+ Map<TableIdentifier, IcebergProperty> identifierToProperties =
dbToTableIdentifiers.get(db);
+ identifierToProperties.remove(identifier);
+ }
+ if (dbToTableToCreationRecord.containsKey(db.getFullName())) {
+ Map<String, IcebergTableCreationRecord> recordMap =
dbToTableToCreationRecord.get(db.getFullName());
+ recordMap.remove(table.getName());
+ }
+ LOG.info("DeRegister table[{}] from database[{}]", table.getName(),
db.getFullName());
Review comment:
```suggestion
LOG.info("Deregister table[{}] from database[{}]", table.getName(),
db.getFullName());
```
##########
File path: fe/fe-core/src/main/java/org/apache/doris/catalog/Catalog.java
##########
@@ -2642,16 +2657,24 @@ public void createDb(CreateDbStmt stmt) throws
DdlException {
ErrorReport.reportDdlException(ErrorCode.ERR_DB_CREATE_EXISTS, fullDbName);
}
} else {
- id = getNextId();
- Database db = new Database(id, fullDbName);
- db.setClusterName(clusterName);
unprotectCreateDb(db);
editLog.logCreateDb(db);
}
} finally {
unlock();
}
LOG.info("createDb dbName = " + fullDbName + ", id = " + id);
+
+ // create tables in iceberg database
+ if (db.getDbProperties().getIcebergProperty().isExist()) {
+ IcebergProperty icebergProperty =
db.getDbProperties().getIcebergProperty();
+ IcebergCatalog icebergCatalog =
IcebergCatalogMgr.getCatalog(icebergProperty);
+ List<TableIdentifier> icebergTables =
icebergCatalog.listTables(icebergProperty.getDatabase());
Review comment:
not resolved?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]