moggaa commented on code in PR #17653:
URL: https://github.com/apache/iceberg/pull/17653#discussion_r4241816041
##########
kafka-connect/kafka-connect-transforms/src/test/java/org/apache/iceberg/connect/transforms/TestCopyValue.java:
##########
@@ -86,4 +86,31 @@ public void testCopyValueWithSchema() {
assertThat(newValue.get("data_copy")).isEqualTo("foobar");
}
}
+
+ @Test
+ public void testCopyValueWithSchemaPreservesNullOfFieldWithDefault() {
+ Map<String, String> props =
+ ImmutableMap.of(
+ "source.field", "data",
+ "target.field", "data_copy");
+
+ Schema schema =
+ SchemaBuilder.struct()
+ .field("id", Schema.INT64_SCHEMA)
+ .field("data",
SchemaBuilder.string().optional().defaultValue("").build());
+
+ Struct value = new Struct(schema).put("id", 123L).put("data", null);
+
+ try (CopyValue<SinkRecord> smt = new CopyValue<>()) {
+ smt.configure(props);
+ SinkRecord record = new SinkRecord("topic", 0, null, null, schema,
value, 0);
+ SinkRecord result = smt.apply(record);
+
+ Struct newValue = (Struct) result.value();
+
+ // the explicit null is preserved for both the copied and the target
field
+ assertThat(newValue.getWithoutDefault("data")).isNull();
+ assertThat(newValue.getWithoutDefault("data_copy")).isNull();
Review Comment:
Added in 751c2e0a4 — both fields now assert `get(...)` still returns the
default, matching the other three SMT tests.
--
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]