rdblue commented on code in PR #18108:
URL: https://github.com/apache/iceberg/pull/18108#discussion_r4148827749


##########
core/src/test/java/org/apache/iceberg/TestTrackedFileStruct.java:
##########
@@ -340,6 +342,78 @@ void projectedStructLike() {
     assertThat(file.get(1, Long.class)).isEqualTo(1024L);
   }
 
+  @Test
+  void partitionIsProjectedOntoResolvedSpec() {
+    // a table whose partitioning evolved from id to category
+    Schema schema =
+        new Schema(
+            Types.NestedField.required(1, "id", Types.IntegerType.get()),
+            Types.NestedField.required(2, "category", Types.StringType.get()));
+    PartitionSpec idSpec =
+        PartitionSpec.builderFor(schema)
+            .withSpecId(0)
+            .add(1, 1000, "id", Transforms.identity())
+            .build();
+    PartitionSpec categorySpec =
+        PartitionSpec.builderFor(schema)
+            .withSpecId(1)
+            .add(2, 1001, "category", Transforms.identity())
+            .build();
+    Map<Integer, PartitionSpec> specsById =
+        ImmutableMap.of(idSpec.specId(), idSpec, categorySpec.specId(), 
categorySpec);
+
+    // the manifest stores partitions in the union type, where category sits 
after id
+    Types.StructType unionType = 
Partitioning.unionPartitionTypes(specsById.values());
+    int categoryUnionPos = 
unionType.fields().indexOf(unionType.field("category"));
+    PartitionData unionPartition = new PartitionData(unionType);
+    unionPartition.set(categoryUnionPos, "books");
+
+    TrackedFileStruct file = trackedFile(categorySpec.specId(), 
unionPartition);
+    file.setPartitionProjection(StructProjection.create(unionType, 
categorySpec.partitionType()));
+
+    // category is at position 1 in the union but position 0 in categorySpec; 
reading by the spec's
+    // ordinal must return category, not id (null)
+    assertThat(file.partition().get(0, 
CharSequence.class)).hasToString("books");

Review Comment:
   Probably better to use a StructComparator instead of dealing with 
CharSequence and `hasToString`.



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