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



##########
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()) {

Review comment:
       I think we can have some sort of helper method for adding columns for a 
schema, so the logic do not have to be repeated.




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