From b0531d08d3a75a6f58f4337f479e0adc574289c6 Mon Sep 17 00:00:00 2001 From: Raminder Singh Date: Mon, 20 Oct 2025 15:50:41 +0530 Subject: [PATCH] fix: snapshot was producing empty summary --- crates/iceberg/src/transaction/snapshot.rs | 23 ++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/crates/iceberg/src/transaction/snapshot.rs b/crates/iceberg/src/transaction/snapshot.rs index a03b8dc490..93dd819d5c 100644 --- a/crates/iceberg/src/transaction/snapshot.rs +++ b/crates/iceberg/src/transaction/snapshot.rs @@ -380,17 +380,8 @@ impl<'a> SnapshotProducer<'a> { snapshot_produce_operation: OP, process: MP, ) -> Result { - let new_manifests = self - .manifest_file(&snapshot_produce_operation, &process) - .await?; - let next_seq_num = self.table.metadata().next_sequence_number(); - - let summary = self.summary(&snapshot_produce_operation).map_err(|err| { - Error::new(ErrorKind::Unexpected, "Failed to create snapshot summary.").with_source(err) - })?; - let manifest_list_path = self.generate_manifest_list_file_path(0); - + let next_seq_num = self.table.metadata().next_sequence_number(); let mut manifest_list_writer = match self.table.metadata().format_version() { FormatVersion::V1 => ManifestListWriter::v1( self.table @@ -408,6 +399,18 @@ impl<'a> SnapshotProducer<'a> { next_seq_num, ), }; + + // Calling self.summary() before self.manifest_file() is important because self.added_data_files + // will be set to an empty vec after self.manifest_file() returns, resulting in an empty summary + // being generated. + let summary = self.summary(&snapshot_produce_operation).map_err(|err| { + Error::new(ErrorKind::Unexpected, "Failed to create snapshot summary.").with_source(err) + })?; + + let new_manifests = self + .manifest_file(&snapshot_produce_operation, &process) + .await?; + manifest_list_writer.add_manifests(new_manifests.into_iter())?; manifest_list_writer.close().await?;