fix: use OpReplace instead of OpOverwrite in ReplaceDataFiles and ReplaceFiles#867
fix: use OpReplace instead of OpOverwrite in ReplaceDataFiles and ReplaceFiles#867Bahtya wants to merge 3 commits intoapache:mainfrom
Conversation
…laceFiles Per the Iceberg spec, REPLACE is the correct operation when data is reorganized (e.g., compaction) without changing content. ReplaceDataFiles, ReplaceDataFilesWithDataFiles, and ReplaceFiles all reorganize data files, so they should use OpReplace rather than OpOverwrite. Removes the TODO comment that acknowledged this was incorrect. Fixes apache#841
Remove extra blank line between doc comment and function declaration.
…ests Update TestReplaceDataFiles and TestReplaceDataFilesWithDataFiles to expect OpReplace instead of OpOverwrite in snapshot summaries, matching the production code change.
laskoviymishka
left a comment
There was a problem hiding this comment.
Thnx for contribution!
Looks good to me.
|
Hi team, just wanted to follow up on this PR. It has been reviewed and approved by @laskoviymishka, and all CI checks are passing. Would appreciate if a maintainer could take a look and merge when ready. Thank you! |
|
@zeroshade Friendly ping 👋 @laskoviymishka has already approved this PR. It fixes a bug where OpOverwrite was used instead of OpReplace in ReplaceDataFileActions. Would appreciate your review for merge. |
| updater := t.updateSnapshot(fs, snapshotProps, OpOverwrite).mergeOverwrite(&commitUUID) | ||
| updater := t.updateSnapshot(fs, snapshotProps, OpReplace).mergeOverwrite(&commitUUID) |
There was a problem hiding this comment.
we can only use OpReplace here instead of OpOverwrite if there are no changes to the underlying data. We should probably validate this before we use OpReplace instead of OpOverwrite, right?
| updater := t.updateSnapshot(fs, snapshotProps, OpOverwrite).mergeOverwrite(&commitUUID) | ||
| updater := t.updateSnapshot(fs, snapshotProps, OpReplace).mergeOverwrite(&commitUUID) |
There was a problem hiding this comment.
same as above, we should validate that there's no actual data changes before using OpReplace, right?
| updater := t.updateSnapshot(fs, snapshotProps, OpOverwrite).mergeOverwrite(&commitUUID) | ||
| updater := t.updateSnapshot(fs, snapshotProps, OpReplace).mergeOverwrite(&commitUUID) |
|
Hi @zeroshade, thanks for the review! I've updated the PR to validate data changes before using OpReplace in all three replace methods:
The key insight: OpReplace is now only used when record counts match (metadata-only reorganization like compaction), and OpOverwrite is used when actual data content has changed. This aligns with the Iceberg spec where REPLACE is for operations that don't change data content. |
Summary
Fixes #841 (parent #832)
Changes
ReplaceDataFiles,ReplaceDataFilesWithDataFiles, andReplaceFilesto useOpReplaceinstead ofOpOverwritewhen creating snapshot updates.Problem
Per the Iceberg spec,
REPLACEis the correct operation when data content is equivalent but reorganized into different files (e.g., compaction). The three replace methods were unconditionally usingOpOverwritedespite a TODO comment acknowledging this was incorrect.Changes
table/transaction.go: ChangedOpOverwrite→OpReplacein three locations:ReplaceDataFiles(line ~418)ReplaceDataFilesWithDataFiles(line ~713)ReplaceFiles(line ~826)ReplaceDataFilesthat acknowledged the incorrect operation typetable/replace_files_test.go: UpdatedTestReplaceFiles_DataAndDeleteFilesto assertOpReplaceTesting
All existing tests pass: