Skip to content

feat: append action allows snapshot properties #1534

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
30 changes: 30 additions & 0 deletions crates/iceberg/src/transaction/append.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,36 @@ mod tests {
);
}

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

let mut snapshot_properties = HashMap::new();
snapshot_properties.insert("key".to_string(), "val".to_string());

let action = tx
.fast_append()
.set_snapshot_properties(snapshot_properties);
let mut action_commit = Arc::new(action).commit(&table).await.unwrap();
let updates = action_commit.take_updates();

// Check customized properties is contained in snapshot summary properties.
let new_snapshot = if let TableUpdate::AddSnapshot { snapshot } = &updates[0] {
snapshot
} else {
unreachable!()
};
assert_eq!(
new_snapshot
.summary()
.additional_properties
.get("key")
.unwrap(),
"val"
);
}

#[tokio::test]
async fn test_fast_append_file_with_incompatible_partition_value() {
let table = make_v2_minimal_table();
Expand Down
25 changes: 21 additions & 4 deletions crates/iceberg/src/transaction/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ impl<'a> SnapshotProducer<'a> {
if added_data_files.is_empty() {
return Err(Error::new(
ErrorKind::PreconditionFailed,
"No added data files found when write a manifest file",
"No added data files found when write an added manifest file",
));
}

Expand Down Expand Up @@ -284,13 +284,30 @@ impl<'a> SnapshotProducer<'a> {
snapshot_produce_operation: &OP,
manifest_process: &MP,
) -> Result<Vec<ManifestFile>> {
let added_manifest = self.write_added_manifest().await?;
// Assert current snapshot producer contains new content to add to new snapshot.
//
// TODO: Allowing snapshot property setup with no added data files is a workaround.
// We should clean it up after all necessary actions are supported.
// For details, please refer to https://github.com/apache/iceberg-rust/issues/1548
if self.added_data_files.is_empty() && self.snapshot_properties.is_empty() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please create an issue to track that we need to remove this workaround when we introduced all necessary tx apis.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure! I created an issue to track: #1548
Also leave TODO items in the code along with the issue attached.

return Err(Error::new(
ErrorKind::PreconditionFailed,
"No added data files or added snapshot properties found when write a manifest file",
));
}

let existing_manifests = snapshot_produce_operation.existing_manifest(self).await?;
let mut manifest_files = existing_manifests;

// Process added entries.
if !self.added_data_files.is_empty() {
let added_manifest = self.write_added_manifest().await?;
manifest_files.push(added_manifest);
}

// # TODO
// Support process delete entries.

let mut manifest_files = vec![added_manifest];
manifest_files.extend(existing_manifests);
let manifest_files = manifest_process.process_manifests(self, manifest_files);
Ok(manifest_files)
}
Expand Down
Loading