anoopj commented on code in PR #16958:
URL: https://github.com/apache/iceberg/pull/16958#discussion_r3670080824
##########
api/src/test/java/org/apache/iceberg/types/TestTypeUtil.java:
##########
@@ -1037,4 +1038,41 @@ public void testIndexStatsNames() {
.containsEntry(24, "addresses_value") // the leaf takes precedence
.hasSize(22);
}
+
+ @Test
+ public void testReplaceFieldTypes() {
+ Types.StructType replacement = Types.StructType.of(required(10, "x",
IntegerType.get()));
+ Schema schema =
+ new Schema(
+ required(1, "id", IntegerType.get()),
+ required(2, "s", Types.StructType.of(required(3, "a",
Types.LongType.get()))));
+
+ Schema result = TypeUtil.replaceFieldTypes(schema, ImmutableMap.of(2,
(Type) replacement));
Review Comment:
Done
##########
api/src/test/java/org/apache/iceberg/types/TestTypeUtil.java:
##########
@@ -1037,4 +1038,41 @@ public void testIndexStatsNames() {
.containsEntry(24, "addresses_value") // the leaf takes precedence
.hasSize(22);
}
+
+ @Test
+ public void testReplaceFieldTypes() {
+ Types.StructType replacement = Types.StructType.of(required(10, "x",
IntegerType.get()));
+ Schema schema =
+ new Schema(
+ required(1, "id", IntegerType.get()),
+ required(2, "s", Types.StructType.of(required(3, "a",
Types.LongType.get()))));
+
+ Schema result = TypeUtil.replaceFieldTypes(schema, ImmutableMap.of(2,
(Type) replacement));
+
+ assertThat(result.findField(1).type()).isEqualTo(IntegerType.get());
+ assertThat(result.findField(2).type()).isEqualTo(replacement);
+ }
+
+ @Test
+ public void testReplaceFieldTypesListElement() {
+ Schema schema =
+ new Schema(required(1, "list", Types.ListType.ofRequired(2,
Types.StructType.of())));
+
+ Schema result =
+ TypeUtil.replaceFieldTypes(
+ schema,
+ ImmutableMap.of(2, (Type) Types.StructType.of(required(3, "x",
IntegerType.get()))));
+
+ Types.ListType list = (Types.ListType) result.findField(1).type();
+
assertThat(list.elementType().asStructType().field(3).name()).isEqualTo("x");
+ assertThat(list.isElementRequired()).isTrue();
+ }
+
+ @Test
+ public void testReplaceFieldTypesNoMatchReturnsSameSchema() {
+ Schema schema = new Schema(required(1, "id", IntegerType.get()));
+ Schema result =
+ TypeUtil.replaceFieldTypes(schema, ImmutableMap.of(99, (Type)
Types.LongType.get()));
Review Comment:
Done
--
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]