You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor: consolidate snapshot expiration into MaintenanceTable (#2143)
<!--
Thanks for opening a pull request!
-->
<!-- Closes#2150 -->
# Rationale for this change
- Consolidates snapshot expiration functionality from the standalone
`ExpireSnapshots` class into the `MaintenanceTable` class for a unified
maintenance API.
- Resolves planned work left over from #1880, and closes#2142
- Achieves feature and API parity with the Java implementation for
snapshot retention and table maintenance.
# Features & Enhancements
- Introduces `table.maintenance.expire_snapshots()` as the unified entry
point for snapshot expiration and future maintenance operations.
- Retains the existing `ExpireSnapshots` implementation internally. The
`expire_snapshots()` method on `MaintenanceTable` now returns an
`ExpireSnapshots` object, preserving transaction semantics and
supporting context manager usage:
```python
with table.maintenance.expire_snapshots() as expire_snapshots:
expire_snapshots.by_id(1)
expire_snapshots.by_id(2)
```
- Focuses this PR on refactoring and documentation improvements, while
maintaining compatibility with the prior `ExpireSnapshots` interface.
- Sets a foundation for future expansion of the `MaintenanceTable`
abstraction to encapsulate additional maintenance operations.
# Bug Fixes & Cleanups
- **ManageSnapshots Cleanup
([#2151](#2151
- Removes an unrelated instance variable from the `ManageSnapshots`
class, aligning with the Java reference implementation.
# Testing & Documentation
- **Testing:**
- Tested the new API interface including:
- Expiration by ID
- Protection of branch/tag snapshots
- **Documentation:**
- Added and updated documentation to describe:
- API usage examples
Preview:
<img width="1686" height="1015" alt="Screenshot 2025-08-11 at 1 37
04 PM"
src="https://github.com/user-attachments/assets/f469f3fc-b4b1-4ec9-b1ca-b9185e22643e"
/>
# Are these changes tested?
Yes. All changes are tested.~, with this PR predicated on the final
changes from #1200.~ This work builds on the framework introduced by
@jayceslesar in #1200 for the `MaintenanceTable`.
# Are there any user-facing changes?
---
**Closes:**
- Closes#2151
- Closes#2142
---------
Co-authored-by: Fokko Driesprong <[email protected]>
Co-authored-by: Kevin Liu <[email protected]>
PyIceberg provides table maintenance operations through the `table.maintenance` API. This provides a clean interface for performing maintenance tasks like snapshot expiration.
1293
+
1294
+
### Snapshot Expiration
1295
+
1296
+
Expire old snapshots to clean up table metadata and reduce storage costs:
0 commit comments