Skip to content

fix: include NULL in delete predicate for evolved partition fields in dynamic_partition_overwrite#3460

Open
GayathriSrividya wants to merge 1 commit into
apache:mainfrom
GayathriSrividya:fix/issue-3148-partition-spec-evolution
Open

fix: include NULL in delete predicate for evolved partition fields in dynamic_partition_overwrite#3460
GayathriSrividya wants to merge 1 commit into
apache:mainfrom
GayathriSrividya:fix/issue-3148-partition-spec-evolution

Conversation

@GayathriSrividya

Copy link
Copy Markdown
Contributor

Closes #3148

Root cause

dynamic_partition_overwrite builds its delete predicate using the current partition spec only:

delete_filter = self._build_partition_predicate(
    partition_records=partitions_to_overwrite,
    spec=self.table_metadata.spec(),   # always current spec
    schema=self.table_metadata.schema(),
)

After a partition spec evolution (e.g. adding a region field), data files written under the older spec carry NULL for the new field — because region simply wasn't part of the schema at write time.

The predicate produced for the new partition {category=A, region=us} is:

category = 'A' AND region = 'us'

The _StrictMetricsEvaluator correctly sees that spec-0 files have region = NULL for every row, so region = 'us' can never be ROWS_MUST_MATCH. Those files are silently kept, leaving stale data behind.

Fix

Detect which fields in the current spec were absent from at least one historical spec ("evolved" fields). For those fields, extend the per-field clause to also accept NULL:

category = 'A' AND (region = 'us' OR region IS NULL)

This causes the metrics evaluator to flag pre-evolution files (all-null region) as ROWS_MUST_MATCH and delete them, while correctly preserving files in other non-overlapping partitions (e.g. region = 'eu').

Verification

Added two unit tests for _build_partition_predicate (with / without evolved_source_ids) and manually confirmed the repro from the issue now produces [999] instead of [1, 2, 999].

make lint  ✓
pytest tests/table/  ✓  (304 passed)

@Fokko

Fokko commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

@GayathriSrividya Thanks for opening this PR, but I think you've pulled in some unrelated commits here

@GayathriSrividya

Copy link
Copy Markdown
Contributor Author

@GayathriSrividya Thanks for opening this PR, but I think you've pulled in some unrelated commits here

Thanks, @Fokko. Could you please point out which commits look unrelated? I’ll clean up the branch and keep this PR focused only on the #3148 fix. Or I will close this and open fresh PR

@Fokko

Fokko commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

@GayathriSrividya

The changes around making the list operations return an iterator:

image

@GayathriSrividya

Copy link
Copy Markdown
Contributor Author

@GayathriSrividya

The changes around making the list operations return an iterator:

image

Okay, noted. Sorry for the extra commits.

I’ll make clean changes and open a PR from a different branch. Please give me some time.

@github-actions

Copy link
Copy Markdown

This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that's incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@iceberg.apache.org list. Thank you for your contributions.

@github-actions github-actions Bot added the stale label Jul 11, 2026
@GayathriSrividya GayathriSrividya force-pushed the fix/issue-3148-partition-spec-evolution branch from 0567a6e to e015a56 Compare July 14, 2026 06:46
@GayathriSrividya

Copy link
Copy Markdown
Contributor Author

@GayathriSrividya

The changes around making the list operations return an iterator:

image

Updated this PR with a clean history and removed unrelated iterator commits.
Could you please take another look?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: dynamic_partition_overwrite silently skips spec-0 manifests after partition spec evolution

2 participants