jackye1995 commented on a change in pull request #3888:
URL: https://github.com/apache/iceberg/pull/3888#discussion_r784279724



##########
File path: 
aws/src/main/java/org/apache/iceberg/aws/glue/IcebergToGlueConverter.java
##########
@@ -252,59 +256,118 @@ private static String toTypeString(Type type) {
 
   private static List<Column> toColumns(TableMetadata metadata) {
     List<Column> columns = Lists.newArrayList();
-    Set<NestedField> rootColumnSet = Sets.newHashSet();
+    Set<String> addedNames = Sets.newHashSet();
     // Add schema-column fields
     for (NestedField field : metadata.schema().columns()) {
-      rootColumnSet.add(field);
-      columns.add(Column.builder()
-          .name(field.name())
-          .type(toTypeString(field.type()))
-          .comment(field.doc())
-          .parameters(convertToParameters(SCHEMA_COLUMN, field))
-          .build());
+      addColumnWithDedupe(columns, addedNames, field, field.name(), 
SCHEMA_COLUMN, true);
     }
     // Add schema-subfield
-    for (NestedField field : 
TypeUtil.indexById(metadata.schema().asStruct()).values()) {
-      if (!rootColumnSet.contains(field)) {
-        columns.add(Column.builder()
-            .name(field.name())
-            .type(toTypeString(field.type()))
-            .comment(field.doc())
-            .parameters(convertToParameters(SCHEMA_SUBFIELD, field))
-            .build());
+    for (String fieldName : 
TypeUtil.indexNameById(metadata.schema().asStruct()).values()) {
+      NestedField field = metadata.schema().findField(fieldName);
+      if (field != null) {
+        addColumnWithDedupe(columns, addedNames, field, fieldName, 
SCHEMA_SUBFIELD, true);
+      }
+    }
+    // Add old schema fields
+    for (Schema schema : metadata.schemas()) {
+      if (schema.schemaId() != metadata.currentSchemaId()) {
+        // Add old schema-column fields
+        for (NestedField field : schema.columns()) {
+          addColumnWithDedupe(columns, addedNames, field, field.name(), 
SCHEMA_COLUMN, false);
+        }
+        // Add old schema-subfield
+        for (String fieldName : 
TypeUtil.indexNameById(schema.asStruct()).values()) {
+          NestedField field = schema.findField(fieldName);
+          if (field != null) {
+            addColumnWithDedupe(columns, addedNames, field, fieldName, 
SCHEMA_SUBFIELD, false);
+          }
+        }
       }
     }
     // Add partition-field
     for (PartitionField partitionField : metadata.spec().fields()) {
+      addPartitionColumnWithDedupe(columns, addedNames, partitionField, 
metadata.spec().schema(), true);
+    }
+    // Add old partition-field
+    for (PartitionSpec spec : metadata.specs()) {

Review comment:
       similar comment for the partition spec, we can have a helper method




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

Reply via email to