moggaa commented on code in PR #17653:
URL: https://github.com/apache/iceberg/pull/17653#discussion_r4241814843
##########
kafka-connect/kafka-connect/src/test/java/org/apache/iceberg/connect/data/TestRecordConverter.java:
##########
@@ -962,6 +988,102 @@ public void testNoSchemaEvolutionStructWithNullValue() {
assertThat(consumer.empty()).isTrue();
}
+ @ParameterizedTest
+ @ValueSource(booleans = {true, false})
+ public void testNoSchemaEvolutionStructWithNullValueOfFieldWithDefault(
+ boolean replaceNullWithDefault) {
+ when(config.replaceNullWithDefault()).thenReturn(replaceNullWithDefault);
+
+ org.apache.iceberg.Schema nestedStructSchema =
+ new org.apache.iceberg.Schema(
+ NestedField.required(1, "id", IntegerType.get()),
+ NestedField.optional(
+ 2, "nested", StructType.of(NestedField.optional(3, "a",
IntegerType.get()))));
+
+ Table table = mock(Table.class);
+ when(table.schema()).thenReturn(nestedStructSchema);
+ RecordConverter converter = new RecordConverter(table, config);
+
+ SchemaBuilder connectNestedSchemaBuilder =
+ SchemaBuilder.struct().optional().field("a",
Schema.OPTIONAL_INT32_SCHEMA);
+ Struct nestedDefault = new Struct(connectNestedSchemaBuilder).put("a", 42);
Review Comment:
Agreed the cycle is ugly, but the suggested construction doesn't pass
validation: `SchemaBuilder.defaultValue` validates the value against the
builder via `ConnectSchema.validateValue`, whose STRUCT branch requires
`struct.schema().equals(schema)`, and `ConnectSchema.equals` is class-gated —
so a struct built from the already-built schema fails with `DataException:
Struct schemas do not match` (confirmed against connect-api 3.9.2). This is a
known gap: [KAFKA-12694](https://issues.apache.org/jira/browse/KAFKA-12694) is
still open, and its duplicate
[KAFKA-14716](https://issues.apache.org/jira/browse/KAFKA-14716) describes the
builder-referencing struct as the only way to set a struct-typed default. So
the cycle is the documented workaround rather than an accident — I've kept the
construction as is.
--
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]