Skip to content

chore: Add assertion for empty data files for append action #1301

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 6 commits into from
May 10, 2025
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
4 changes: 4 additions & 0 deletions crates/iceberg/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ pub type Result<T> = std::result::Result<T, Error>;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum ErrorKind {
/// The operation was rejected because the system is not in a state required for the operation’s execution.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The description from error status is borrowed from https://grpc.io/docs/guides/status-codes/#the-full-list-of-status-codes

PreconditionFailed,

/// Iceberg don't know what happened here, and no actions other than
/// just returning it back. For example, iceberg returns an internal
/// service error.
Expand Down Expand Up @@ -76,6 +79,7 @@ impl From<ErrorKind> for &'static str {
ErrorKind::TableNotFound => "TableNotFound",
ErrorKind::NamespaceAlreadyExists => "NamespaceAlreadyExists",
ErrorKind::NamespaceNotFound => "NamespaceNotFound",
ErrorKind::PreconditionFailed => "PreconditionFailed",
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions crates/iceberg/src/transaction/append.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,15 @@ mod tests {
use crate::transaction::Transaction;
use crate::{TableRequirement, TableUpdate};

#[tokio::test]
async fn test_empty_data_append_action() {
let table = make_v2_minimal_table();
let tx = Transaction::new(&table);
let mut action = tx.fast_append(None, vec![]).unwrap();
action.add_data_files(vec![]).unwrap();
assert!(action.apply().await.is_err());
}

#[tokio::test]
async fn test_fast_append_action() {
let table = make_v2_minimal_table();
Expand Down
7 changes: 7 additions & 0 deletions crates/iceberg/src/transaction/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,13 @@ impl<'a> SnapshotProduceAction<'a> {
// Write manifest file for added data files and return the ManifestFile for ManifestList.
async fn write_added_manifest(&mut self) -> Result<ManifestFile> {
let added_data_files = std::mem::take(&mut self.added_data_files);
if added_data_files.is_empty() {
return Err(Error::new(
ErrorKind::PreconditionFailed,
"No added data files found when write a manifest file",
));
}

let snapshot_id = self.snapshot_id;
let format_version = self.tx.current_table.metadata().format_version();
let manifest_entries = added_data_files.into_iter().map(|data_file| {
Expand Down
Loading