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

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


The following commit(s) were added to refs/heads/main by this push:
     new f22c0f9f Add unit tests for UpdateStatisticsAction functionality. 
(#1675)
f22c0f9f is described below

commit f22c0f9f23a18ae75146df138ba72669150e3c00
Author: slfan1989 <[email protected]>
AuthorDate: Thu Sep 25 18:24:47 2025 +0800

    Add unit tests for UpdateStatisticsAction functionality. (#1675)
    
    ## Which issue does this PR close?
    
    - Closes #1676.
    
    ## What changes are included in this PR?
    
    - Added tests for setting and removing statistics files in
    UpdateStatisticsAction.
    - Tests cover scenarios for:
    1. Setting a single statistics file.
    2. Ensuring no statistics are set.
    
    ## Are these changes tested?
    
    Tested locally.
---
 .../iceberg/src/transaction/update_statistics.rs   | 52 ++++++++++++++++++++++
 1 file changed, 52 insertions(+)

diff --git a/crates/iceberg/src/transaction/update_statistics.rs 
b/crates/iceberg/src/transaction/update_statistics.rs
index 636bb0ca..dfce95d8 100644
--- a/crates/iceberg/src/transaction/update_statistics.rs
+++ b/crates/iceberg/src/transaction/update_statistics.rs
@@ -171,4 +171,56 @@ mod tests {
             Some(statistics_file_2)
         );
     }
+
+    #[test]
+    fn test_set_single_statistics() {
+        let table = make_v2_table();
+        let tx = Transaction::new(&table);
+
+        let statistics_file = StatisticsFile {
+            snapshot_id: 1234567890i64,
+            statistics_path: "s3://a/b/stats1.puffin".to_string(),
+            file_size_in_bytes: 500,
+            file_footer_size_in_bytes: 50,
+            key_metadata: None,
+            blob_metadata: vec![],
+        };
+
+        // Set statistics
+        let tx = tx
+            .update_statistics()
+            .set_statistics(statistics_file.clone())
+            .apply(tx)
+            .unwrap();
+
+        let action = (*tx.actions[0])
+            .downcast_ref::<UpdateStatisticsAction>()
+            .unwrap();
+
+        // Verify that the statistics file is set correctly
+        assert_eq!(
+            action
+                .statistics_to_set
+                .get(&statistics_file.snapshot_id)
+                .unwrap()
+                .clone(),
+            Some(statistics_file)
+        );
+    }
+
+    #[test]
+    fn test_no_statistics_set() {
+        let table = make_v2_table();
+        let tx = Transaction::new(&table);
+
+        // No statistics are set or removed
+        let tx = tx.update_statistics().apply(tx).unwrap();
+
+        let action = (*tx.actions[0])
+            .downcast_ref::<UpdateStatisticsAction>()
+            .unwrap();
+
+        // Verify that no statistics are set
+        assert!(action.statistics_to_set.is_empty());
+    }
 }

Reply via email to