@@ -106,34 +106,38 @@ impl std::fmt::Debug for ManifestListWriter {
106
106
107
107
impl ManifestListWriter {
108
108
/// 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 ( [
111
111
( "snapshot-id" . to_string ( ) , snapshot_id. to_string ( ) ) ,
112
- (
113
- "parent-snapshot-id" . to_string ( ) ,
114
- parent_snapshot_id. to_string ( ) ,
115
- ) ,
116
112
( "format-version" . to_string ( ) , "1" . to_string ( ) ) ,
117
113
] ) ;
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
+ }
118
120
Self :: new ( FormatVersion :: V1 , output_file, metadata, 0 , snapshot_id)
119
121
}
120
122
121
123
/// Construct a v2 [`ManifestListWriter`] that writes to a provided [`OutputFile`].
122
124
pub fn v2 (
123
125
output_file : OutputFile ,
124
126
snapshot_id : i64 ,
125
- parent_snapshot_id : i64 ,
127
+ parent_snapshot_id : Option < i64 > ,
126
128
sequence_number : i64 ,
127
129
) -> Self {
128
- let metadata = HashMap :: from_iter ( [
130
+ let mut metadata = HashMap :: from_iter ( [
129
131
( "snapshot-id" . to_string ( ) , snapshot_id. to_string ( ) ) ,
130
- (
131
- "parent-snapshot-id" . to_string ( ) ,
132
- parent_snapshot_id. to_string ( ) ,
133
- ) ,
134
132
( "sequence-number" . to_string ( ) , sequence_number. to_string ( ) ) ,
135
133
( "format-version" . to_string ( ) , "2" . to_string ( ) ) ,
136
134
] ) ;
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
+ ) ;
137
141
Self :: new (
138
142
FormatVersion :: V2 ,
139
143
output_file,
@@ -580,6 +584,18 @@ pub struct ManifestFile {
580
584
pub key_metadata : Vec < u8 > ,
581
585
}
582
586
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
+
583
599
/// The type of files tracked by the manifest, either data or delete files; Data(0) for all v1 manifests
584
600
#[ derive( Debug , PartialEq , Clone , Eq ) ]
585
601
pub enum ManifestContentType {
@@ -1146,7 +1162,7 @@ mod test {
1146
1162
let mut writer = ManifestListWriter :: v1 (
1147
1163
file_io. new_output ( full_path. clone ( ) ) . unwrap ( ) ,
1148
1164
1646658105718557341 ,
1149
- 1646658105718557341 ,
1165
+ Some ( 1646658105718557341 ) ,
1150
1166
) ;
1151
1167
1152
1168
writer
@@ -1213,7 +1229,7 @@ mod test {
1213
1229
let mut writer = ManifestListWriter :: v2 (
1214
1230
file_io. new_output ( full_path. clone ( ) ) . unwrap ( ) ,
1215
1231
1646658105718557341 ,
1216
- 1646658105718557341 ,
1232
+ Some ( 1646658105718557341 ) ,
1217
1233
1 ,
1218
1234
) ;
1219
1235
@@ -1335,7 +1351,7 @@ mod test {
1335
1351
let io = FileIOBuilder :: new_fs_io ( ) . build ( ) . unwrap ( ) ;
1336
1352
let output_file = io. new_output ( path. to_str ( ) . unwrap ( ) ) . unwrap ( ) ;
1337
1353
1338
- let mut writer = ManifestListWriter :: v1 ( output_file, 1646658105718557341 , 0 ) ;
1354
+ let mut writer = ManifestListWriter :: v1 ( output_file, 1646658105718557341 , Some ( 0 ) ) ;
1339
1355
writer
1340
1356
. add_manifests ( expected_manifest_list. entries . clone ( ) . into_iter ( ) )
1341
1357
. unwrap ( ) ;
@@ -1391,7 +1407,7 @@ mod test {
1391
1407
let io = FileIOBuilder :: new_fs_io ( ) . build ( ) . unwrap ( ) ;
1392
1408
let output_file = io. new_output ( path. to_str ( ) . unwrap ( ) ) . unwrap ( ) ;
1393
1409
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) ;
1395
1411
writer
1396
1412
. add_manifests ( expected_manifest_list. entries . clone ( ) . into_iter ( ) )
1397
1413
. unwrap ( ) ;
@@ -1445,7 +1461,7 @@ mod test {
1445
1461
let io = FileIOBuilder :: new_fs_io ( ) . build ( ) . unwrap ( ) ;
1446
1462
let output_file = io. new_output ( path. to_str ( ) . unwrap ( ) ) . unwrap ( ) ;
1447
1463
1448
- let mut writer = ManifestListWriter :: v2 ( output_file, 1646658105718557341 , 0 , 1 ) ;
1464
+ let mut writer = ManifestListWriter :: v2 ( output_file, 1646658105718557341 , Some ( 0 ) , 1 ) ;
1449
1465
writer
1450
1466
. add_manifests ( expected_manifest_list. entries . clone ( ) . into_iter ( ) )
1451
1467
. unwrap ( ) ;
0 commit comments