From 64dfe568f4e9697ebb8cf9e0b451f58e600f25c1 Mon Sep 17 00:00:00 2001 From: Srinivas Lade Date: Sat, 22 Mar 2025 13:05:56 -0400 Subject: [PATCH 1/2] implement update_statistics on transaction --- pyiceberg/table/__init__.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pyiceberg/table/__init__.py b/pyiceberg/table/__init__.py index cab5d73d27..7e4669bbed 100644 --- a/pyiceberg/table/__init__.py +++ b/pyiceberg/table/__init__.py @@ -438,6 +438,15 @@ def update_snapshot(self, snapshot_properties: Dict[str, str] = EMPTY_DICT) -> U """ return UpdateSnapshot(self, io=self._table.io, snapshot_properties=snapshot_properties) + def update_statistics(self) -> UpdateStatistics: + """ + Create a new UpdateStatistics to update the statistics of the table. + + Returns: + A new UpdateStatistics + """ + return UpdateStatistics(transaction=self) + def append(self, df: pa.Table, snapshot_properties: Dict[str, str] = EMPTY_DICT) -> None: """ Shorthand API for appending a PyArrow table to a table transaction. From 28253cb174ca5168ce8564269dc342d305dacc68 Mon Sep 17 00:00:00 2001 From: Srinivas Lade Date: Sat, 22 Mar 2025 13:18:28 -0400 Subject: [PATCH 2/2] update test --- tests/integration/test_statistics_operations.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/integration/test_statistics_operations.py b/tests/integration/test_statistics_operations.py index a7b4e38802..09273768d9 100644 --- a/tests/integration/test_statistics_operations.py +++ b/tests/integration/test_statistics_operations.py @@ -82,3 +82,10 @@ def create_statistics_file(snapshot_id: int, type_name: str) -> StatisticsFile: update.remove_statistics(add_snapshot_id_1) assert len(tbl.metadata.statistics) == 1 + + with tbl.transaction() as txn: + with txn.update_statistics() as update: + update.set_statistics(statistics_file_snap_1) + update.set_statistics(statistics_file_snap_2) + + assert len(tbl.metadata.statistics) == 2