|
84 | 84 | SnapshotLogEntry, |
85 | 85 | ) |
86 | 86 | from pyiceberg.table.sorting import UNSORTED_SORT_ORDER, SortOrder |
87 | | -from pyiceberg.table.statistics import StatisticsFile |
88 | 87 | from pyiceberg.table.update import ( |
89 | 88 | AddPartitionSpecUpdate, |
90 | 89 | AddSchemaUpdate, |
|
95 | 94 | AssertTableUUID, |
96 | 95 | AssignUUIDUpdate, |
97 | 96 | RemovePropertiesUpdate, |
98 | | - RemoveStatisticsUpdate, |
99 | 97 | SetCurrentSchemaUpdate, |
100 | 98 | SetDefaultSortOrderUpdate, |
101 | 99 | SetDefaultSpecUpdate, |
102 | 100 | SetLocationUpdate, |
103 | 101 | SetPropertiesUpdate, |
104 | 102 | SetSnapshotRefUpdate, |
105 | | - SetStatisticsUpdate, |
106 | 103 | TableRequirement, |
107 | 104 | TableUpdate, |
108 | 105 | UpdatesAndRequirements, |
|
119 | 116 | _OverwriteFiles, |
120 | 117 | ) |
121 | 118 | from pyiceberg.table.update.spec import UpdateSpec |
| 119 | +from pyiceberg.table.update.statistics import UpdateStatistics |
122 | 120 | from pyiceberg.typedef import ( |
123 | 121 | EMPTY_DICT, |
124 | 122 | IcebergBaseModel, |
@@ -666,42 +664,6 @@ def update_location(self, location: str) -> Transaction: |
666 | 664 | """ |
667 | 665 | raise NotImplementedError("Not yet implemented") |
668 | 666 |
|
669 | | - def set_statistics(self, snapshot_id: int, statistics_file: StatisticsFile) -> Transaction: |
670 | | - """Set the statistics for a snapshot. |
671 | | -
|
672 | | - Args: |
673 | | - snapshot_id: The snapshot ID to set the statistics for. |
674 | | - statistics_file: The statistics file to set. |
675 | | -
|
676 | | - Returns: |
677 | | - The alter table builder. |
678 | | - """ |
679 | | - updates = ( |
680 | | - SetStatisticsUpdate( |
681 | | - snapshot_id=snapshot_id, |
682 | | - statistics=statistics_file, |
683 | | - ), |
684 | | - ) |
685 | | - |
686 | | - return self._apply(updates, ()) |
687 | | - |
688 | | - def remove_statistics(self, snapshot_id: int) -> Transaction: |
689 | | - """Remove the statistics for a snapshot. |
690 | | -
|
691 | | - Args: |
692 | | - snapshot_id: The snapshot ID to remove the statistics for. |
693 | | -
|
694 | | - Returns: |
695 | | - The alter table builder. |
696 | | - """ |
697 | | - updates = ( |
698 | | - RemoveStatisticsUpdate( |
699 | | - snapshot_id=snapshot_id, |
700 | | - ), |
701 | | - ) |
702 | | - |
703 | | - return self._apply(updates, ()) |
704 | | - |
705 | 667 | def commit_transaction(self) -> Table: |
706 | 668 | """Commit the changes to the catalog. |
707 | 669 |
|
@@ -1021,6 +983,23 @@ def manage_snapshots(self) -> ManageSnapshots: |
1021 | 983 | """ |
1022 | 984 | return ManageSnapshots(transaction=Transaction(self, autocommit=True)) |
1023 | 985 |
|
| 986 | + def update_statistics(self) -> UpdateStatistics: |
| 987 | + """ |
| 988 | + Shorthand to run statistics management operations like add statistics and remove statistics. |
| 989 | +
|
| 990 | + Use table.update_statistics().<operation>().commit() to run a specific operation. |
| 991 | + Use table.update_statistics().<operation-one>().<operation-two>().commit() to run multiple operations. |
| 992 | +
|
| 993 | + Pending changes are applied on commit. |
| 994 | +
|
| 995 | + We can also use context managers to make more changes. For example: |
| 996 | +
|
| 997 | + with table.update_statistics() as update: |
| 998 | + update.set_statistics(snapshot_id=1, statistics_file=statistics_file) |
| 999 | + update.remove_statistics(snapshot_id=2) |
| 1000 | + """ |
| 1001 | + return UpdateStatistics(transaction=Transaction(self, autocommit=True)) |
| 1002 | + |
1024 | 1003 | def update_schema(self, allow_incompatible_changes: bool = False, case_sensitive: bool = True) -> UpdateSchema: |
1025 | 1004 | """Create a new UpdateSchema to alter the columns of this table. |
1026 | 1005 |
|
|
0 commit comments