gong commented on code in PR #8141:
URL: https://github.com/apache/inlong/pull/8141#discussion_r1214186268


##########
inlong-sort/sort-flink/sort-flink-v1.13/sort-connectors/iceberg/src/main/java/org/apache/inlong/sort/iceberg/sink/multiple/DynamicSchemaHandleOperator.java:
##########
@@ -434,33 +450,29 @@ private void handleSchemaInfoEvent(TableIdentifier 
tableId, Schema schema) {
 
     // ================================ All coordinator handle method 
==============================================
     private void handleTableCreateEventFromOperator(TableIdentifier tableId, 
Schema schema) {
-        if (!catalog.tableExists(tableId)) {
-            if (asNamespaceCatalog != null && 
!asNamespaceCatalog.namespaceExists(tableId.namespace())) {
-                try {
-                    asNamespaceCatalog.createNamespace(tableId.namespace());
-                    LOG.info("Auto create Database({}) in Catalog({}).", 
tableId.namespace(), catalog.name());
-                } catch (AlreadyExistsException e) {
-                    LOG.warn("Database({}) already exist in Catalog({})!", 
tableId.namespace(), catalog.name());
-                }
-            }
-            ImmutableMap.Builder<String, String> properties = 
ImmutableMap.builder();
-            properties.put("format-version", "2");
-            properties.put("write.upsert.enabled", "true");
-            properties.put("write.metadata.metrics.default", "full");
-            // for hive visible
-            properties.put("engine.hive.enabled", "true");
-            try {
-                catalog.createTable(tableId, schema, 
PartitionSpec.unpartitioned(), properties.build());
-                LOG.info("Auto create Table({}) in Database({}) in 
Catalog({})!",
-                        tableId.name(), tableId.namespace(), catalog.name());
-            } catch (AlreadyExistsException e) {
-                LOG.warn("Table({}) already exist in Database({}) in 
Catalog({})!",
-                        tableId.name(), tableId.namespace(), catalog.name());
-            }
-        }
+        IcebergSchemaChangeUtils.createTable(catalog, tableId, 
asNamespaceCatalog, schema);
         handleSchemaInfoEvent(tableId, catalog.loadTable(tableId).schema());
     }
 
+    @VisibleForTesting
+    public static Map<String, ColumnSchema> extractColumnSchema(Schema schema) 
{
+        Map<String, ColumnSchema> columnSchemaMap = new LinkedHashMap<>();
+        List<Types.NestedField> nestedFieldList = schema.columns();
+        int n = nestedFieldList.size();
+        for (int i = 0; i < n; i++) {
+            Types.NestedField nestedField = nestedFieldList.get(i);
+            ColumnSchema columnSchema = new ColumnSchema();
+            columnSchema.setName(nestedField.name());
+            columnSchema.setType(FlinkSchemaUtil.convert(nestedField.type()));
+            columnSchema.setNullable(nestedField.isOptional());
+            columnSchema.setComment(nestedField.doc());
+            columnSchema.setPosition(i == 0 ? 
TableChange.ColumnPosition.first()
+                    : TableChange.ColumnPosition.after(nestedFieldList.get(n - 
1).name()));

Review Comment:
   `TableChange.ColumnPosition.after(nestedFieldList.get(n - 1).name())` is 
right ?
   nestedFieldList.get(n - 1) maybe nestedFieldList.get(i - 1) ?



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

Reply via email to