rdblue commented on a change in pull request #2952:
URL: https://github.com/apache/iceberg/pull/2952#discussion_r693534406
##########
File path: api/src/test/java/org/apache/iceberg/types/TestTypeUtil.java
##########
@@ -103,6 +105,261 @@ public void testAssignIncreasingFreshIdNewIdentifier() {
Sets.newHashSet(sourceSchema.findField("a").fieldId()),
actualSchema.identifierFieldIds());
}
+ @Test
+ public void testProject() {
+ Schema schema = new Schema(
+ Lists.newArrayList(
+ required(10, "a", Types.IntegerType.get()),
+ required(11, "A", Types.IntegerType.get()),
+ required(12, "someStruct", Types.StructType.of(
+ required(13, "b", Types.IntegerType.get()),
+ required(14, "B", Types.IntegerType.get()),
+ required(15, "anotherStruct", Types.StructType.of(
+ required(16, "c", Types.IntegerType.get()),
+ required(17, "C", Types.IntegerType.get()))
+ )))));
+
+ Schema expectedTop = new Schema(
+ Lists.newArrayList(
+ required(11, "A", Types.IntegerType.get())));
+
+ Schema actualTop = TypeUtil.project(schema, Sets.newHashSet(11));
+ Assert.assertEquals(expectedTop.asStruct(), actualTop.asStruct());
+
+ Schema expectedDepthOne = new Schema(
+ Lists.newArrayList(
+ required(10, "a", Types.IntegerType.get()),
+ required(12, "someStruct", Types.StructType.of(
+ required(13, "b", Types.IntegerType.get())))));
+
+ Schema actualDepthOne = TypeUtil.project(schema, Sets.newHashSet(10, 12,
13));
+ Assert.assertEquals(expectedDepthOne.asStruct(),
actualDepthOne.asStruct());
+
+ Schema expectedDepthTwo = new Schema(
+ Lists.newArrayList(
+ required(11, "A", Types.IntegerType.get()),
+ required(12, "someStruct", Types.StructType.of(
+ required(15, "anotherStruct", Types.StructType.of(
+ required(17, "C", Types.IntegerType.get()))
+ )))));
+
+ Schema actualDepthTwo = TypeUtil.project(schema, Sets.newHashSet(11, 12,
15, 17));
+ Assert.assertEquals(expectedDepthTwo.asStruct(),
actualDepthTwo.asStruct());
+ }
+
+ @Test
+ public void testProjectNaturallyEmpty() {
+ Schema schema = new Schema(
+ Lists.newArrayList(
+ required(12, "someStruct", Types.StructType.of(
+ required(15, "anotherStruct", Types.StructType.of(
+ required(20, "empty", Types.StructType.of())
+ ))))));
+
+ Schema expectedDepthOne = new Schema(
+ Lists.newArrayList(
+ required(12, "someStruct", Types.StructType.of())));
+
+ Schema actualDepthOne = TypeUtil.project(schema, Sets.newHashSet(12));
+ Assert.assertEquals(expectedDepthOne.asStruct(),
actualDepthOne.asStruct());
+
+ Schema expectedDepthTwo = new Schema(
+ Lists.newArrayList(
+ required(12, "someStruct", Types.StructType.of(
+ required(15, "anotherStruct", Types.StructType.of())))));
+
+ Schema actualDepthTwo = TypeUtil.project(schema, Sets.newHashSet(12, 15));
+ Assert.assertEquals(expectedDepthTwo.asStruct(),
actualDepthTwo.asStruct());
+
+ Schema expectedDepthThree = new Schema(
+ Lists.newArrayList(
+ required(12, "someStruct", Types.StructType.of(
+ required(15, "anotherStruct", Types.StructType.of(
+ required(20, "empty", Types.StructType.of())
+ ))))));
+
+ Schema actualDepthThree = TypeUtil.project(schema, Sets.newHashSet(12, 15,
20));
Review comment:
These tests always project the IDs further up the tree. I think it would
be good to also test inclusion from children: `Sets.newHashSet(20)`
--
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]