fix(transaction): don't let user properties override computed summary metrics#2726
Open
viirya wants to merge 2 commits into
Open
fix(transaction): don't let user properties override computed summary metrics#2726viirya wants to merge 2 commits into
viirya wants to merge 2 commits into
Conversation
… metrics Building a snapshot summary merged the user's `snapshot_properties` on top of the computed metrics, so a caller could overwrite a metric key such as `added-data-files` with an arbitrary value, corrupting the summary. A non-integer value then panicked `update_totals`, which parsed the added/removed deltas with `.expect()`. This matches iceberg-java's behavior on both points (verified against `SnapshotProducer.java` and `SnapshotSummary.java` on `main`): - `SnapshotSummary.Builder.build()` adds custom properties first, then `metrics.addTo(builder)`, so computed metrics win on a key collision. We now apply `snapshot_properties` first and let the computed metrics overwrite them. - `SnapshotProducer.updateTotal` wraps parsing in try/catch and skips the total on a `NumberFormatException`. `update_totals` now tolerates an unparseable added/removed value by skipping that total instead of panicking. Closes apache#2725
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?
What changes are included in this PR?
Building a snapshot summary let a user-supplied snapshot property overwrite a computed metric key, and a non-integer value then panicked total computation. Both are fixed to match iceberg-java.
1. Computed metrics now win over user properties (
transaction/snapshot.rs). Previously:Now the user properties are applied first and the computed metrics overwrite them:
This matches
SnapshotSummary.Builder.build()in iceberg-java, which doesbuilder.putAll(properties)(custom props) first and thenmetrics.addTo(builder), so computed metrics win on a key collision.2.
update_totalstolerates an unparseable delta instead of panicking (spec/snapshot_summary.rs). Theadded-*/removed-*parses used.expect("must be parsable as it was just serialized"). A non-integer value (which can also legitimately come from a previous snapshot's summary) panicked the commit. It now skips that total, matching iceberg-java'sSnapshotProducer.updateTotal, which wraps theLong.parseLongcalls intry { … } catch (NumberFormatException e) { // ignore and do not add total }.Both Java behaviors verified against
apache/icebergmain(core/src/main/java/org/apache/iceberg/SnapshotProducer.java,SnapshotSummary.java).Are these changes tested?
Two new regression tests:
transaction::append::test_snapshot_properties_cannot_override_computed_metrics— a fast-append whosesnapshot_propertiessetadded-data-files=9999andadded-records=<non-integer>commits without panicking, and the resulting summary reports the real computed counts (1), not the user values.spec::snapshot_summary::test_update_totals_tolerates_unparseable_added_value— an unparseableadded-*value skips that one total while sibling totals still compute, with no panic.Both fail if the respective fix is reverted (verified). Full
iceberglib suite (1373 tests) passes, clippy + rustfmt clean.