[Core] Add Delete File Support and Partition Pruning for Incremental Changelog Scans
This PR extends BaseIncrementalChangelogScan to support positional and equality delete files (MoR use cases), enabling complete CDC coverage.
I read all discussion on @wypoon 's #10935 The PR was old and also it does not cover all cases. I decided to implement with a fresh approach but reduced scope. Initial PR had spark implementation. in this PR I will only focus on core module support. With this implementation, changelog scans now correctly produce DeletedRowsScanTask, DeletedDataFileScanTask, and AddedRowsScanTask even when delete files are present.
I implemented unit tests for following scenario behaviors
| Scenario | Expected Behavior |
|---|---|
| Insert → Equality Delete → Re-insert | One DELETE + one INSERT changelog event |
| Insert & Delete in Same Commit | Emitted as one task with attached deletes |
| Overlapping Equality + Position Deletes | Deduplicated delete application |
| Existing Deletes + New Deletes | Both applied without duplication |
| Overwrite Snapshot with Deletes | No NPE, correct ADDED/DELETED tasks |
| Large Delete Set | Pruned by partition filter |
Step by Step Planning Logic:
The doPlanFiles method now:
- Builds the existing delete index from the base snapshot
- Builds per-snapshot added delete indexes for each changelog snapshot
- Plans data file tasks (ADDED/DELETED) with appropriate delete files attached
- Plans additional
DeletedRowsScanTaskinstances for EXISTING data files affected by new delete files
Three Types of Changelog Tasks
-
AddedRowsScanTask: For newly added data files
- Includes both existing deletes (inherited) and newly added deletes in the same snapshot
- Produces INSERT changelog rows
-
DeletedDataFileScanTask: For deleted data files
- Includes existing deletes that were present before file deletion
- Produces DELETE changelog rows for the entire file
-
DeletedRowsScanTask: For existing data files with new delete files
addedDeletes(): New delete files added in this snapshot (generate DELETE rows)existingDeletes(): Delete files that existed before (applied for filtering)- Produces DELETE changelog rows only for newly deleted records
Processing multiple snapshot and equality deletes are expensive operations for huge tables. I also added few performance optimization.
| Optimization | Description |
|---|---|
| Manifest caching | Introduced DeleteManifestCache to avoid redundant manifest parsing |
| Partition pruning | Uses filter pushdown to skip irrelevant delete manifests |
| Incremental accumulation | Avoids rebuilding the delete index for every snapshot |
| Selective copy | ContentFileUtil.copy() keeps only essential stats to reduce memory footprint |
Possible Future Work
- V3 Deletion Vector support. I am trying to define foundation for Deletion Vector base CDC.
- Add persistent delete index cache
- Engine level support
@wypoon @pvary @aokolnychyi @stevenzwu I will appreciated if you share your thoughts. I believe This PR will unblock many use cases.
Changelog without deletes is useless! Thanks for adding this. Looking forward to it!!
Sightly unrelated to the PR. I am trying to understand the state and roadmap of changelog / incremental cdc support in core and spark. Looking at this PR's description, it looks like there is still quite a bit to do.
What is a good resource for me to understand it? I am looking for both documentation level content and design details.
@vigneshc Actually, this PR will provide full CDC support for V2 tables once it’s merged. We’ve already covered all possible scenarios. I haven’t implemented the engine execution part yet because I wanted to focus on the core functionality first. Would you consider contributing Spark support after this PR is merged?
@vigneshc Actually, this PR will provide full CDC support for V2 tables once it’s merged. We’ve already covered all possible scenarios. I haven’t implemented the engine execution part yet because I wanted to focus on the core functionality first. Would you consider contributing Spark support after this PR is merged?
I see this procedure, create_changelog_view . https://iceberg.apache.org/docs/latest/spark-procedures/#change-data-capture
Can you help me understand the difference between the support this procedure offers, and the pr enables? Initial pointers are enough. On spark, I have not contributed to this repo, not sure how hard it would be. I can give it a shot with some help.
This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the [email protected] list. Thank you for your contributions.
This pull request has been closed due to lack of activity. This is not a judgement on the merit of the PR in any way. It is just a way of keeping the PR queue manageable. If you think that is incorrect, or the pull request requires review, you can revive the PR at any time.
Let me reopen and take a look today.
What I like about this PR is the attempt to have per snapshot state like DeleteFileIndex and the incremental approach for building that state. It does seem like there are some correctness issues in the implementation, however.
I found some old notes on this topic and spent some time thinking about it. Sharing them below.
Potential Algorithm
Iterate over changelog snapshots (ignoring logical rewrites).
- Find new data and delete files added across the changelog range (look for new manifests and ADDED manifest entry statuses).
- Find data and delete files that have been removed across the changelog range (look for new manifests and DELETED manifest entry statuses).
- Build the affected partition set and a set of affected data files locations for pruning of base data and delete manifests. This combined predicate may be used for pruning along the user-provided filter. It would essentially tell us what partitions have been affected. See below for examples.
AddedRowsScanTask
This task type contains data file + deletes assigned in the same snapshot.
The only delete lookup that needs to happen for new data files is DVs associated in the same snapshot. Like in this PR, we can simply build DeleteFileIndex using the new delete files from that snapshot. This information will be sufficient to emit this type of tasks. We don’t need to scan through existing deletes.
DeletedDataFileScanTask
This task type contains data file + existing deletes.
For each removed data file, we need to find deletes that were associated with it. We have to scan the effective delete file list for this changelog snapshot (base + incremental changes up to this snapshot) while doing the lookup. We don’t have manifest affinity in V3 but we can prune the base delete set using the user provided predicate and by collecting partitions and file names of all affected data files in the changelog range.
If the table only contains DVs, the set of removed delete files for that snapshot will contain the old DV. While dropping data files engines must drop the DV too (double check this statement). This means we don’t have to scan through base deletes if we know that we only deal with DVs.
It is likely OK to ignore delete compactions that happened during the changelog range and use old deletes as their content should be the same (I need to think this through, actually).
DeletedRowsScanTask
This task type contains data file + added deletes + existing deletes.
For each new delete file, we have to find its data file and the list of previous deletes.
If the added delete is a DV, the old DV (if existed) must be in the set of removed DVs in that snapshot. We won’t have to scan historic deletes.
We can use the same partition set and file name filter to find data files. We also have to scan the effective set of data files. The applicable data file will have to be either in the base file set or in the ANY snapshot after that including REWRITEs that we ignore while selecting changelog snapshots. Therefore, we will have to check compaction outputs, newly added files in the changelog range and potentially the base set of data files (filtered by affected files and partitions).
This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the [email protected] list. Thank you for your contributions.
A much needed feature!
Getting to this in next few days, still remember.
@talatuyarer @aokolnychyi will it be much easier if we only support v3+ tables with deletion vector, supposing deprecation of position/equality deletes over time?
I went through the approach and it seems working. I had a slightly different mental model in my head where we would potentially do more upfront but simplify the rest of the logic. I am not sure it would be any better, though. Give me a few days to think about it and I will report back.