rdblue commented on a change in pull request #2936:
URL: https://github.com/apache/iceberg/pull/2936#discussion_r685546964
##########
File path: core/src/main/java/org/apache/iceberg/Partitioning.java
##########
@@ -177,4 +184,42 @@ 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, NestedField> commonFields = Maps.newHashMap();
+
+ for (PartitionSpec spec : table.specs().values()) {
+ List<NestedField> fields = spec.partitionType().fields();
+
+ for (NestedField field : fields) {
+ int fieldId = field.fieldId();
+ NestedField existingField = commonFields.get(fieldId);
+
+ // partition fields may conflict in v1 tables
+ ValidationException.check(existingField == null ||
existingField.equals(field),
Review comment:
I think that this should check `fieldId`, `souceId`, and `transform`,
but not `name` because it should be possible to rename fields without breaking
anything. That's why we have `fieldId`.
Also, if one of the transforms is `void` then it should also be allowed
because we replace transforms with a `void` transform to delete partition
fields in v1. `void` produces a single value that is valid for the output of
any partition function.
--
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]