diff --git a/Cargo.lock b/Cargo.lock index c120f53896..6528d13f65 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 9a3c970aa4..d3b3cb2e3a 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, + ) -> 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 4211b4f138..012fb52bb5 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, + ) -> Result<&mut Self> { + self.snapshot_properties = snapshot_properties; + Ok(self) + } + /// Add data files to the snapshot. pub fn add_data_files( &mut self,