Skip to content

[1034] Reconcile Iceberg identifier fields in schema sync when a record key becomes nullable - #1057

Open
shubhammittal92 wants to merge 1 commit into
apache:mainfrom
shubhammittal92:fix-1034-iceberg-identifier-nullable
Open

shubhammittal92 wants to merge 1 commit into
apache:mainfrom
shubhammittal92:fix-1034-iceberg-identifier-nullable

Conversation

@shubhammittal92

Copy link
Copy Markdown

Fixes #1034

What is the purpose of the pull request

IcebergSchemaSync.sync applied column updates (including makeColumnOptional) but never reconciled the table's identifier-field set. When an existing Iceberg table had a required record-key/identifier field that the source later evolved to nullable, the commit failed with:

java.lang.IllegalArgumentException: Cannot add field <name> as an identifier field: not a required field

IcebergSchemaExtractor.toIceberg already handles this for brand-new schemas (it drops identifier fields when any record key is nullable), but the sync path for existing tables never propagated identifier-field changes, leaving a stale identifier set that Iceberg rejects at commit.

Brief change log

  • After the column updates are applied in IcebergSchemaSync.sync, reconcile the identifier set to the latest schema (updateSchema.setIdentifierFields(latest.identifierFieldNames())) when current.identifierFieldIds() differs from latest.identifierFieldIds(). This reuses the identifier set the extractor already computes correctly (empty when any record key is nullable) instead of duplicating the all-or-nothing rule.
  • Added unit tests in TestIcebergSchemaSync (identifier set reconciled on required→optional transition; unchanged identifier fields are not re-synced).
  • Added TestIcebergSchemaSyncIdentifierReconcile, a real HadoopTables end-to-end test.

Verify this pull request

This change added tests and can be verified as follows:

  • TestIcebergSchemaSyncIdentifierReconcile creates a real Iceberg table with a required identifier field, evolves that field to nullable, syncs, and commits. It fails with the exact exception above before this fix and passes after, asserting the field becomes optional and the identifier set is cleared.
  • Mock-based unit tests in TestIcebergSchemaSync verify the setIdentifierFields interaction.
  • Full xtable-core iceberg test suite passes; spotless:check is clean.

…rd key becomes nullable

IcebergSchemaSync.sync applied column updates (including makeColumnOptional)
but never reconciled the table's identifier-field set. When an existing table
had a required record-key/identifier field that the source later evolved to
nullable, the commit failed with:
  "Cannot add field <name> as an identifier field: not a required field".

After applying the column updates, reconcile the identifier set to the latest
schema whenever the identifier field ids differ. This reuses the identifier set
IcebergSchemaExtractor already computes correctly (empty when any record key is
nullable) instead of duplicating that logic, and closes the general gap that
sync never propagated identifier-field changes.

Tests: added mock unit tests in TestIcebergSchemaSync plus a real HadoopTables
end-to-end test (TestIcebergSchemaSyncIdentifierReconcile) that fails with the
exact exception before the fix and passes after.

Signed-off-by: Shubham Mittal <shubmittal.92@gmail.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Iceberg schema sync fails when a required record key becomes nullable ("Cannot add field ... as an identifier field")

1 participant