#18262·iceberg

Flink: DynamicIcebergSink writes an unbindable equality delete when a schema evolution splits one table across two writers inside one checkpoint

Author: abrarsher23Created Sep 25, 2026Updated Sep 29, 2026

Apache Iceberg version: 1.10.2 (reproduced). The code involved is unchanged in 1.11.0, 1.12.0-rc1 and main (flink/v2.3), so the same behaviour is expected there; only 1.10.2 has been run.

Query engine: Flink (DynamicIcebergSink, DataStream API, upsert mode)

**Please describe the bug **

Summary

If a table's input schema evolves in the middle of a checkpoint, DynamicIcebergSink in upsert mode opens a second TaskWriter for that table. An update to a key already written in the same checkpoint then goes to the second writer, whose insertedRowMap is empty, so the key is retired with an equality delete instead of a position delete.

Because all files of one table in a checkpoint are committed in a single RowDelta, that equality delete gets the same sequence number as the data file holding the old row. Equality deletes only apply to data with a strictly lower sequence number, so the delete never takes effect and both versions of the key stay visible. A later RewriteDataFiles makes the duplicate permanent.

FlinkSink and IcebergSink avoid this by always retiring same-checkpoint rewrites with a position delete. DynamicIcebergSink reuses the same delta writers but keys them per record on a WriteTarget that includes the schema id, which breaks that invariant.

Root cause

Line numbers at tag apache-iceberg-1.10.2, flink/v2.0.

  1. DynamicWriter#write creates one writer per WriteTarget, and WriteTarget includes schemaId (DynamicWriter.java:92-100, WriteTarget.java:32-37).
  2. On SCHEMA_UPDATE_NEEDED, TableUpdater#findOrCreateSchema evolves the table inline and the resolved schema id changes (TableUpdater.java:135-148, DynamicRecordProcessor.java:111-123, 145-173).
  3. The next record for the table therefore gets a second TaskWriter; writers is only cleared in prepareCommit() (DynamicWriter.java:84, 193).
  4. Each TaskWriter has its own insertedRowMap, which alone decides position vs equality delete (BaseTaskWriter.java:121, 186-196, 216-220; BaseDeltaTaskWriter.java:82-88). The second writer's map is empty, so the update becomes an equality delete.
  5. DynamicCommitter builds one RowDelta per (table, branch) per checkpoint (DynamicCommitter.java:125-134, 309-328), so both writers' files share one sequence number and the delete cannot apply.

Reproduction

Integration test feeding DynamicIcebergSink with parallelism 1, DistributionMode.NONE, immediateTableUpdate(true), setUpsertMode(true), equality field order_id, checkpointing disabled so the bounded run commits once.

  • schema v1 = (order_id string, amount int); schema v2 = v1 plus a nullable note string
  • in one commit: INSERT {order_id="K", amount=100} under v1, then UPDATE_AFTER {order_id="K", amount=200, note=null} under v2

Expected (and observed when both records are under v1): 1 row; 1 data file, 1 position delete, 1 equality delete (the insert's normal deleteKey).

Actual: 2 rows; 2 data files, 2 equality deletes, 0 position deletes, all at one sequence_number (added-data-files=2, added-equality-delete-files=2, total-position-deletes=0).

A schema evolution between two different keys produces 2 data files and 2 equality deletes at one sequence number and is correct, so "data file and equality delete at the same sequence number" is not the symptom by itself. The symptom is an in-commit update whose delete is an equality delete instead of a position delete.

Impact

Silent duplicate rows on upsert tables whenever a key is written and then updated inside the checkpoint in which the input schema evolves, which is what happens when an upstream CDC source adds a column. No exception, the commit succeeds, and compaction makes it permanent.

Proposed fix

Share one inserted-row tracker across all TaskWriters of a table for the lifetime of a checkpoint, scoped to the WriteTarget without schemaId and cleared next to writers.clear(). The second writer's deleteKey then finds the first writer's PathOffset and emits a position delete against the first writer's data file, which is valid at an equal sequence number. The map key is the equality-field projection, which adding a column does not change. Two details: BaseEqualityDeltaWriter.close() currently clears the map (BaseTaskWriter.java:243-246), and PathOffset is private (:267), so the tracker needs an ownership flag and a small interface or exposed type. Sharing should be guarded when an equality field's type changes, and a mid-checkpoint partition-spec evolution would remain out of scope.

Willingness to contribute

  • I can contribute a fix for this bug independently
  • I would be willing to contribute a fix for this bug with guidance from the Iceberg community
  • I cannot contribute a fix for this bug at this time

Happy to open a PR with the fix and a regression test for this case.