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 40b055a7 feat: set snapshot summary property in append action (#1391) 40b055a7 is described below commit 40b055a779365b121ad070b900389d27f8122741 Author: dentiny <dentiny...@gmail.com> AuthorDate: Thu May 29 02:25:27 2025 -0700 feat: set snapshot summary property in append action (#1391) ## Which issue does this PR close? - Closes https://github.com/apache/iceberg-rust/issues/1329 ## What changes are included in this PR? This PR tries to do the same thing as reverted [PR](https://github.com/apache/iceberg-rust/pull/1336), which adds capability to set snapshot summary properties. Followup on thread: https://github.com/apache/iceberg-rust/pull/1336#issuecomment-2915765649, in this PR I took a different way, which expose interfaces within fast append action. ## Are these changes tested? Yes, I add new unit tests. --- Cargo.lock | 2 +- crates/iceberg/src/transaction/append.rs | 50 ++++++++++++++++++++++++++++++ crates/iceberg/src/transaction/snapshot.rs | 9 ++++++ 3 files changed, 60 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index c120f538..6528d13f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3712,7 +3712,7 @@ dependencies = [ "iceberg-catalog-rest", "iceberg-datafusion", "iceberg_test_utils", - "ordered-float 4.6.0", + "ordered-float 2.10.1", "parquet", "tokio", "uuid", diff --git a/crates/iceberg/src/transaction/append.rs b/crates/iceberg/src/transaction/append.rs index 9a3c970a..d3b3cb2e 100644 --- a/crates/iceberg/src/transaction/append.rs +++ b/crates/iceberg/src/transaction/append.rs @@ -72,6 +72,16 @@ impl<'a> FastAppendAction<'a> { Ok(self) } + /// Set snapshot summary properties. + pub fn set_snapshot_properties( + &mut self, + snapshot_properties: HashMap<String, String>, + ) -> Result<&mut Self> { + self.snapshot_produce_action + .set_snapshot_properties(snapshot_properties)?; + Ok(self) + } + /// Adds existing parquet files /// /// Note: This API is not yet fully supported in version 0.5.x. @@ -211,6 +221,8 @@ impl SnapshotProduceOperation for FastAppendOperation { #[cfg(test)] mod tests { + use std::collections::HashMap; + use crate::scan::tests::TableTestFixture; use crate::spec::{ DataContentType, DataFileBuilder, DataFileFormat, Literal, MAIN_BRANCH, Struct, @@ -228,6 +240,44 @@ mod tests { assert!(action.apply().await.is_err()); } + #[tokio::test] + async fn test_set_snapshot_properties() { + let table = make_v2_minimal_table(); + let tx = Transaction::new(&table); + let mut action = tx.fast_append(None, vec![]).unwrap(); + + let mut snapshot_properties = HashMap::new(); + snapshot_properties.insert("key".to_string(), "val".to_string()); + action.set_snapshot_properties(snapshot_properties).unwrap(); + let data_file = DataFileBuilder::default() + .content(DataContentType::Data) + .file_path("test/1.parquet".to_string()) + .file_format(DataFileFormat::Parquet) + .file_size_in_bytes(100) + .record_count(1) + .partition_spec_id(table.metadata().default_partition_spec_id()) + .partition(Struct::from_iter([Some(Literal::long(300))])) + .build() + .unwrap(); + action.add_data_files(vec![data_file]).unwrap(); + let tx = action.apply().await.unwrap(); + + // Check customized properties is contained in snapshot summary properties. + let new_snapshot = if let TableUpdate::AddSnapshot { snapshot } = &tx.updates[0] { + snapshot + } else { + unreachable!() + }; + assert_eq!( + new_snapshot + .summary() + .additional_properties + .get("key") + .unwrap(), + "val" + ); + } + #[tokio::test] async fn test_fast_append_action() { let table = make_v2_minimal_table(); diff --git a/crates/iceberg/src/transaction/snapshot.rs b/crates/iceberg/src/transaction/snapshot.rs index 4211b4f1..012fb52b 100644 --- a/crates/iceberg/src/transaction/snapshot.rs +++ b/crates/iceberg/src/transaction/snapshot.rs @@ -122,6 +122,15 @@ impl<'a> SnapshotProduceAction<'a> { Ok(()) } + /// Set snapshot summary properties. + pub fn set_snapshot_properties( + &mut self, + snapshot_properties: HashMap<String, String>, + ) -> Result<&mut Self> { + self.snapshot_properties = snapshot_properties; + Ok(self) + } + /// Add data files to the snapshot. pub fn add_data_files( &mut self,