feat(writer): add change-type splitter for delta writes - #3231
Open
laskoviymishka wants to merge 1 commit into
Open
laskoviymishka wants to merge 1 commit into
laskoviymishka wants to merge 1 commit into
Conversation
Introduce the delta_writer module as the first building block for the DeltaWriter epic (apache#2218). Its record_ops::split_by_change_type takes a RecordBatch carrying the repo's _change_type column and splits it into separate insert and delete batches. The _change_type column is located by name (RESERVED_COL_NAME_CHANGE_TYPE), wherever it sits in the schema, and must be a non-nullable Utf8 column whose values are all one of the four spec change types. Following Java's BaseDeltaTaskWriter, INSERT and UPDATE_AFTER rows collapse to inserts while DELETE and UPDATE_BEFORE rows collapse to deletes. The _change_type column is stripped from both outputs, preserving each payload column's field-id metadata and the schema-level metadata; input row order is preserved within each side. Anything violating the contract (missing/mistyped/nullable/null/out-of-domain _change_type, or no payload columns) is rejected as DataInvalid. The module is pub(crate) since nothing wires it into a writer yet (that lands in a later PR of the epic).
laskoviymishka
marked this pull request as ready for review
September 15, 2026 20:02
anoopj
reviewed
Sep 16, 2026
| //! | ||
| //! A delta writer consumes a stream of row-level changes (inserts and deletes) | ||
| //! and produces both data files and delete files in a single pass. This is the | ||
| //! foundation for the `DeltaWriter` epic (see <https://github.com/apache/iceberg-rust/issues/2218>). |
Member
There was a problem hiding this comment.
Nit: consider trimming the link to epic etc.
anoopj
reviewed
Sep 16, 2026
| /// `_change_type` column removed. Field metadata (including Parquet field ids) | ||
| /// and the schema-level metadata are preserved. | ||
| #[derive(Debug)] | ||
| pub struct SplitBatches { |
Member
There was a problem hiding this comment.
This class and the fields are all pub, but the parent (delta_writer) is crate-internal. Also not consistent with the constants above. Should they be pub(crate) and widen when we actually use it?
anoopj
reviewed
Sep 16, 2026
| //! | ||
| //! [`RecordBatch`]: arrow_array::RecordBatch | ||
|
|
||
| // The building blocks here are wired into the DeltaWriter in a later PR (#2218), |
Member
There was a problem hiding this comment.
Nit: Suggest dropping these, as these will go stale pretty soon.
anoopj
reviewed
Sep 16, 2026
Comment on lines
+207
to
+224
| let payload_fields = schema | ||
| .fields() | ||
| .iter() | ||
| .enumerate() | ||
| .filter(|(idx, _)| *idx != change_type_idx) | ||
| .map(|(_, field)| field.clone()) | ||
| .collect::<Vec<_>>(); | ||
| let payload_schema = Arc::new(Schema::new_with_metadata( | ||
| payload_fields, | ||
| schema.metadata().clone(), | ||
| )); | ||
| let payload_columns = batch | ||
| .columns() | ||
| .iter() | ||
| .enumerate() | ||
| .filter(|(idx, _)| *idx != change_type_idx) | ||
| .map(|(_, column)| column.clone()) | ||
| .collect::<Vec<_>>(); |
Member
There was a problem hiding this comment.
This reimplements RecordBatch::project. You could just do something like:
let payload_indices: Vec<usize> = (0..batch.num_columns())
.filter(|idx| *idx != change_type_idx)
.collect();
let payload = batch.project(&payload_indices)?;
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Introduce the delta_writer module as the first building block for the DeltaWriter epic (#2218). Its record_ops::split_by_change_type takes a RecordBatch carrying the repo's _change_type column and splits it into separate insert and delete batches.
The _change_type column is located by name (RESERVED_COL_NAME_CHANGE_TYPE), wherever it sits in the schema, and must be a non-nullable Utf8 column whose values are all one of the four spec change types. Following Java's BaseDeltaTaskWriter, INSERT and UPDATE_AFTER rows collapse to inserts while DELETE and UPDATE_BEFORE rows collapse to deletes. The _change_type column is stripped from both outputs, preserving each payload column's field-id metadata and the schema-level metadata; input row order is preserved within each side. Anything violating the contract (missing/mistyped/nullable/null/out-of-domain _change_type, or no payload columns) is rejected as DataInvalid.
The module is pub(crate) since nothing wires it into a writer yet (that lands in a later PR of the epic).
Are these changes tested?
Newly added tests.