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


##########
api/src/test/java/org/apache/iceberg/types/TestTypeUtil.java:
##########
@@ -645,4 +651,70 @@ public void testReassignOrRefreshIdsCaseInsensitive() {
                 required(2, "FIELD2", Types.IntegerType.get())));
     assertThat(actualSchema.asStruct()).isEqualTo(expectedSchema.asStruct());
   }
+
+  private static Stream<Arguments> testTypes() {
+    return Stream.of(
+        Arguments.of(Types.UnknownType.get()),
+        Arguments.of(Types.VariantType.get()),
+        Arguments.of(Types.TimestampNanoType.withoutZone()),
+        Arguments.of(Types.TimestampNanoType.withZone()));
+  }
+
+  @ParameterizedTest
+  @MethodSource("testTypes")
+  public void testAssignFreshIdsWithType(Type testType) {
+    Schema schema =
+        new Schema(required(0, "v", testType), required(1, "A", 
Types.IntegerType.get()));
+
+    Schema assignedSchema = TypeUtil.assignFreshIds(schema, new 
AtomicInteger(10)::incrementAndGet);
+    Schema expectedSchema =
+        new Schema(required(11, "v", testType), required(12, "A", 
Types.IntegerType.get()));
+    assertThat(assignedSchema.asStruct()).isEqualTo(expectedSchema.asStruct());
+  }
+
+  @ParameterizedTest
+  @MethodSource("testTypes")
+  public void testReassignIdsWithType(Type testType) {
+    Schema schema =
+        new Schema(required(0, "v", testType), required(1, "A", 
Types.IntegerType.get()));
+    Schema sourceSchema =
+        new Schema(required(1, "v", testType), required(2, "A", 
Types.IntegerType.get()));
+
+    Schema reassignedSchema = TypeUtil.reassignIds(schema, sourceSchema);
+    assertThat(reassignedSchema.asStruct()).isEqualTo(sourceSchema.asStruct());
+  }
+
+  @ParameterizedTest
+  @MethodSource("testTypes")
+  public void testIndexByIdWithType(Type testType) {
+    Schema schema =
+        new Schema(required(0, "v", testType), required(1, "A", 
Types.IntegerType.get()));
+
+    Map<Integer, Types.NestedField> indexByIds = 
TypeUtil.indexById(schema.asStruct());
+    assertThat(indexByIds.get(0).type()).isEqualTo(testType);
+  }
+
+  @ParameterizedTest
+  @MethodSource("testTypes")
+  public void testIndexNameByIdWithType(Type testType) {
+    Schema schema =
+        new Schema(required(0, "v", testType), required(1, "A", 
Types.IntegerType.get()));
+
+    Map<Integer, String> indexNameByIds = 
TypeUtil.indexNameById(schema.asStruct());
+    assertThat(indexNameByIds.get(0)).isEqualTo("v");
+  }
+
+  @ParameterizedTest
+  @MethodSource("testTypes")
+  public void testProjectWithType(Type testType) {
+    Schema schema =
+        new Schema(required(0, "v", testType), required(1, "A", 
Types.IntegerType.get()));
+
+    Schema expectedSchema = new Schema(Lists.newArrayList(required(0, "v", 
testType)));
+    Schema projectedSchema = TypeUtil.project(schema, Sets.newHashSet(0));
+    
assertThat(projectedSchema.asStruct()).isEqualTo(expectedSchema.asStruct());
+
+    Set<Integer> projectedIds = TypeUtil.getProjectedIds(schema);

Review Comment:
   It looks like this is testing both `getProjectedIds` and `project`. It's 
minor, but I think these should test one visitor at a time.



-- 
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: issues-unsubscr...@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to