Skip to content

Commit eba39e3

Browse files
authored
Merge pull request #170 from Embucket/aosipov/append_operation_summary
Append operation summary
2 parents 4d65178 + e0f3caf commit eba39e3

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

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-
3-
use iceberg_rust_spec::{manifest::ManifestEntry, manifest_list::ManifestListEntry};
2+
use std::collections::HashMap;
43
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

@@ -116,15 +117,12 @@ impl<'table> TableTransaction<'table> {
116117
/// .await?;
117118
/// ```
118119
pub fn append_data(mut self, files: Vec<DataFile>) -> Self {
120+
let summary = append_summary(&files);
121+
119122
self.operations
120123
.entry(APPEND_KEY.to_owned())
121124
.and_modify(|mut x| {
122-
if let Operation::Append {
123-
branch: _,
124-
data_files: old,
125-
delete_files: _,
126-
additional_summary: None,
127-
} = &mut x
125+
if let Operation::Append { data_files: old, ..} = &mut x
128126
{
129127
old.extend_from_slice(&files)
130128
}
@@ -133,7 +131,7 @@ impl<'table> TableTransaction<'table> {
133131
branch: self.branch.clone(),
134132
data_files: files,
135133
delete_files: Vec::new(),
136-
additional_summary: None,
134+
additional_summary: summary,
137135
});
138136
self
139137
}

0 commit comments

Comments
 (0)