Skip to content

Fix issue #3758: upsert duplicates/stales rows on temporal-transform-… - #3775

Open
amitpoorab wants to merge 1 commit into
apache:mainfrom
amitpoorab:fix/3758-manifest-pruning-guard
Open

Fix issue #3758: upsert duplicates/stales rows on temporal-transform-…#3775
amitpoorab wants to merge 1 commit into
apache:mainfrom
amitpoorab:fix/3758-manifest-pruning-guard

Conversation

@amitpoorab

Copy link
Copy Markdown

…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).

…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.

# 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):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

i dont think this is the right solution. we should fix the underlying issue instead of special casing for identity transform

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.

Agree on this. spec_is_identity_only additionally raises questions about what happens when there's a mixture of identity / non-identity transforms.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Got it. This is just a temp to fix. Agree we need fix underlying issue. I'll open another PR.

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.

3 participants