@@ -41,6 +41,9 @@ use crate::io::OutputFile;
4141use crate :: spec:: PartitionField ;
4242use crate :: { Error , ErrorKind } ;
4343
44+ /// Placeholder for snapshot ID. The field with this value must be replaced with the actual snapshot ID before it is committed.
45+ pub const UNASSIGNED_SNAPSHOT_ID : i64 = -1 ;
46+
4447/// A manifest contains metadata and a list of entries.
4548#[ derive( Debug , PartialEq , Eq , Clone ) ]
4649pub struct Manifest {
@@ -117,7 +120,7 @@ impl Manifest {
117120/// The builder used to create a [`ManifestWriter`].
118121pub struct ManifestWriterBuilder {
119122 output : OutputFile ,
120- snapshot_id : i64 ,
123+ snapshot_id : Option < i64 > ,
121124 key_metadata : Vec < u8 > ,
122125 schema : SchemaRef ,
123126 partition_spec : PartitionSpec ,
@@ -127,7 +130,7 @@ impl ManifestWriterBuilder {
127130 /// Create a new builder.
128131 pub fn new (
129132 output : OutputFile ,
130- snapshot_id : i64 ,
133+ snapshot_id : Option < i64 > ,
131134 key_metadata : Vec < u8 > ,
132135 schema : SchemaRef ,
133136 partition_spec : PartitionSpec ,
@@ -182,7 +185,7 @@ impl ManifestWriterBuilder {
182185pub struct ManifestWriter {
183186 output : OutputFile ,
184187
185- snapshot_id : i64 ,
188+ snapshot_id : Option < i64 > ,
186189
187190 added_files : u32 ,
188191 added_rows : u64 ,
@@ -266,7 +269,7 @@ impl ManifestWriter {
266269 /// Create a new manifest writer.
267270 pub ( crate ) fn new (
268271 output : OutputFile ,
269- snapshot_id : i64 ,
272+ snapshot_id : Option < i64 > ,
270273 key_metadata : Vec < u8 > ,
271274 metadata : ManifestMetadata ,
272275 ) -> Self {
@@ -340,11 +343,11 @@ impl ManifestWriter {
340343 self . check_data_file ( & entry. data_file ) ?;
341344 if entry. sequence_number ( ) . is_some_and ( |n| n >= 0 ) {
342345 entry. status = ManifestStatus :: Added ;
343- entry. snapshot_id = Some ( self . snapshot_id ) ;
346+ entry. snapshot_id = self . snapshot_id ;
344347 entry. file_sequence_number = None ;
345348 } else {
346349 entry. status = ManifestStatus :: Added ;
347- entry. snapshot_id = Some ( self . snapshot_id ) ;
350+ entry. snapshot_id = self . snapshot_id ;
348351 entry. sequence_number = None ;
349352 entry. file_sequence_number = None ;
350353 } ;
@@ -359,7 +362,7 @@ impl ManifestWriter {
359362 self . check_data_file ( & data_file) ?;
360363 let entry = ManifestEntry {
361364 status : ManifestStatus :: Added ,
362- snapshot_id : Some ( self . snapshot_id ) ,
365+ snapshot_id : self . snapshot_id ,
363366 sequence_number : ( sequence_number >= 0 ) . then_some ( sequence_number) ,
364367 file_sequence_number : None ,
365368 data_file,
@@ -378,7 +381,7 @@ impl ManifestWriter {
378381 pub ( crate ) fn delete ( & mut self , mut entry : ManifestEntry ) -> Result < ( ) > {
379382 self . check_data_file ( & entry. data_file ) ?;
380383 entry. status = ManifestStatus :: Deleted ;
381- entry. snapshot_id = Some ( self . snapshot_id ) ;
384+ entry. snapshot_id = self . snapshot_id ;
382385 self . add_entry ( entry) ?;
383386 Ok ( ( ) )
384387 }
@@ -395,7 +398,7 @@ impl ManifestWriter {
395398 self . check_data_file ( & data_file) ?;
396399 let entry = ManifestEntry {
397400 status : ManifestStatus :: Deleted ,
398- snapshot_id : Some ( self . snapshot_id ) ,
401+ snapshot_id : self . snapshot_id ,
399402 sequence_number : Some ( sequence_number) ,
400403 file_sequence_number : Some ( file_sequence_number) ,
401404 data_file,
@@ -547,7 +550,7 @@ impl ManifestWriter {
547550 // real sequence number in `ManifestListWriter`.
548551 sequence_number : UNASSIGNED_SEQUENCE_NUMBER ,
549552 min_sequence_number : self . min_seq_num . unwrap_or ( UNASSIGNED_SEQUENCE_NUMBER ) ,
550- added_snapshot_id : self . snapshot_id ,
553+ added_snapshot_id : self . snapshot_id . unwrap_or ( UNASSIGNED_SNAPSHOT_ID ) ,
551554 added_files_count : Some ( self . added_files ) ,
552555 existing_files_count : Some ( self . existing_files ) ,
553556 deleted_files_count : Some ( self . deleted_files ) ,
@@ -1948,7 +1951,7 @@ mod tests {
19481951 let output_file = io. new_output ( path. to_str ( ) . unwrap ( ) ) . unwrap ( ) ;
19491952 let mut writer = ManifestWriterBuilder :: new (
19501953 output_file,
1951- 1 ,
1954+ Some ( 1 ) ,
19521955 vec ! [ ] ,
19531956 metadata. schema . clone ( ) ,
19541957 metadata. partition_spec . clone ( ) ,
@@ -2128,7 +2131,7 @@ mod tests {
21282131 let output_file = io. new_output ( path. to_str ( ) . unwrap ( ) ) . unwrap ( ) ;
21292132 let mut writer = ManifestWriterBuilder :: new (
21302133 output_file,
2131- 2 ,
2134+ Some ( 2 ) ,
21322135 vec ! [ ] ,
21332136 metadata. schema . clone ( ) ,
21342137 metadata. partition_spec . clone ( ) ,
@@ -2220,7 +2223,7 @@ mod tests {
22202223 let output_file = io. new_output ( path. to_str ( ) . unwrap ( ) ) . unwrap ( ) ;
22212224 let mut writer = ManifestWriterBuilder :: new (
22222225 output_file,
2223- 3 ,
2226+ Some ( 3 ) ,
22242227 vec ! [ ] ,
22252228 metadata. schema . clone ( ) ,
22262229 metadata. partition_spec . clone ( ) ,
@@ -2324,7 +2327,7 @@ mod tests {
23242327 let output_file = io. new_output ( path. to_str ( ) . unwrap ( ) ) . unwrap ( ) ;
23252328 let mut writer = ManifestWriterBuilder :: new (
23262329 output_file,
2327- 2 ,
2330+ Some ( 2 ) ,
23282331 vec ! [ ] ,
23292332 metadata. schema . clone ( ) ,
23302333 metadata. partition_spec . clone ( ) ,
@@ -2426,7 +2429,7 @@ mod tests {
24262429 let output_file = io. new_output ( path. to_str ( ) . unwrap ( ) ) . unwrap ( ) ;
24272430 let mut writer = ManifestWriterBuilder :: new (
24282431 output_file,
2429- 2 ,
2432+ Some ( 2 ) ,
24302433 vec ! [ ] ,
24312434 metadata. schema . clone ( ) ,
24322435 metadata. partition_spec . clone ( ) ,
@@ -2680,7 +2683,7 @@ mod tests {
26802683 let output_file = io. new_output ( path. to_str ( ) . unwrap ( ) ) . unwrap ( ) ;
26812684 let mut writer = ManifestWriterBuilder :: new (
26822685 output_file,
2683- 1 ,
2686+ Some ( 1 ) ,
26842687 vec ! [ ] ,
26852688 metadata. schema . clone ( ) ,
26862689 metadata. partition_spec . clone ( ) ,
@@ -2819,7 +2822,7 @@ mod tests {
28192822 let output_file = io. new_output ( path. to_str ( ) . unwrap ( ) ) . unwrap ( ) ;
28202823 let mut writer = ManifestWriterBuilder :: new (
28212824 output_file,
2822- 3 ,
2825+ Some ( 3 ) ,
28232826 vec ! [ ] ,
28242827 metadata. schema . clone ( ) ,
28252828 metadata. partition_spec . clone ( ) ,
0 commit comments