pvary commented on code in PR #14729:
URL: https://github.com/apache/iceberg/pull/14729#discussion_r2704079848
##########
flink/v2.1/flink/src/test/java/org/apache/iceberg/flink/sink/dynamic/TestEvolveSchemaVisitor.java:
##########
@@ -682,6 +705,78 @@ private static Schema
getNestedSchemaWithOptionalModifier(boolean nestedIsOption
9, "s4",
StringType.get()))))))))))))));
}
+ @Test
+ public void testCaseInsensitiveAddField() {
+ Schema existingSchema =
+ new Schema(
+ Types.NestedField.optional(1, "id", Types.IntegerType.get()),
+ Types.NestedField.optional(2, "name", Types.StringType.get()));
+ Schema targetSchema =
+ new Schema(
+ Types.NestedField.optional(1, "ID", Types.IntegerType.get()),
+ Types.NestedField.optional(2, "NAME", Types.StringType.get()),
+ Types.NestedField.optional(3, "AGE", Types.IntegerType.get()));
+
+ UpdateSchema updateApi = loadUpdateApi(existingSchema);
+ EvolveSchemaVisitor.visit(TABLE, updateApi, existingSchema, targetSchema,
false, false);
+ Schema result = updateApi.apply();
+ assertThat(result.columns()).hasSize(3);
+ assertThat(result.findField("AGE")).isNotNull();
+ }
+
+ @Test
+ public void testCaseInsensitiveMakeFieldOptional() {
+ Schema existingSchema =
+ new Schema(
+ Types.NestedField.optional(1, "id", Types.IntegerType.get()),
+ Types.NestedField.required(2, "name", Types.StringType.get()));
+ Schema targetSchema = new Schema(Types.NestedField.optional(1, "ID",
Types.IntegerType.get()));
+
+ UpdateSchema updateApi = loadUpdateApi(existingSchema);
+ EvolveSchemaVisitor.visit(TABLE, updateApi, existingSchema, targetSchema,
false, false);
+ Schema result = updateApi.apply();
+ assertThat(result.findField("name").isOptional()).isTrue();
+ }
+
+ @Test
+ public void testCaseInsensitiveNestedStructField() {
+ Schema existingSchema =
+ new Schema(
+ optional(1, "struct1", StructType.of(optional(2, "field1",
Types.StringType.get()))));
+ Schema targetSchema =
+ new Schema(
+ optional(
+ 1,
+ "STRUCT1",
+ StructType.of(
+ optional(2, "FIELD1", Types.StringType.get()),
+ optional(3, "FIELD2", Types.IntegerType.get()))));
+
+ UpdateSchema updateApi = loadUpdateApi(existingSchema);
+ EvolveSchemaVisitor.visit(TABLE, updateApi, existingSchema, targetSchema,
false, false);
+ Schema result = updateApi.apply();
+ Types.StructType struct =
result.findField("struct1").type().asStructType();
+ assertThat(struct.fields()).hasSize(2);
+ assertThat(struct.field("FIELD2")).isNotNull();
+ }
+
+ @Test
+ public void testCaseSensitiveDoesNotMatch() {
+ Schema existingSchema =
+ new Schema(Types.NestedField.optional(1, "id",
Types.IntegerType.get()));
+ Schema targetSchema =
+ new Schema(
+ Types.NestedField.optional(1, "ID", Types.IntegerType.get()),
+ Types.NestedField.optional(2, "name", Types.StringType.get()));
+
+ UpdateSchema updateApi = loadUpdateApi(existingSchema);
+ EvolveSchemaVisitor.visit(TABLE, updateApi, existingSchema, targetSchema,
true, false);
Review Comment:
This is why we try to avoid boolean parameters. It is really hard to
understand what's happening here. We usually add a comment `/* caseSensitive
*/`, or if it often used, you might want to use a constant
--
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]