Skip to content

feat(writer): add change-type splitter for delta writes - #3231

Open
laskoviymishka wants to merge 1 commit into
apache:mainfrom
laskoviymishka:feat/delta-ops-splitter
Open

laskoviymishka wants to merge 1 commit into
apache:mainfrom
laskoviymishka:feat/delta-ops-splitter

Conversation

@laskoviymishka

Copy link
Copy Markdown
Contributor

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.

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
laskoviymishka marked this pull request as ready for review September 15, 2026 20:02
//!
//! 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>).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: consider trimming the link to epic etc.

/// `_change_type` column removed. Field metadata (including Parquet field ids)
/// and the schema-level metadata are preserved.
#[derive(Debug)]
pub struct SplitBatches {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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?

//!
//! [`RecordBatch`]: arrow_array::RecordBatch

// The building blocks here are wired into the DeltaWriter in a later PR (#2218),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: Suggest dropping these, as these will go stale pretty soon.

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<_>>();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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)?;

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.

2 participants