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
9 changes: 9 additions & 0 deletions crates/iceberg/src/spec/snapshot_summary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const TOTAL_RECORDS: &str = "total-records";
const TOTAL_FILE_SIZE: &str = "total-files-size";
const CHANGED_PARTITION_COUNT_PROP: &str = "changed-partition-count";
const CHANGED_PARTITION_PREFIX: &str = "partitions.";
const ICEBERG_VERSION_PROP: &str = "iceberg-version";

/// `SnapshotSummaryCollector` collects and aggregates snapshot update metrics.
/// It gathers metrics about added or removed data files and manifests, and tracks
Expand Down Expand Up @@ -330,6 +331,14 @@ where T: PartialOrd + Default + ToString {
}
}

pub(crate) fn set_iceberg_version(properties: &mut HashMap<String, String>) {
Comment thread
kevinjqliu marked this conversation as resolved.
let version = env!("CARGO_PKG_VERSION");
properties.insert(
ICEBERG_VERSION_PROP.to_string(),
format!("Apache Iceberg Rust {version}"),
Comment thread
kevinjqliu marked this conversation as resolved.
);
}
Comment thread
kevinjqliu marked this conversation as resolved.

pub(crate) fn update_snapshot_summaries(
summary: Summary,
previous_summary: Option<&Summary>,
Expand Down
31 changes: 31 additions & 0 deletions crates/iceberg/src/transaction/append.rs
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,37 @@ mod tests {
);
}

#[tokio::test]
async fn test_snapshot_summary_records_writer_identity() {
let table = make_v2_minimal_table();
let tx = Transaction::new(&table);

let snapshot_properties = HashMap::from([
("key".to_string(), "val".to_string()),
("iceberg-version".to_string(), "caller".to_string()),
]);

let action = tx
.fast_append()
.set_snapshot_properties(snapshot_properties);
let mut action_commit = commit_with_fresh_state(action, &table).await.unwrap();
let updates = action_commit.take_updates();

let new_snapshot = if let TableUpdate::AddSnapshot { snapshot } = &updates[0] {
snapshot
} else {
unreachable!()
};
let props = &new_snapshot.summary().additional_properties;
let version = env!("CARGO_PKG_VERSION");

assert_eq!(
props.get("iceberg-version").unwrap(),
&format!("Apache Iceberg Rust {version}")
);
assert_eq!(props.get("key").unwrap(), "val");
}

#[tokio::test]
async fn test_append_snapshot_properties() {
let table = make_v2_minimal_table();
Expand Down
8 changes: 5 additions & 3 deletions crates/iceberg/src/transaction/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use crate::spec::{
DataFile, DataFileFormat, FormatVersion, MAIN_BRANCH, ManifestContentType, ManifestEntry,
ManifestFile, ManifestListWriter, ManifestWriter, ManifestWriterBuilder, Operation,
PartitionSpecRef, SchemaRef, Snapshot, SnapshotReference, SnapshotRetention,
SnapshotSummaryCollector, Struct, StructType, Summary, TableProperties,
SnapshotSummaryCollector, Struct, StructType, Summary, TableProperties, set_iceberg_version,
update_snapshot_summaries,
};
use crate::table::Table;
Expand Down Expand Up @@ -453,11 +453,13 @@ impl<'a> SnapshotProducer<'a> {
additional_properties,
};

update_snapshot_summaries(
let mut summary = update_snapshot_summaries(
summary,
previous_snapshot.map(|s| s.summary()),
snapshot_produce_operation.truncate_full_table(),
)
)?;
set_iceberg_version(&mut summary.additional_properties);
Comment thread
kevinjqliu marked this conversation as resolved.
Ok(summary)
}

fn generate_manifest_list_file_path(&self, attempt: i64) -> Result<String> {
Expand Down
Loading