Skip to content

feat: add delta writer for row-level changes#2219

Open
DAlperin wants to merge 1 commit intoapache:mainfrom
MaterializeInc:upstream/delta-writer
Open

feat: add delta writer for row-level changes#2219
DAlperin wants to merge 1 commit intoapache:mainfrom
MaterializeInc:upstream/delta-writer

Conversation

@DAlperin
Copy link

@DAlperin DAlperin commented Mar 6, 2026

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:

  1. RowDeltaAction Transaction (could be supplanted by feat(transaction): add RowDelta transaction action for row-level modi… #2203

    • 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

Are these changes tested?

Unit tests for each new writer are added.

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
Copy link

@vustef vustef left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apparently this file is missing a license header

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please run cargo fmt --all with a corresponding cargo version

})
.build()?;

println!(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume you used this for some debugging and it should be removed?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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.

Support for a DeltaWriter

2 participants