feat: add delta writer for row-level changes#2219
feat: add delta writer for row-level changes#2219DAlperin wants to merge 1 commit intoapache:mainfrom
Conversation
This commit adds support for row-level changes (inserts, updates, and deletes) to Iceberg tables through a new DeltaWriter implementation. This enables CDC (Change Data Capture), upsert operations, and efficient row-level deletions. Key Components: 1. RowDeltaAction Transaction - New transaction type for applying row-level changes atomically - Supports both data files and delete files in a single transaction - Located in transaction/row_delta.rs 2. Position Delete Writer - Writes position delete files for efficient row-level deletions - Deletes rows by file path and row position - Located in writer/base_writer/position_delete_writer.rs 3. Delta Writer (Combined Writer) - Orchestrates data file, position delete, and equality delete writers - Intelligently routes operations based on row tracking - Memory-bounded row tracking with configurable limits - Falls back to equality deletes for older/evicted rows - Located in writer/combined_writer/delta_writer.rs Input Format: The DeltaWriter expects RecordBatch with an operations column: - Value 1 = Insert/Update (write to data file) - Value -1 = Delete (write to delete file) Memory Management: - Tracks recently written rows for efficient position deletes - Configurable max_seen_rows limit (default: 100,000) - FIFO eviction when limit is reached - Can be disabled (set to 0) to use only equality deletes
vustef
left a comment
There was a problem hiding this comment.
Thanks @DAlperin. I've put some high-level comments. Hoping mostly that @liurenjie1024 has some time to review this or to delegate to some other maintainer who's also more familiar.
There was a problem hiding this comment.
apparently this file is missing a license header
There was a problem hiding this comment.
Can you please run cargo fmt --all with a corresponding cargo version
| }) | ||
| .build()?; | ||
|
|
||
| println!( |
There was a problem hiding this comment.
I assume you used this for some debugging and it should be removed?
There was a problem hiding this comment.
Given that his change is bigger, and smaller changes are more manageable, my 2c is to help the other PR (#2203) by reviewing it, and then potentially building upon it.
| } | ||
| } | ||
|
|
||
| struct RowDeltaOperation; |
There was a problem hiding this comment.
The action in the other PR supports deleting data files (I assume for copy-on-write updates and for data file deletes). It'd be good to have that. What do you think?
| /// - pos: long (field id 2147483545) | ||
| pub fn arrow_schema() -> ArrowSchemaRef { | ||
| Arc::new(ArrowSchema::new(vec![ | ||
| Field::new("file_path", DataType::Utf8, false).with_metadata( |
There was a problem hiding this comment.
We have consts for this: RESERVED_COL_NAME_DELETE_FILE_PATH. And RESERVED_FIELD_ID_DELETE_FILE_PATH for field ID.
Or rather, whole FILE_PATH_FIELD can be reused perhaps. Same for pos
There was a problem hiding this comment.
I'm curious what is @liurenjie1024's opinion on where this thing should live.
This is higher level API than e.g. position delete writer or equality delete writer. It is not the only possible choice of combining these (e.g. some might want to switch to copy-on-write if more than 10% of file is changed, alike to Snowflake's heuristic here: https://docs.snowflake.com/en/user-guide/tables-iceberg-manage#usage-notes-for-deletion-vectors). Therefore, it might not generalize well, and perhaps it should either be part of some other crate, or perhaps structured in a way so that there's a factory of different higher-level writers based on different strategies, possibly extensible outside of iceberg-rust.
I still think there's value in this being in this repository, otherwise other people will have a hard time discovering and reusing functionality that they like.
Another thing to note is that if we're writing Iceberg V3 in future, we shouldn't write positional delete files but delete vectors.
Which issue does this PR close?
Closes #2218
What changes are included in this PR?
This PR adds support for row-level changes (inserts, updates, and deletes) to Iceberg tables through a new DeltaWriter implementation. This enables CDC (Change Data Capture), upsert operations, and efficient row-level deletions.
Key Components:
RowDeltaAction Transaction (could be supplanted by feat(transaction): add RowDelta transaction action for row-level modi… #2203
Position Delete Writer
Delta Writer (Combined Writer)
Input Format:
The DeltaWriter expects RecordBatch with an operations column:
Memory Management:
Are these changes tested?
Unit tests for each new writer are added.