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: [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]