aokolnychyi commented on a change in pull request #2984:
URL: https://github.com/apache/iceberg/pull/2984#discussion_r716842115
##########
File path: core/src/main/java/org/apache/iceberg/Partitioning.java
##########
@@ -246,4 +246,45 @@ private static boolean
equivalentIgnoringNames(PartitionField field, PartitionFi
private static boolean compatibleTransforms(Transform<?, ?> t1, Transform<?,
?> t2) {
return t1.equals(t2) || t1.equals(Transforms.alwaysNull()) ||
t2.equals(Transforms.alwaysNull());
}
+
+ /**
+ * Adapts the provided partition data to match the table partition type
built using {@link #partitionType(Table)}.
+ *
+ * @param partitionType a table partition type that includes partition
fields from all specs
+ * @param spec a partition spec
+ * @param partition a struct containing partition data that belongs to the
spec
+ * @return the reconciled partition type
+ */
+ public static StructLike reconcilePartition(StructType partitionType,
PartitionSpec spec, StructLike partition) {
+ StructLike newPartition = new PartitionData(partitionType);
+
+ // build a map from field IDs to their positions in the spec
+ Map<Integer, Integer> fieldIdToSpecPositionMap =
buildFieldIdToPositionMap(spec);
+
+ // iterate through all fields in the partition type and get values from
the partition struct
+ for (int position = 0; position < partitionType.fields().size();
position++) {
+ NestedField field = partitionType.fields().get(position);
+ Integer specPosition = fieldIdToSpecPositionMap.get(field.fieldId());
+ if (specPosition != null) {
+ // retrieve the value as the spec contains this partition field
+ newPartition.set(position, partition.get(specPosition,
field.type().typeId().javaClass()));
+ } else {
+ // set the value as null as the spec does not contain this partition
field
+ newPartition.set(position, null);
+ }
+ }
+
+ return newPartition;
+ }
+
+ private static Map<Integer, Integer> buildFieldIdToPositionMap(PartitionSpec
spec) {
Review comment:
Switched to projections, so no longer applies.
--
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]