Skip to content

Commit b3ea8d1

Browse files
authored
feat: append action allows snapshot properties (#1534)
1 parent 87f7f1a commit b3ea8d1

File tree

2 files changed

+51
-4
lines changed

2 files changed

+51
-4
lines changed

crates/iceberg/src/transaction/append.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,36 @@ mod tests {
208208
);
209209
}
210210

211+
#[tokio::test]
212+
async fn test_append_snapshot_properties() {
213+
let table = make_v2_minimal_table();
214+
let tx = Transaction::new(&table);
215+
216+
let mut snapshot_properties = HashMap::new();
217+
snapshot_properties.insert("key".to_string(), "val".to_string());
218+
219+
let action = tx
220+
.fast_append()
221+
.set_snapshot_properties(snapshot_properties);
222+
let mut action_commit = Arc::new(action).commit(&table).await.unwrap();
223+
let updates = action_commit.take_updates();
224+
225+
// Check customized properties is contained in snapshot summary properties.
226+
let new_snapshot = if let TableUpdate::AddSnapshot { snapshot } = &updates[0] {
227+
snapshot
228+
} else {
229+
unreachable!()
230+
};
231+
assert_eq!(
232+
new_snapshot
233+
.summary()
234+
.additional_properties
235+
.get("key")
236+
.unwrap(),
237+
"val"
238+
);
239+
}
240+
211241
#[tokio::test]
212242
async fn test_fast_append_file_with_incompatible_partition_value() {
213243
let table = make_v2_minimal_table();

crates/iceberg/src/transaction/snapshot.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ impl<'a> SnapshotProducer<'a> {
254254
if added_data_files.is_empty() {
255255
return Err(Error::new(
256256
ErrorKind::PreconditionFailed,
257-
"No added data files found when write a manifest file",
257+
"No added data files found when write an added manifest file",
258258
));
259259
}
260260

@@ -284,13 +284,30 @@ impl<'a> SnapshotProducer<'a> {
284284
snapshot_produce_operation: &OP,
285285
manifest_process: &MP,
286286
) -> Result<Vec<ManifestFile>> {
287-
let added_manifest = self.write_added_manifest().await?;
287+
// Assert current snapshot producer contains new content to add to new snapshot.
288+
//
289+
// TODO: Allowing snapshot property setup with no added data files is a workaround.
290+
// We should clean it up after all necessary actions are supported.
291+
// For details, please refer to https://github.com/apache/iceberg-rust/issues/1548
292+
if self.added_data_files.is_empty() && self.snapshot_properties.is_empty() {
293+
return Err(Error::new(
294+
ErrorKind::PreconditionFailed,
295+
"No added data files or added snapshot properties found when write a manifest file",
296+
));
297+
}
298+
288299
let existing_manifests = snapshot_produce_operation.existing_manifest(self).await?;
300+
let mut manifest_files = existing_manifests;
301+
302+
// Process added entries.
303+
if !self.added_data_files.is_empty() {
304+
let added_manifest = self.write_added_manifest().await?;
305+
manifest_files.push(added_manifest);
306+
}
307+
289308
// # TODO
290309
// Support process delete entries.
291310

292-
let mut manifest_files = vec![added_manifest];
293-
manifest_files.extend(existing_manifests);
294311
let manifest_files = manifest_process.process_manifests(self, manifest_files);
295312
Ok(manifest_files)
296313
}

0 commit comments

Comments
 (0)