aokolnychyi commented on a change in pull request #2936:
URL: https://github.com/apache/iceberg/pull/2936#discussion_r686155666



##########
File path: core/src/main/java/org/apache/iceberg/Partitioning.java
##########
@@ -177,4 +186,52 @@ public Void alwaysNull(int fieldId, String sourceName, int 
sourceId) {
       return null;
     }
   }
+
+  /**
+   * Builds a common partition type for all specs in a table.
+   * <p>
+   * Whenever a table has multiple specs, the partition type is a struct 
containing
+   * all columns that have ever been a part of any spec in the table.
+   *
+   * @param table a table with one or many specs
+   * @return the constructed common partition type
+   */
+  public static StructType partitionType(Table table) {
+    if (table.specs().size() == 1) {
+      return table.spec().partitionType();
+    }
+
+    Map<Integer, PartitionField> fieldMap = Maps.newHashMap();
+    List<NestedField> structFields = Lists.newArrayList();
+
+    // sort the spec IDs in descending order to pick up the most recent field 
names
+    List<Integer> specIds = table.specs().keySet().stream()

Review comment:
       Added a sort by spec ID to make sure we pick up the most recent field 
name (see a dedicated test too). 




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