@@ -24,9 +24,11 @@ use uuid::Uuid;
24
24
use crate :: error:: Result ;
25
25
use crate :: io:: OutputFile ;
26
26
use crate :: spec:: {
27
- DataFile , DataFileFormat , FormatVersion , ManifestEntry , ManifestFile , ManifestListWriter ,
28
- ManifestWriterBuilder , Operation , Snapshot , SnapshotReference , SnapshotRetention , Struct ,
29
- StructType , Summary , MAIN_BRANCH ,
27
+ update_snapshot_summaries, DataFile , DataFileFormat , FormatVersion , ManifestEntry ,
28
+ ManifestFile , ManifestListWriter , ManifestWriterBuilder , Operation , Snapshot ,
29
+ SnapshotReference , SnapshotRetention , SnapshotSummaryCollector , Struct , StructType , Summary ,
30
+ MAIN_BRANCH , PROPERTY_WRITE_PARTITION_SUMMARY_LIMIT ,
31
+ PROPERTY_WRITE_PARTITION_SUMMARY_LIMIT_DEFAULT ,
30
32
} ;
31
33
use crate :: transaction:: Transaction ;
32
34
use crate :: { Error , ErrorKind , TableRequirement , TableUpdate } ;
@@ -221,13 +223,55 @@ impl<'a> SnapshotProduceAction<'a> {
221
223
Ok ( manifest_files)
222
224
}
223
225
224
- // # TODO
225
- // Fulfill this function
226
- fn summary < OP : SnapshotProduceOperation > ( & self , snapshot_produce_operation : & OP ) -> Summary {
227
- Summary {
228
- operation : snapshot_produce_operation. operation ( ) ,
229
- additional_properties : self . snapshot_properties . clone ( ) ,
226
+ // Returns a `Summary` of the current snapshot
227
+ fn summary < OP : SnapshotProduceOperation > (
228
+ & self ,
229
+ snapshot_produce_operation : & OP ,
230
+ ) -> Result < Summary > {
231
+ let mut summary_collector = SnapshotSummaryCollector :: default ( ) ;
232
+ let table_metadata = self . tx . table . metadata_ref ( ) ;
233
+
234
+ let partition_summary_limit = if let Some ( limit) = table_metadata
235
+ . properties ( )
236
+ . get ( PROPERTY_WRITE_PARTITION_SUMMARY_LIMIT )
237
+ {
238
+ if let Ok ( limit) = limit. parse :: < u64 > ( ) {
239
+ limit
240
+ } else {
241
+ PROPERTY_WRITE_PARTITION_SUMMARY_LIMIT_DEFAULT
242
+ }
243
+ } else {
244
+ PROPERTY_WRITE_PARTITION_SUMMARY_LIMIT_DEFAULT
245
+ } ;
246
+
247
+ summary_collector. set_partition_summary_limit ( partition_summary_limit) ;
248
+
249
+ for data_file in & self . added_data_files {
250
+ summary_collector. add_file (
251
+ data_file,
252
+ table_metadata. current_schema ( ) . clone ( ) ,
253
+ table_metadata. default_partition_spec ( ) . clone ( ) ,
254
+ ) ;
230
255
}
256
+
257
+ let previous_snapshot = table_metadata
258
+ . snapshot_by_id ( self . snapshot_id )
259
+ . and_then ( |snapshot| snapshot. parent_snapshot_id ( ) )
260
+ . and_then ( |parent_id| table_metadata. snapshot_by_id ( parent_id) ) ;
261
+
262
+ let mut additional_properties = summary_collector. build ( ) ;
263
+ additional_properties. extend ( self . snapshot_properties . clone ( ) ) ;
264
+
265
+ let summary = Summary {
266
+ operation : snapshot_produce_operation. operation ( ) ,
267
+ additional_properties,
268
+ } ;
269
+
270
+ update_snapshot_summaries (
271
+ summary,
272
+ previous_snapshot. map ( |s| s. summary ( ) ) ,
273
+ snapshot_produce_operation. operation ( ) == Operation :: Overwrite ,
274
+ )
231
275
}
232
276
233
277
fn generate_manifest_list_file_path ( & self , attempt : i64 ) -> String {
@@ -253,7 +297,13 @@ impl<'a> SnapshotProduceAction<'a> {
253
297
. await ?;
254
298
let next_seq_num = self . tx . table . metadata ( ) . next_sequence_number ( ) ;
255
299
256
- let summary = self . summary ( & snapshot_produce_operation) ;
300
+ let summary = self
301
+ . summary ( & snapshot_produce_operation)
302
+ . map_err ( |err| {
303
+ Error :: new ( ErrorKind :: Unexpected , "Failed to create snapshot summary." )
304
+ . with_source ( err)
305
+ } )
306
+ . unwrap ( ) ;
257
307
258
308
let manifest_list_path = self . generate_manifest_list_file_path ( 0 ) ;
259
309
0 commit comments