Skip to content

Commit 60d548d

Browse files
committed
fix None case for parant_snapshot_id
1 parent ec4db7b commit 60d548d

File tree

3 files changed

+14
-16
lines changed

3 files changed

+14
-16
lines changed

crates/iceberg/src/scan.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ mod tests {
453453
use crate::spec::{
454454
DataContentType, DataFileBuilder, DataFileFormat, FormatVersion, Literal, Manifest,
455455
ManifestContentType, ManifestEntry, ManifestListWriter, ManifestMetadata, ManifestStatus,
456-
ManifestWriter, Struct, TableMetadata, EMPTY_SNAPSHOT_ID,
456+
ManifestWriter, Struct, TableMetadata,
457457
};
458458
use crate::table::Table;
459459
use crate::TableIdent;
@@ -611,9 +611,7 @@ mod tests {
611611
.new_output(current_snapshot.manifest_list())
612612
.unwrap(),
613613
current_snapshot.snapshot_id(),
614-
current_snapshot
615-
.parent_snapshot_id()
616-
.unwrap_or(EMPTY_SNAPSHOT_ID),
614+
current_snapshot.parent_snapshot_id(),
617615
current_snapshot.sequence_number(),
618616
);
619617
manifest_list_write

crates/iceberg/src/spec/manifest_list.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,18 +118,20 @@ impl ManifestListWriter {
118118
pub fn v2(
119119
output_file: OutputFile,
120120
snapshot_id: i64,
121-
parent_snapshot_id: i64,
121+
parent_snapshot_id: Option<i64>,
122122
sequence_number: i64,
123123
) -> Self {
124-
let metadata = HashMap::from_iter([
124+
let mut metadata = HashMap::from_iter([
125125
("snapshot-id".to_string(), snapshot_id.to_string()),
126-
(
127-
"parent-snapshot-id".to_string(),
128-
parent_snapshot_id.to_string(),
129-
),
130126
("sequence-number".to_string(), sequence_number.to_string()),
131127
("format-version".to_string(), "2".to_string()),
132128
]);
129+
if let Some(parent_snapshot_id) = parent_snapshot_id {
130+
metadata.insert(
131+
"parent-snapshot-id".to_string(),
132+
parent_snapshot_id.to_string(),
133+
);
134+
}
133135
Self::new(
134136
FormatVersion::V2,
135137
output_file,
@@ -1204,7 +1206,7 @@ mod test {
12041206
let mut writer = ManifestListWriter::v2(
12051207
file_io.new_output(full_path.clone()).unwrap(),
12061208
1646658105718557341,
1207-
1646658105718557341,
1209+
Some(1646658105718557341),
12081210
1,
12091211
);
12101212

@@ -1382,7 +1384,7 @@ mod test {
13821384
let io = FileIOBuilder::new_fs_io().build().unwrap();
13831385
let output_file = io.new_output(path.to_str().unwrap()).unwrap();
13841386

1385-
let mut writer = ManifestListWriter::v2(output_file, snapshot_id, 0, seq_num);
1387+
let mut writer = ManifestListWriter::v2(output_file, snapshot_id, Some(0), seq_num);
13861388
writer
13871389
.add_manifests(expected_manifest_list.entries.clone().into_iter())
13881390
.unwrap();
@@ -1436,7 +1438,7 @@ mod test {
14361438
let io = FileIOBuilder::new_fs_io().build().unwrap();
14371439
let output_file = io.new_output(path.to_str().unwrap()).unwrap();
14381440

1439-
let mut writer = ManifestListWriter::v2(output_file, 1646658105718557341, 0, 1);
1441+
let mut writer = ManifestListWriter::v2(output_file, 1646658105718557341, Some(0), 1);
14401442
writer
14411443
.add_manifests(expected_manifest_list.entries.clone().into_iter())
14421444
.unwrap();

crates/iceberg/src/transaction.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -455,9 +455,7 @@ impl<'a> SnapshotProduceAction<'a> {
455455
.file_io()
456456
.new_output(manifest_list_path.clone())?,
457457
self.snapshot_id,
458-
// # TODO
459-
// Should we use `0` here for default parent snapshot id?
460-
self.parent_snapshot_id.unwrap_or_default(),
458+
self.parent_snapshot_id,
461459
next_seq_num,
462460
);
463461
manifest_list_writer.add_manifests(manifest_files.into_iter())?;

0 commit comments

Comments
 (0)