Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 50 additions & 0 deletions crates/iceberg/src/transaction/append.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand All @@ -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();
Expand Down
9 changes: 9 additions & 0 deletions crates/iceberg/src/transaction/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading