fix: apply schema-force-optional recursively in schema evolution path [fj4WqyCCw3C5ShR1RfB7MoBPTpkRrBFYP1uT35g3MvT] - #17556
Open
waterWang wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
When
iceberg.tables.schema-force-optional=trueis set and schema evolution is enabled, theRecordConverteronly makes a table field optional when the incoming Connect record field's schema is already optional. It does not checkconfig.schemaForceOptional(), so required nested struct fields in the Connect schema remain required in the Iceberg table.This is a gap in the schema evolution path:
toIcebergTypealready appliesschemaForceOptionalrecursively for initial schema creation (auto-create), but themakeOptionallogic inRecordConverterdoes not consult the flag.Changes
RecordConverter.java —
convertToStruct(Struct): Changed themakeOptionalcondition fromtableField.isRequired() && recordField.schema().isOptional()totableField.isRequired() && (config.schemaForceOptional() || recordField.schema().isOptional()).RecordConverter.java —
evolveSchemaFromConnectSchema: Same change for the nested-field case.TestSchemaUtils.java — Added
testToIcebergTypeNestedStructparameterized test that verifiestoIcebergTyperecursively appliesschemaForceOptionalto nested struct fields at every level.Impact
schemaForceOptional=truenow ensures that required fields in the Connect schema are marked optional in the Iceberg schema during evolution, matching the behavior already present in the auto-create path._cdc.keystruct (from DebeziumTransform) keeps required nested fields, causing writer failures when the source PK changes and old key fields disappear from incoming records.Closes #17555