Skip to content

Commit 59109b7

Browse files
committed
Append operation summary
1 parent 0e08384 commit 59109b7

2 files changed

Lines changed: 29 additions & 9 deletions

File tree

iceberg-rust/src/table/transaction/append.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use std::cmp::Ordering;
2+
use std::collections::HashMap;
23

3-
use iceberg_rust_spec::{manifest::ManifestEntry, manifest_list::ManifestListEntry};
4-
use smallvec::SmallVec;
4+
use iceberg_rust_spec::{
5+
manifest::ManifestEntry, manifest_list::ManifestListEntry, manifest::Content, manifest::DataFile};
56

67
use crate::{
78
error::Error,
@@ -189,3 +190,24 @@ pub(crate) fn select_manifest_unpartitioned(
189190
})
190191
.ok_or(Error::NotFound("Manifest for insert".to_owned()))
191192
}
193+
194+
195+
pub(crate) fn append_summary(files: &[DataFile]) -> Option<HashMap<String, String>> {
196+
if files.is_empty() {
197+
return None;
198+
}
199+
200+
let (mut added_data_files, mut added_records, mut added_files_size) = (0usize, 0i64, 0i64);
201+
202+
for file in files.iter().filter(|f| *f.content() == Content::Data) {
203+
added_data_files += 1;
204+
added_records += file.record_count();
205+
added_files_size += file.file_size_in_bytes();
206+
}
207+
208+
Some(HashMap::from([
209+
("added-files-size".into(), added_files_size.to_string()),
210+
("added-records".into(), added_records.to_string()),
211+
("added-data-files".into(), added_data_files.to_string()),
212+
]))
213+
}

iceberg-rust/src/table/transaction/mod.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use std::collections::HashMap;
2020
use iceberg_rust_spec::spec::{manifest::DataFile, schema::Schema, snapshot::SnapshotReference};
2121

2222
use crate::{catalog::commit::CommitTable, error::Error, table::Table};
23+
use crate::table::transaction::append::append_summary;
2324

2425
use self::operation::Operation;
2526

@@ -118,15 +119,12 @@ impl<'table> TableTransaction<'table> {
118119
/// .await?;
119120
/// ```
120121
pub fn append_data(mut self, files: Vec<DataFile>) -> Self {
122+
let summary = append_summary(&files);
123+
121124
self.operations
122125
.entry(APPEND_KEY.to_owned())
123126
.and_modify(|mut x| {
124-
if let Operation::Append {
125-
branch: _,
126-
data_files: old,
127-
delete_files: _,
128-
additional_summary: None,
129-
} = &mut x
127+
if let Operation::Append { data_files: old, ..} = &mut x
130128
{
131129
old.extend_from_slice(&files)
132130
}
@@ -135,7 +133,7 @@ impl<'table> TableTransaction<'table> {
135133
branch: self.branch.clone(),
136134
data_files: files,
137135
delete_files: Vec::new(),
138-
additional_summary: None,
136+
additional_summary: summary,
139137
});
140138
self
141139
}

0 commit comments

Comments
 (0)