You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by GitBox <gi...@apache.org> on 2021/12/14 06:03:42 UTC
[GitHub] [incubator-doris] qidaye opened a new pull request #7391: [Iceberg] Support create Iceberg external table
qidaye opened a new pull request #7391:
URL: https://github.com/apache/incubator-doris/pull/7391
## Proposed changes
Close related #7389
Support create Iceberg external table in Doris.
This is the first step to support Iceberg external table.
### Create Iceberg external table
This pr describes two ways to create Iceberg external tables. Both ways do not require explicitly specifying column definitions, Doris automatically converts them based on Iceberg's column definitions.
1. Create an Iceberg external table directly
```sql
CREATE [EXTERNAL] TABLE table_name
ENGINE = ICEBERG
[COMMENT "comment"]
PROPERTIES (
"database" = "iceberg_db_name",
"table" = "icberg_table_name",
"hive.metastore.uris" = "thrift://192.168.0.1:9083",
"catalog.type" = "HIVE_CATALOG"
);
```
2. Create an Iceberg database and automatically create all the tables under that db.
```sql
CREATE DATABASE db_name
ENGINE = ICEBERG
[COMMENT "comment"]
PROPERTIES (
"database" = "iceberg_db_name",
"hive.metastore.uris" = "thrift://192.168.0.1:9083",
"catalog.type" = "HIVE_CATALOG"
);
```
### Show table creation
1. For individual tables you can view them with `help show create table`.
```sql
mysql> show create table iceberg_db.logs_1;
+--------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+--------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| logs_1 | CREATE TABLE `logs_1` (
`level` varchar(-1) NOT NULL COMMENT "null",
`event_time` datetime NOT NULL COMMENT "null",
`message` varchar(-1) NOT NULL COMMENT "null"
) ENGINE=ICEBERG
COMMENT "ICEBERG"
PROPERTIES (
"database" = "doris",
"table" = "logs_1",
"hive.metastore.uris" = "thrift://10.10.10.10:9087",
"catalog.type" = "HIVE_CATALOG"
) |
+--------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
```
2. For Iceberg database, you can view it with `help show table creation`.
```sql
mysql> show table creation from iceberg_db;
+--------+---------+---------------------+---------------------------------------------------------+
| Table | Status | Create Time | Error Msg |
+--------+---------+---------------------+---------------------------------------------------------+
| logs | fail | 2021-12-14 13:50:10 | Cannot convert unknown type to Doris type: list<string> |
| logs_1 | success | 2021-12-14 13:50:10 | |
+--------+---------+---------------------+---------------------------------------------------------+
2 rows in set (0.00 sec)
```
This is a new syntax.
Show table creation records in Iceberg database:
Syntax:
```sql
SHOW TABLE CREATION [FROM db] [LIKE mask]
```
## Types of changes
What types of changes does your code introduce to Doris?
_Put an `x` in the boxes that apply_
- [ ] Bugfix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] Documentation Update (if none of the other choices apply)
- [ ] Code refactor (Modify the code structure, format the code, etc...)
- [ ] Optimization. Including functional usability improvements and performance improvements.
- [ ] Dependency. Such as changes related to third-party components.
- [ ] Other.
## Checklist
_Put an `x` in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code._
- [x] I have created an issue on (Fix #ISSUE) and described the bug/feature there in detail
- [x] Compiling and unit tests pass locally with my changes
- [x] I have added tests that prove my fix is effective or that my feature works
- [x] If these changes need document changes, I have updated the document
- [ ] Any dependent changes have been merged
## Further comments
If this is a relatively large or complex change, kick off the discussion at dev@doris.apache.org by explaining why you chose the solution you did and what alternatives you considered, etc...
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
[GitHub] [incubator-doris] qidaye commented on a change in pull request #7391: [feature-wip](iceberg) Step1: Support create Iceberg external table
Posted by GitBox <gi...@apache.org>.
qidaye commented on a change in pull request #7391:
URL: https://github.com/apache/incubator-doris/pull/7391#discussion_r784675617
##########
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:
Added a new `DorisIcebergException` which is a `RuntimeException` in `IcebergCatalog.listTable`.
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
[GitHub] [incubator-doris] morningman merged pull request #7391: [feature-wip](iceberg) Step1: Support create Iceberg external table
Posted by GitBox <gi...@apache.org>.
morningman merged pull request #7391:
URL: https://github.com/apache/incubator-doris/pull/7391
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
[GitHub] [incubator-doris] morningman commented on a change in pull request #7391: [feature-wip](iceberg) Step1: Support create Iceberg external table
Posted by GitBox <gi...@apache.org>.
morningman commented on a change in pull request #7391:
URL: https://github.com/apache/incubator-doris/pull/7391#discussion_r777271525
##########
File path: fe/fe-core/src/main/java/org/apache/doris/catalog/Catalog.java
##########
@@ -4615,6 +4656,9 @@ public boolean unprotectDropTable(Database db, Table table, boolean isForceDrop,
// drop all temp partitions of this table, so that there is no temp partitions in recycle bin,
// which make things easier.
((OlapTable) table).dropAllTempPartitions();
+ } else if (table.getType() == TableType.ICEBERG) {
+ // drop Iceberg database table creation record
+ icebergTableCreationRecordMgr.deRegisterTable(db, (IcebergTable) table);
Review comment:
```suggestion
icebergTableCreationRecordMgr.deregisterTable(db, (IcebergTable) table);
```
##########
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:
What if the `listTables` throw exception?
##########
File path: fe/fe-core/src/main/java/org/apache/doris/external/iceberg/IcebergTableCreationRecordMgr.java
##########
@@ -0,0 +1,229 @@
+// 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());
+ }
+
+ // remove already created tables or failed tables
+ private void removeDuplicateTables() {
+ for (Map.Entry<String, Map<String, IcebergTableCreationRecord>> entry : dbToTableToCreationRecord.entrySet()) {
+ String dbName = entry.getKey();
+ Catalog.getCurrentCatalog().getDb(dbName).ifPresent(db -> {
+ if (dbToTableIdentifiers.containsKey(db)) {
+ for (Map.Entry<String, IcebergTableCreationRecord> innerEntry : entry.getValue().entrySet()) {
+ String tableName = innerEntry.getKey();
+ String icebergDbName = db.getDbProperties().getIcebergProperty().getDatabase();
+ TableIdentifier identifier = TableIdentifier.of(icebergDbName, tableName);
+ dbToTableIdentifiers.get(db).remove(identifier);
+ }
+ }
+ });
+ }
+ }
+
+ @Override
+ protected void runAfterCatalogReady() {
+ PropertySchema.DateProperty prop =
+ new PropertySchema.DateProperty("key", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
+ for (Map.Entry<Database, Map<TableIdentifier, IcebergProperty>> entry : dbToTableIdentifiers.entrySet()) {
+ Database db = entry.getKey();
+ for (Map.Entry<TableIdentifier, IcebergProperty> innerEntry : entry.getValue().entrySet()) {
+ TableIdentifier identifier = innerEntry.getKey();
+ IcebergProperty icebergProperty = innerEntry.getValue();
+ try {
+ // get doris table from iceberg
+ IcebergTable table = IcebergCatalogMgr.getTableFromIceberg(identifier.name(),
+ icebergProperty, identifier, false);
+ // check iceberg table if exists in doris database
+ if (!db.createTableWithLock(table, false, false).first) {
+ ErrorReport.reportDdlException(ErrorCode.ERR_CANT_CREATE_TABLE,
+ table.getName(), ErrorCode.ERR_TABLE_EXISTS_ERROR.getCode());
+ }
+ addTableCreationRecord(db.getFullName(), table.getName(), SUCCESS,
+ prop.writeTimeFormat(new Date(System.currentTimeMillis())), "");
+ LOG.info("Successfully create table[{}-{}]", table.getName(), table.getId());
+ } catch (Exception e) {
+ addTableCreationRecord(db.getFullName(), identifier.name(), FAIL,
+ prop.writeTimeFormat(new Date(System.currentTimeMillis())), e.getMessage());
+ LOG.warn("Failed create table[{}], error: {}", identifier.name(), e.getMessage());
+ }
+ }
+ }
+ removeDuplicateTables();
+ }
+
+ private void addTableCreationRecord(String db, String table, String status, String createTime, String errorMsg) {
+ writeLock();
Review comment:
Use `try...finally` to wrap the lock
##########
File path: fe/fe-core/src/main/java/org/apache/doris/external/iceberg/IcebergTableCreationRecordMgr.java
##########
@@ -0,0 +1,229 @@
+// 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) {
```
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
[GitHub] [incubator-doris] github-actions[bot] commented on pull request #7391: [feature-wip](iceberg) Step1: Support create Iceberg external table
Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #7391:
URL: https://github.com/apache/incubator-doris/pull/7391#issuecomment-1021945487
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
[GitHub] [incubator-doris] qidaye commented on a change in pull request #7391: [feature-wip](iceberg) Step1: Support create Iceberg external table
Posted by GitBox <gi...@apache.org>.
qidaye commented on a change in pull request #7391:
URL: https://github.com/apache/incubator-doris/pull/7391#discussion_r790683010
##########
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:
Done
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
[GitHub] [incubator-doris] qidaye commented on a change in pull request #7391: [feature-wip](iceberg) Step1: Support create Iceberg external table
Posted by GitBox <gi...@apache.org>.
qidaye commented on a change in pull request #7391:
URL: https://github.com/apache/incubator-doris/pull/7391#discussion_r790684350
##########
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:
Done
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
[GitHub] [incubator-doris] morningman commented on a change in pull request #7391: [Iceberg] Support create Iceberg external table
Posted by GitBox <gi...@apache.org>.
morningman commented on a change in pull request #7391:
URL: https://github.com/apache/incubator-doris/pull/7391#discussion_r775030951
##########
File path: fe/fe-core/src/main/java/org/apache/doris/analysis/CreateTableStmt.java
##########
@@ -167,6 +168,21 @@ public CreateTableStmt(boolean ifNotExists,
this.rollupAlterClauseList = rollupAlterClauseList == null ? new ArrayList<>() : rollupAlterClauseList;
}
+ public CreateTableStmt(boolean ifNotExists,
Review comment:
Add comment to explain what this construction method for :
```
// This is for iceberg table, which has no column schema
```
##########
File path: fe/fe-core/src/main/java/org/apache/doris/catalog/Catalog.java
##########
@@ -4072,6 +4121,62 @@ private void createHiveTable(Database db, CreateTableStmt stmt) throws DdlExcept
LOG.info("successfully create table[{}-{}]", tableName, tableId);
}
+ /**
+ * create iceberg table in Doris
+ *
+ * 1. check table existence in Iceberg
+ * 2. get table schema from Iceberg
+ * 3. convert Iceberg table schema to Doris table schema
+ * 4. create associate table in Doris
+ *
+ * @param db
+ * @param stmt
+ * @throws DdlException
+ */
+ private void createIcebergTable(Database db, CreateTableStmt stmt) throws DdlException {
Review comment:
Move all iceberg related method to a new class.
##########
File path: fe/fe-core/src/main/java/org/apache/doris/analysis/CreateDbStmt.java
##########
@@ -24,19 +24,37 @@
import org.apache.doris.common.ErrorReport;
import org.apache.doris.common.FeNameFormat;
import org.apache.doris.common.UserException;
+import org.apache.doris.common.util.PrintableMap;
import org.apache.doris.mysql.privilege.PrivPredicate;
import org.apache.doris.qe.ConnectContext;
import com.google.common.base.Strings;
+import com.google.common.collect.Sets;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
// 用于描述CREATE DATABASE的内部结构
public class CreateDbStmt extends DdlStmt {
private boolean ifNotExists;
private String dbName;
+ private String engineName;
+ private Map<String, String> properties;
+
+ private static Set<String> engineNames;
Review comment:
```suggestion
private static final Set<String> ENGINE_NAMES;
```
##########
File path: fe/fe-core/src/main/java/org/apache/doris/catalog/IcebergDatabase.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.catalog;
+
+import org.apache.doris.common.io.Text;
+import org.apache.doris.external.iceberg.IcebergCatalogMgr;
+
+import com.google.common.collect.Maps;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.util.Map;
+
+/**
+ * Internal represent Iceberg database in Doris
+ */
+public class IcebergDatabase extends Database {
+ private static final Logger LOG = LogManager.getLogger(IcebergDatabase.class);
+
+ private String icebergDb;
+ private Map<String, String> dbProperties = Maps.newHashMap();
Review comment:
I think `dbProperties` can be a common fields of `Database`?
So we don't need to use a derived class.
##########
File path: fe/fe-core/src/main/java/org/apache/doris/catalog/Catalog.java
##########
@@ -2652,6 +2668,32 @@ public void createDb(CreateDbStmt stmt) throws DdlException {
unlock();
}
LOG.info("createDb dbName = " + fullDbName + ", id = " + id);
+
+ // create tables in iceberg database
+ if (CollectionUtils.isNotEmpty(icebergTables)) {
+ Map<String, String> properties = stmt.getProperties();
+ for (TableIdentifier identifier : icebergTables) {
+ properties.put(IcebergCatalogMgr.TABLE, identifier.name());
+ icebergTableCreationRecordMgr.registerTable(db, identifier,properties);
Review comment:
```suggestion
icebergTableCreationRecordMgr.registerTable(db, identifier, properties);
```
##########
File path: fe/fe-core/src/main/java/org/apache/doris/catalog/Catalog.java
##########
@@ -2652,6 +2668,32 @@ public void createDb(CreateDbStmt stmt) throws DdlException {
unlock();
}
LOG.info("createDb dbName = " + fullDbName + ", id = " + id);
+
+ // create tables in iceberg database
+ if (CollectionUtils.isNotEmpty(icebergTables)) {
+ Map<String, String> properties = stmt.getProperties();
+ for (TableIdentifier identifier : icebergTables) {
+ properties.put(IcebergCatalogMgr.TABLE, identifier.name());
+ icebergTableCreationRecordMgr.registerTable(db, identifier,properties);
+ }
+ }
+ }
+
+ // Create Iceberg database in Doris
+ public IcebergDatabase createIcebergDb(CreateDbStmt stmt, long id, List<TableIdentifier> icebergTables) throws DdlException {
Review comment:
Move this to a new class, eg `IcebergUtils`. Because the Catalog.java is too large.
##########
File path: fe/fe-core/src/main/java/org/apache/doris/catalog/Catalog.java
##########
@@ -2643,7 +2653,13 @@ public void createDb(CreateDbStmt stmt) throws DdlException {
}
} else {
id = getNextId();
- Database db = new Database(id, fullDbName);
+ if (engineName.equals("builtin")) {
+ db = new Database(id, fullDbName);
+ } else if (engineName.equals("iceberg")) {
+ db = createIcebergDb(stmt, id, icebergTables);
Review comment:
`createIcebergDb` may be a time cost methods? but it is executed with lock holding.
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
[GitHub] [incubator-doris] qidaye commented on a change in pull request #7391: [feature-wip](iceberg) Step1: Support create Iceberg external table
Posted by GitBox <gi...@apache.org>.
qidaye commented on a change in pull request #7391:
URL: https://github.com/apache/incubator-doris/pull/7391#discussion_r790684457
##########
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:
Done
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
[GitHub] [incubator-doris] morningman commented on a change in pull request #7391: [feature-wip](iceberg) Step1: Support create Iceberg external table
Posted by GitBox <gi...@apache.org>.
morningman commented on a change in pull request #7391:
URL: https://github.com/apache/incubator-doris/pull/7391#discussion_r792333809
##########
File path: fe/fe-core/src/main/java/org/apache/doris/catalog/Catalog.java
##########
@@ -2631,7 +2636,15 @@ public Frontend getFeByName(String name) {
public void createDb(CreateDbStmt stmt) throws DdlException {
final String clusterName = stmt.getClusterName();
String fullDbName = stmt.getFullDbName();
- long id = 0L;
+ Map<String, String> properties = stmt.getProperties();
+
+ long id = getNextId();
+ Database db = new Database(id, fullDbName);
+ db.setClusterName(clusterName);
+ // check and analyze database properties before create database
+ db.getDbProperties().putAll(properties);
Review comment:
merge these 2 methods:
```
db.getDbProperties().putAll(properties);
db.getDbProperties().checkAndBuildProperties();
```
to
```
db.addAndBuildProperties(properties);
```
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
[GitHub] [incubator-doris] qidaye commented on a change in pull request #7391: [feature-wip](iceberg) Step1: Support create Iceberg external table
Posted by GitBox <gi...@apache.org>.
qidaye commented on a change in pull request #7391:
URL: https://github.com/apache/incubator-doris/pull/7391#discussion_r790684537
##########
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:
Done
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
[GitHub] [incubator-doris] morningman commented on a change in pull request #7391: [feature-wip](iceberg) Step1: Support create Iceberg external table
Posted by GitBox <gi...@apache.org>.
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org