@@ -106,34 +106,38 @@ impl std::fmt::Debug for ManifestListWriter {
106106
107107impl ManifestListWriter {
108108 /// Construct a v1 [`ManifestListWriter`] that writes to a provided [`OutputFile`].
109- pub fn v1 ( output_file : OutputFile , snapshot_id : i64 , parent_snapshot_id : i64 ) -> Self {
110- let metadata = HashMap :: from_iter ( [
109+ pub fn v1 ( output_file : OutputFile , snapshot_id : i64 , parent_snapshot_id : Option < i64 > ) -> Self {
110+ let mut metadata = HashMap :: from_iter ( [
111111 ( "snapshot-id" . to_string ( ) , snapshot_id. to_string ( ) ) ,
112- (
113- "parent-snapshot-id" . to_string ( ) ,
114- parent_snapshot_id. to_string ( ) ,
115- ) ,
116112 ( "format-version" . to_string ( ) , "1" . to_string ( ) ) ,
117113 ] ) ;
114+ if let Some ( parent_snapshot_id) = parent_snapshot_id {
115+ metadata. insert (
116+ "parent-snapshot-id" . to_string ( ) ,
117+ parent_snapshot_id. to_string ( ) ,
118+ ) ;
119+ }
118120 Self :: new ( FormatVersion :: V1 , output_file, metadata, 0 , snapshot_id)
119121 }
120122
121123 /// Construct a v2 [`ManifestListWriter`] that writes to a provided [`OutputFile`].
122124 pub fn v2 (
123125 output_file : OutputFile ,
124126 snapshot_id : i64 ,
125- parent_snapshot_id : i64 ,
127+ parent_snapshot_id : Option < i64 > ,
126128 sequence_number : i64 ,
127129 ) -> Self {
128- let metadata = HashMap :: from_iter ( [
130+ let mut metadata = HashMap :: from_iter ( [
129131 ( "snapshot-id" . to_string ( ) , snapshot_id. to_string ( ) ) ,
130- (
131- "parent-snapshot-id" . to_string ( ) ,
132- parent_snapshot_id. to_string ( ) ,
133- ) ,
134132 ( "sequence-number" . to_string ( ) , sequence_number. to_string ( ) ) ,
135133 ( "format-version" . to_string ( ) , "2" . to_string ( ) ) ,
136134 ] ) ;
135+ metadata. insert (
136+ "parent-snapshot-id" . to_string ( ) ,
137+ parent_snapshot_id
138+ . map ( |v| v. to_string ( ) )
139+ . unwrap_or ( "null" . to_string ( ) ) ,
140+ ) ;
137141 Self :: new (
138142 FormatVersion :: V2 ,
139143 output_file,
@@ -580,6 +584,18 @@ pub struct ManifestFile {
580584 pub key_metadata : Vec < u8 > ,
581585}
582586
587+ impl ManifestFile {
588+ /// Checks if the manifest file has any added files.
589+ pub fn has_added_files ( & self ) -> bool {
590+ self . added_files_count . is_none ( ) || self . added_files_count . unwrap ( ) > 0
591+ }
592+
593+ /// Checks if the manifest file has any existed files.
594+ pub fn has_existing_files ( & self ) -> bool {
595+ self . existing_files_count . is_none ( ) || self . existing_files_count . unwrap ( ) > 0
596+ }
597+ }
598+
583599/// The type of files tracked by the manifest, either data or delete files; Data(0) for all v1 manifests
584600#[ derive( Debug , PartialEq , Clone , Eq ) ]
585601pub enum ManifestContentType {
@@ -1146,7 +1162,7 @@ mod test {
11461162 let mut writer = ManifestListWriter :: v1 (
11471163 file_io. new_output ( full_path. clone ( ) ) . unwrap ( ) ,
11481164 1646658105718557341 ,
1149- 1646658105718557341 ,
1165+ Some ( 1646658105718557341 ) ,
11501166 ) ;
11511167
11521168 writer
@@ -1213,7 +1229,7 @@ mod test {
12131229 let mut writer = ManifestListWriter :: v2 (
12141230 file_io. new_output ( full_path. clone ( ) ) . unwrap ( ) ,
12151231 1646658105718557341 ,
1216- 1646658105718557341 ,
1232+ Some ( 1646658105718557341 ) ,
12171233 1 ,
12181234 ) ;
12191235
@@ -1335,7 +1351,7 @@ mod test {
13351351 let io = FileIOBuilder :: new_fs_io ( ) . build ( ) . unwrap ( ) ;
13361352 let output_file = io. new_output ( path. to_str ( ) . unwrap ( ) ) . unwrap ( ) ;
13371353
1338- let mut writer = ManifestListWriter :: v1 ( output_file, 1646658105718557341 , 0 ) ;
1354+ let mut writer = ManifestListWriter :: v1 ( output_file, 1646658105718557341 , Some ( 0 ) ) ;
13391355 writer
13401356 . add_manifests ( expected_manifest_list. entries . clone ( ) . into_iter ( ) )
13411357 . unwrap ( ) ;
@@ -1391,7 +1407,7 @@ mod test {
13911407 let io = FileIOBuilder :: new_fs_io ( ) . build ( ) . unwrap ( ) ;
13921408 let output_file = io. new_output ( path. to_str ( ) . unwrap ( ) ) . unwrap ( ) ;
13931409
1394- let mut writer = ManifestListWriter :: v2 ( output_file, snapshot_id, 0 , seq_num) ;
1410+ let mut writer = ManifestListWriter :: v2 ( output_file, snapshot_id, Some ( 0 ) , seq_num) ;
13951411 writer
13961412 . add_manifests ( expected_manifest_list. entries . clone ( ) . into_iter ( ) )
13971413 . unwrap ( ) ;
@@ -1445,7 +1461,7 @@ mod test {
14451461 let io = FileIOBuilder :: new_fs_io ( ) . build ( ) . unwrap ( ) ;
14461462 let output_file = io. new_output ( path. to_str ( ) . unwrap ( ) ) . unwrap ( ) ;
14471463
1448- let mut writer = ManifestListWriter :: v2 ( output_file, 1646658105718557341 , 0 , 1 ) ;
1464+ let mut writer = ManifestListWriter :: v2 ( output_file, 1646658105718557341 , Some ( 0 ) , 1 ) ;
14491465 writer
14501466 . add_manifests ( expected_manifest_list. entries . clone ( ) . into_iter ( ) )
14511467 . unwrap ( ) ;
0 commit comments