Skip to content

fix: support fast append across partition specs - #3662

Merged
CTTY merged 2 commits into
apache:mainfrom
szehon-ho:issue-3500-group-files-by-spec
Nov 12, 2026
Merged

CTTY merged 2 commits into
apache:mainfrom
szehon-ho:issue-3500-group-files-by-spec

Conversation

@szehon-ho

@szehon-ho szehon-ho commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

Which issue does this PR close?

Closes #3500.

What changes are included in this PR?

Allow fast append to use any partition spec retained by the table, so files written under spec 0 can still commit after the default changes to spec 1. Write added files in separate manifests by spec and use each file's spec for validation and partition summaries. Validation errors identify the file, and retries explicitly reject cached manifests whose specs were removed. No public API changes.

Are these changes tested?

Unit tests cover mixed-spec appends in v1/v2/v3, unknown specs, incompatible partition values, duplicate paths, manifest reuse and summaries after the default spec changes, removed specs during retries, and multi-spec retries across a v1-to-v2 format upgrade.

  • cargo test -p iceberg --lib transaction::: 111 passed.
  • cargo clippy -p iceberg --all-targets --all-features -- -D warnings
  • cargo fmt --all -- --check
  • Public API generation with cargo-public-api 0.51.0: no API changes.

AI Disclosure

Codex assisted with implementation and tests; Isaac (Claude) reviewed the initial change. Review focus: partition attribution in summaries and cached-manifest validity across retries. Support for appending after a partition source column is dropped is deferred to a follow-up.

Copilot AI balanced review requested due to automatic review settings November 10, 2026 01:29
// TODO(#3500): group the files by partition spec and write one
// manifest per group.
// BTreeMap keeps added manifests in deterministic partition spec order.
let mut files_by_spec: BTreeMap<i32, Vec<&DataFile>> = BTreeMap::new();

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

note: this is a bit different than java (hashmap) but explicitly specified in #3500 :)

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Valid appends under a retained partition spec are rejected after its source column is dropped; validation, manifest writing, and added-file summaries need a retained schema, with regression coverage.

1 open issue
What changed in this PR

This PR addresses #3500 by allowing fast append to use retained partition specs, so changing the default spec does not prevent older-spec files from committing.

Changes:

  • Validate files against their own partition specs and write manifests in deterministic spec order.
  • Use each added file’s spec when calculating snapshot summaries.
  • Add coverage for mixed-spec appends, invalid partitions, duplicate files, manifest reuse, and format-upgrade retries.
File Description
crates/​iceberg/​src/​transaction/​snapshot/​simple.rs Adds per-spec validation and manifest grouping, with retry tests.
crates/​iceberg/​src/​transaction/​snapshot/​mod.rs Attributes added-file summaries to each file’s partition spec.
crates/​iceberg/​src/​transaction/​append.rs Tests mixed-spec appends across v1/v2/v3 and validation failures.

Review effort: Balanced

})?;
validate_partition_value(
data_file.partition(),
&spec.partition_type(metadata.current_schema())?,

@szehon-ho szehon-ho Nov 10, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The rejection described is real, but two points:

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Keeping dropped-source-column support for a follow-up, as agreed in the review.

@szehon-ho

Copy link
Copy Markdown
Member Author

@CTTY @viirya can you help me take a look when you have time ? Thank you!

@viirya viirya left a comment

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.

Thanks @szehon-ho, this looks good. One point worth calling out: the build_summary change fixes an existing crash. Before this PR, a retry that reused the cached manifest after the default spec changed to one with more fields panicked in partition_to_path (data[i] out of bounds). The suggestions inline are non-blocking.

On the Copilot thread: agreed this is fine as a follow-up. One small note: Java's FastAppend doesn't validate partition values at all, so Java accepts that case and we reject it. Rejecting seems like the right default here.

let spec = metadata
.partition_spec_by_id(data_file.partition_spec_id)
.ok_or_else(|| {
invalid_data!("Unknown partition spec id {}", data_file.partition_spec_id)

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.

Now that files from several specs can be mixed, it would help to include the file path in this error and in the incompatible-value error below, e.g. Cannot find partition spec {id} for data file {path} as in Java.

Also, partition_type is now rebuilt for every file. Grouping first and validating each group once would avoid that, and would let write_added_manifest take the resolved spec instead of looking it up again.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

+1 on both points mentioned here

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Added file paths to both errors. Grouping now resolves the spec and partition type once per group and passes the resolved spec to the manifest writer.

@@ -180,28 +178,25 @@ impl SimpleSnapshotProducer {

self.validate_added_data_files(table)?;

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.

On a cache hit we don't check that the cached manifests' specs still exist. If a concurrent commit removes spec 0 (allowed once it's no longer the default), the retry still fails, but only because build_summary can't resolve the spec ("Failed to create snapshot summary."). That's the right outcome, but it happens by accident. Could we check this explicitly here, or at least note it next to the "a spec the table still has" doc on validate_added_data_files?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Added an explicit spec-existence check before reusing cached manifests, with a regression test for removal of a cached spec.

.metadata()
.clone()
.into_builder(None)
.add_default_partition_spec(UnboundPartitionSpec::builder().build())

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.

The retry half of this test still passes if build_summary is reverted to default_partition_spec(), because the new default has fewer fields. Using a default spec with more fields (e.g. the bucket spec from append.rs) and asserting the retried summary would pin the fix to the retry path. The fresh-producer half is already covered by test_fast_append_groups_files_by_partition_spec, so it could go.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The retry now switches to a spec with more fields and compares the summaries. Removed the fresh-producer half.

new_file.clone(),
old_file.clone(),
other_old_file.clone(),
old_file.clone(),

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.

The duplicate inputs here and the already-live check at the end are spec-agnostic and already covered by test_fast_append_dedupes_* and test_validate_files_not_live_sees_files_added_by_rebase. Dropping them would keep this test focused on grouping and the summary.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Removed the duplicate inputs and already-live check so this test focuses on grouping and summaries.

@CTTY CTTY left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the fix and LGTM overall! I've left some comments

let spec = metadata
.partition_spec_by_id(data_file.partition_spec_id)
.ok_or_else(|| {
invalid_data!("Unknown partition spec id {}", data_file.partition_spec_id)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

+1 on both points mentioned here

// manifest per group.
// BTreeMap keeps added manifests in deterministic partition spec order.
let mut files_by_spec: BTreeMap<i32, Vec<&DataFile>> = BTreeMap::new();
for file in &self.intent.data_files {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

we are iterating the data_files from intent twice. Once in validate_added_data_files and another time here. how about having validated_added_data_files return Result<files_by_spec> directly?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Changed validated_added_data_files to return the validated groups with their resolved specs, which are passed directly to manifest writing.

@szehon-ho

Copy link
Copy Markdown
Member Author

@CTTY @viirya can you take another look when you have a chance? Thanks!

@CTTY CTTY left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM!

@CTTY
CTTY added this pull request to the merge queue Nov 12, 2026
Merged via the queue into apache:main with commit 5b1fa2e Nov 12, 2026
25 checks passed
@viirya

viirya commented Nov 12, 2026

Copy link
Copy Markdown
Member

Thanks @szehon-ho, the updates address everything. LGTM!

@szehon-ho

Copy link
Copy Markdown
Member Author

Thank you both for great review!

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.

Group added data files by partition spec in SimpleSnapshotProducer

4 participants