You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iceberg.apache.org by fo...@apache.org on 2025/04/04 19:07:47 UTC

(iceberg-python) branch main updated: Add support for `Transaction.update_statistics()` (#1831)

This is an automated email from the ASF dual-hosted git repository.

fokko pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg-python.git


The following commit(s) were added to refs/heads/main by this push:
     new da403d24 Add support for `Transaction.update_statistics()` (#1831)
da403d24 is described below

commit da403d24112c93eaef92b5bf854634b0144f2853
Author: Srinivas Lade <sr...@gmail.com>
AuthorDate: Fri Apr 4 15:07:43 2025 -0400

    Add support for `Transaction.update_statistics()` (#1831)
    
    # Rationale for this change
    
    Addd a new API `Transaction.update_statistics()` to use the existing
    transaction instead of a brand new one.
    
    # Are these changes tested?
    
    I extended
    `tests/integration/test_statistics_operations.py::test_manage_statistics`
    to test the new API.
    
    # Are there any user-facing changes?
    
    Users can now update statistics files within an ongoing transaction.
---
 pyiceberg/table/__init__.py                     | 9 +++++++++
 tests/integration/test_statistics_operations.py | 7 +++++++
 2 files changed, 16 insertions(+)

diff --git a/pyiceberg/table/__init__.py b/pyiceberg/table/__init__.py
index 1ebdd8bc..8f7b45f5 100644
--- a/pyiceberg/table/__init__.py
+++ b/pyiceberg/table/__init__.py
@@ -438,6 +438,15 @@ class Transaction:
         """
         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.
diff --git a/tests/integration/test_statistics_operations.py b/tests/integration/test_statistics_operations.py
index a7b4e388..09273768 100644
--- a/tests/integration/test_statistics_operations.py
+++ b/tests/integration/test_statistics_operations.py
@@ -82,3 +82,10 @@ def test_manage_statistics(catalog: "Catalog", arrow_table_with_null: "pa.Table"
         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