Skip to content

Remove partition statistics of removed snapshots - #4364

Open
ShivamSharma43 wants to merge 1 commit into
apache:mainfrom
ShivamSharma43:remove-partition-statistics-with-snapshots
Open

ShivamSharma43 wants to merge 1 commit into
apache:mainfrom
ShivamSharma43:remove-partition-statistics-with-snapshots

Conversation

@ShivamSharma43

Copy link
Copy Markdown

Rationale for this change

When a snapshot is removed (RemoveSnapshotsUpdate, which expire_snapshots uses), pyiceberg removes the snapshot's statistics files but keeps its partition statistics files. After expiring a snapshot, the table metadata still has partition-statistics entries pointing at a snapshot that is gone.

Iceberg Java removes both in TableMetadata.Builder.rewriteSnapshotsInternal:

removeStatistics(snapshotId);
removePartitionStatistics(snapshotId);

This adds the same removal for partition statistics, next to the existing one for statistics. A REST catalog server applies the update itself, so you mostly see this with catalogs where pyiceberg writes the metadata (SQL, Glue, Hive, DynamoDB). The test for #4201 works around the same gap by patching commit_table to drop these entries.

I didn't find an existing issue for this.

Are these changes tested?

Yes. I added test_update_remove_snapshots_with_partition_statistics to tests/table/test_expire_snapshots.py, next to the existing statistics test. It fails on main (the partition statistics entry for the removed snapshot is still there) and passes with this change. prek run passes on the changed files.

Are there any user-facing changes?

After expire_snapshots, table metadata no longer lists partition statistics for snapshots that were removed.

AI disclosure

I used Claude Code (AI) to find this gap by comparing pyiceberg with Iceberg Java, and to write the fix and the test. I reviewed the change. One thing I'm not sure about: I kept the removal in the RemoveSnapshotsUpdate handler, applied as internal RemovePartitionStatisticsUpdates the same way the statistics removal already works. I did not add a matching cleanup of the partition statistics files on storage. That belongs with the file-cleanup work in #4201.

🤖 Generated with Claude Code

https://claude.ai/code/session_012XPuJeHi7A5CeHSKHjHmwx

RemoveSnapshotsUpdate dropped the statistics files of removed snapshots
but kept their partition statistics files, so expire_snapshots left
partition-statistics entries that point at snapshots that no longer
exist. Iceberg Java removes both in TableMetadata.Builder.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012XPuJeHi7A5CeHSKHjHmwx
Copilot AI balanced review requested due to automatic review settings November 13, 2026 07:53

Copilot AI left a comment

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

This branch has not been deployed

No deployments
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