Fix issue #3758: upsert duplicates/stales rows on temporal-transform-… - #3775
Open
amitpoorab wants to merge 1 commit into
Open
Fix issue #3758: upsert duplicates/stales rows on temporal-transform-…#3775amitpoorab wants to merge 1 commit into
amitpoorab wants to merge 1 commit into
Conversation
…sform-partitioned tables Regression: On a partitioned table with temporal transforms (day/month/year/hour), upsert operations were leaving replaced rows in place and duplicating untouched rows, silently. This was a regression from v0.11.1. Root cause: Manifest pruning optimization (PR apache#3011) uses a predicate built from partition VALUES aliased onto SOURCE COLUMN names, which causes false negatives for non-identity transforms during manifest evaluation. For temporal transforms, a day-ordinal (e.g. 20455) gets misinterpreted as microseconds-since-epoch and produces a wildly different partition value when re-transformed, causing the manifest evaluator to wrongly conclude 'this manifest cannot match' and skip it, leaving stale rows in place. Fix: Restrict the manifest pruning optimization to identity-transform-only specs. For non-identity transforms, fall back to the pre-apache#3011 behavior of always opening manifests and checking exact file identity, which is provably correct. This mirrors an existing guard in dynamic_partition_overwrite. Performance: identity-partitioned tables keep the apache#3011 speedup; non-identity specs revert to 0.11.1 perf (slower but correct). Added: parametrized regression test covering identity, day, month, year, hour, and bucket transforms to prevent re-regression.
kevinjqliu
reviewed
Aug 10, 2026
|
|
||
| # Manifest does not contain rows that match the files to delete partitions | ||
| if not manifest_evaluators[manifest_file.partition_spec_id](manifest_file): | ||
| if spec_is_identity_only and not manifest_evaluators[manifest_file.partition_spec_id](manifest_file): |
Contributor
There was a problem hiding this comment.
i dont think this is the right solution. we should fix the underlying issue instead of special casing for identity transform
Collaborator
There was a problem hiding this comment.
Agree on this. spec_is_identity_only additionally raises questions about what happens when there's a mixture of identity / non-identity transforms.
Author
There was a problem hiding this comment.
Got it. This is just a temp to fix. Agree we need fix underlying issue. I'll open another PR.
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.
…partitioned tables
Regression: On a partitioned table with temporal transforms (day/month/year/hour), upsert operations were leaving replaced rows in place and duplicating untouched rows, silently. This was a regression from v0.11.1.
Root cause: Manifest pruning optimization (PR #3011) uses a predicate built from partition VALUES aliased onto SOURCE COLUMN names, which causes false negatives for non-identity transforms during manifest evaluation. For temporal transforms, a day-ordinal (e.g. 20455) gets misinterpreted as microseconds-since-epoch and produces a wildly different partition value when re-transformed, causing the manifest evaluator to wrongly conclude 'this manifest cannot match' and skip it, leaving stale rows in place.
Fix: Restrict the manifest pruning optimization to identity-transform-only specs. For non-identity transforms, fall back to the pre-#3011 behavior of always opening manifests and checking exact file identity, which is provably correct. This mirrors an existing guard in dynamic_partition_overwrite.
Performance: identity-partitioned tables keep the #3011 speedup; non-identity specs revert to 0.11.1 perf (slower but correct).
Added: parametrized regression test covering identity, day, month, year, hour, and bucket transforms to prevent re-regression.
Rationale for this change
On partitioned tables with temporal transforms (day/month/year/hour), upsert() was silently
corrupting data: leaving replaced rows in place and duplicating untouched rows.
Root cause: PR #3011 added a manifest pruning optimization that builds predicates by aliasing
partition VALUES onto SOURCE COLUMN names. This causes type mismatches for non-identity
transforms during manifest evaluation, resulting in false negatives that skip the exact
identity checks — leaving stale data behind.
Fix: Restrict the manifest pruning optimization to identity-transform-only specs.
Non-identity specs fall back to the proven-correct pre-#3011 behavior (slower but correct).
Are these changes tested?
Yes. Added a parametrized regression test covering identity, day, month, year, hour,
and bucket transforms. The test appends 2 rows sharing a partition, upserts 1 row,
and verifies no duplicates or stale rows remain.
All 28 upsert tests pass (22 existing + 6 new regression tests).
Are there any user-facing changes?
Yes. This fixes a data corruption bug (regression from v0.11.1) in upsert() on
temporal-partitioned tables. Users with such tables will now get correct results instead
of silent data loss.
Performance: Identity-partitioned tables retain the #3011 optimization. Non-identity
specs revert to v0.11.1 performance (slower but correct).