Repository navigation
fix: support fast append across partition specs - #3662
Conversation
| // 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(); |
There was a problem hiding this comment.
note: this is a bit different than java (hashmap) but explicitly specified in #3500 :)
There was a problem hiding this comment.
🟡 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())?, |
There was a problem hiding this comment.
The rejection described is real, but two points:
- This is not a regression: before this PR, appending under a nondefault spec was rejected altogether. This is an additional edge case in the retained-spec support.
- The proposed historical-schema lookup would go beyond directly mirroring Java FastAppend. Java rebinds retained specs to the current schema, and uses
Unknownwhen a source column has been dropped. Resolving an older schema would follow the existing Rust removed-file summary path.
There was a problem hiding this comment.
Keeping dropped-source-column support for a follow-up, as agreed in the review.
viirya
left a comment
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
+1 on both points mentioned here
There was a problem hiding this comment.
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)?; | |||
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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()) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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(), |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Removed the duplicate inputs and already-live check so this test focuses on grouping and summaries.
CTTY
left a comment
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
+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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Changed validated_added_data_files to return the validated groups with their resolved specs, which are passed directly to manifest writing.
|
Thanks @szehon-ho, the updates address everything. LGTM! |
|
Thank you both for great review! |

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 warningscargo fmt --all -- --checkAI 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.