@@ -104,12 +104,12 @@ impl<'a> Transaction<'a> {
104
104
Ok ( self )
105
105
}
106
106
107
- /// Creates a merge snapshot action.
108
- pub fn merge_snapshot (
107
+ /// Creates a fast append action.
108
+ pub fn fast_append (
109
109
self ,
110
110
commit_uuid : Option < String > ,
111
111
key_metadata : Vec < u8 > ,
112
- ) -> Result < MergeSnapshotAction < ' a > > {
112
+ ) -> Result < FastAppendAction < ' a > > {
113
113
let parent_snapshot_id = self
114
114
. table
115
115
. metadata ( )
@@ -127,7 +127,7 @@ impl<'a> Transaction<'a> {
127
127
. unwrap_or_default ( ) ;
128
128
let commit_uuid = commit_uuid. unwrap_or_else ( || uuid:: Uuid :: new_v4 ( ) . to_string ( ) ) ;
129
129
130
- MergeSnapshotAction :: new (
130
+ FastAppendAction :: new (
131
131
self ,
132
132
parent_snapshot_id,
133
133
snapshot_id,
@@ -166,8 +166,8 @@ impl<'a> Transaction<'a> {
166
166
}
167
167
}
168
168
169
- /// Transaction action for merging snapshot .
170
- pub struct MergeSnapshotAction < ' a > {
169
+ /// FastAppendAction is a transaction action for fast append data files to the table .
170
+ pub struct FastAppendAction < ' a > {
171
171
tx : Transaction < ' a > ,
172
172
173
173
parent_snapshot_id : Option < i64 > ,
@@ -184,7 +184,7 @@ pub struct MergeSnapshotAction<'a> {
184
184
appended_data_files : Vec < DataFile > ,
185
185
}
186
186
187
- impl < ' a > MergeSnapshotAction < ' a > {
187
+ impl < ' a > FastAppendAction < ' a > {
188
188
#[ allow( clippy:: too_many_arguments) ]
189
189
pub ( crate ) fn new (
190
190
tx : Transaction < ' a > ,
@@ -234,21 +234,6 @@ impl<'a> MergeSnapshotAction<'a> {
234
234
)
235
235
}
236
236
237
- fn generate_manifest_list_file_path ( & self , next_seq_num : i64 ) -> String {
238
- format ! (
239
- "{}/{}/snap-{}-{}-{}.{}" ,
240
- self . tx. table. metadata( ) . location( ) ,
241
- META_ROOT_PATH ,
242
- self . snapshot_id,
243
- next_seq_num,
244
- self . commit_uuid,
245
- DataFileFormat :: Avro
246
- )
247
- }
248
-
249
- // # TODO:
250
- // This method act like fast append now, because we don't support overwrite and partial overwrite.
251
- // In the future, this method should be modify when we support them.
252
237
async fn manifest_from_parent_snapshot ( & self ) -> Result < Vec < ManifestFile > > {
253
238
if let Some ( snapshot) = self . tx . table . metadata ( ) . current_snapshot ( ) {
254
239
let manifest_list = snapshot
@@ -315,31 +300,98 @@ impl<'a> MergeSnapshotAction<'a> {
315
300
316
301
/// Finished building the action and apply it to the transaction.
317
302
pub async fn apply ( mut self ) -> Result < Transaction < ' a > > {
303
+ let summary = self . summary ( ) ;
304
+ let manifest = self . manifest_for_data_file ( ) . await ?;
305
+ let existing_manifest_files = self . manifest_from_parent_snapshot ( ) . await ?;
306
+
307
+ let snapshot_produce_action = SnapshotProduceAction :: new (
308
+ self . tx ,
309
+ self . snapshot_id ,
310
+ self . parent_snapshot_id ,
311
+ self . schema_id ,
312
+ self . format_version ,
313
+ self . commit_uuid ,
314
+ ) ?;
315
+
316
+ snapshot_produce_action
317
+ . apply (
318
+ vec ! [ manifest]
319
+ . into_iter ( )
320
+ . chain ( existing_manifest_files. into_iter ( ) ) ,
321
+ summary,
322
+ )
323
+ . await
324
+ }
325
+ }
326
+
327
+ struct SnapshotProduceAction < ' a > {
328
+ tx : Transaction < ' a > ,
329
+
330
+ parent_snapshot_id : Option < i64 > ,
331
+ snapshot_id : i64 ,
332
+ schema_id : i32 ,
333
+ format_version : FormatVersion ,
334
+
335
+ commit_uuid : String ,
336
+ }
337
+
338
+ impl < ' a > SnapshotProduceAction < ' a > {
339
+ pub ( crate ) fn new (
340
+ tx : Transaction < ' a > ,
341
+ snapshot_id : i64 ,
342
+ parent_snapshot_id : Option < i64 > ,
343
+ schema_id : i32 ,
344
+ format_version : FormatVersion ,
345
+ commit_uuid : String ,
346
+ ) -> Result < Self > {
347
+ Ok ( Self {
348
+ tx,
349
+ parent_snapshot_id,
350
+ snapshot_id,
351
+ schema_id,
352
+ format_version,
353
+ commit_uuid,
354
+ } )
355
+ }
356
+
357
+ fn generate_manifest_list_file_path ( & self , next_seq_num : i64 ) -> String {
358
+ format ! (
359
+ "{}/{}/snap-{}-{}-{}.{}" ,
360
+ self . tx. table. metadata( ) . location( ) ,
361
+ META_ROOT_PATH ,
362
+ self . snapshot_id,
363
+ next_seq_num,
364
+ self . commit_uuid,
365
+ DataFileFormat :: Avro
366
+ )
367
+ }
368
+
369
+ /// Finished building the action and apply it to the transaction.
370
+ pub async fn apply (
371
+ mut self ,
372
+ manifest_files : impl IntoIterator < Item = ManifestFile > ,
373
+ summary : Summary ,
374
+ ) -> Result < Transaction < ' a > > {
318
375
let next_seq_num = if self . format_version as u8 > 1u8 {
319
376
self . tx . table . metadata ( ) . last_sequence_number ( ) + 1
320
377
} else {
321
378
INITIAL_SEQUENCE_NUMBER
322
379
} ;
323
380
let commit_ts = chrono:: Utc :: now ( ) . timestamp_millis ( ) ;
324
- let summary = self . summary ( ) ;
325
-
326
- let manifest = self . manifest_for_data_file ( ) . await ?;
327
-
328
381
let manifest_list_path = self . generate_manifest_list_file_path ( next_seq_num) ;
382
+
329
383
let mut manifest_list_writer = ManifestListWriter :: v2 (
330
384
self . tx
331
385
. table
332
386
. file_io ( )
333
- . new_output ( self . generate_manifest_list_file_path ( next_seq_num ) ) ?,
387
+ . new_output ( manifest_list_path . clone ( ) ) ?,
334
388
self . snapshot_id ,
335
389
// # TODO
336
390
// Should we use `0` here for default parent snapshot id?
337
391
self . parent_snapshot_id . unwrap_or_default ( ) ,
338
392
next_seq_num,
339
393
) ;
340
- manifest_list_writer
341
- . add_manifests ( self . manifest_from_parent_snapshot ( ) . await ?. into_iter ( ) ) ?;
342
- manifest_list_writer. add_manifests ( vec ! [ manifest] . into_iter ( ) ) ?;
394
+ manifest_list_writer. add_manifests ( manifest_files. into_iter ( ) ) ?;
343
395
manifest_list_writer. close ( ) . await ?;
344
396
345
397
let new_snapshot = Snapshot :: builder ( )
@@ -644,7 +696,7 @@ mod tests {
644
696
. partition ( Struct :: from_iter ( [ Some ( Literal :: long ( 300 ) ) ] ) )
645
697
. build ( )
646
698
. unwrap ( ) ;
647
- let mut action = tx. merge_snapshot ( None , vec ! [ ] ) . unwrap ( ) ;
699
+ let mut action = tx. fast_append ( None , vec ! [ ] ) . unwrap ( ) ;
648
700
action. add_data_files ( vec ! [ data_file. clone( ) ] ) . unwrap ( ) ;
649
701
let tx = action. apply ( ) . await . unwrap ( ) ;
650
702
0 commit comments