@@ -35,26 +35,26 @@ use crate::error::Result;
3535use crate :: spec:: FormatVersion ;
3636use crate :: table:: Table ;
3737use crate :: transaction:: action:: {
38- PendingAction , SetLocation , TransactionAction , TransactionActionCommit ,
38+ BoxedTransactionAction , SetLocation , TransactionAction , TransactionActionCommit ,
3939} ;
4040use crate :: transaction:: append:: FastAppendAction ;
4141use crate :: transaction:: sort_order:: ReplaceSortOrderAction ;
4242use crate :: { Catalog , Error , ErrorKind , TableCommit , TableRequirement , TableUpdate } ;
4343
4444/// Table transaction.
45- pub struct Transaction < ' a > {
46- base_table : & ' a Table ,
45+ pub struct Transaction {
46+ base_table : Table ,
4747 current_table : Table ,
48- actions : Vec < PendingAction > ,
48+ actions : Vec < BoxedTransactionAction > ,
4949 updates : Vec < TableUpdate > ,
5050 requirements : Vec < TableRequirement > ,
5151}
5252
53- impl < ' a > Transaction < ' a > {
53+ impl Transaction {
5454 /// Creates a new transaction.
55- pub fn new ( table : & ' a Table ) -> Self {
55+ pub fn new ( table : Table ) -> Self {
5656 Self {
57- base_table : table,
57+ base_table : table. clone ( ) ,
5858 current_table : table. clone ( ) ,
5959 actions : vec ! [ ] ,
6060 updates : vec ! [ ] ,
@@ -174,7 +174,7 @@ impl<'a> Transaction<'a> {
174174 self ,
175175 commit_uuid : Option < Uuid > ,
176176 key_metadata : Vec < u8 > ,
177- ) -> Result < FastAppendAction < ' a > > {
177+ ) -> Result < FastAppendAction > {
178178 let snapshot_id = self . generate_unique_snapshot_id ( ) ;
179179 FastAppendAction :: new (
180180 self ,
@@ -186,7 +186,7 @@ impl<'a> Transaction<'a> {
186186 }
187187
188188 /// Creates replace sort order action.
189- pub fn replace_sort_order ( self ) -> ReplaceSortOrderAction < ' a > {
189+ pub fn replace_sort_order ( self ) -> ReplaceSortOrderAction {
190190 ReplaceSortOrderAction {
191191 tx : self ,
192192 sort_fields : vec ! [ ] ,
@@ -205,8 +205,7 @@ impl<'a> Transaction<'a> {
205205 /// Set the location of table
206206 pub fn set_location ( mut self , location : String ) -> Result < Self > {
207207 let set_location = SetLocation :: new ( ) . set_location ( location) ;
208- self . apply_commit_result ( Box :: new ( set_location) . commit ( ) ?)
209- . expect ( "Some error msg" ) ;
208+ Arc :: new ( set_location) . commit ( & mut self ) ?;
210209 Ok ( self )
211210 }
212211
@@ -243,14 +242,13 @@ impl<'a> Transaction<'a> {
243242 || self . base_table . metadata_location ( ) != refreshed. metadata_location ( )
244243 {
245244 // current base is stale, use refreshed as base and re-apply transaction actions
246- self . base_table = & refreshed. clone ( ) ;
245+ self . base_table = refreshed. clone ( ) ;
247246 self . current_table = refreshed. clone ( ) ;
248247
249248 let pending_actions = take ( & mut self . actions ) ;
250249
251250 for action in pending_actions {
252- self . apply_commit_result ( action. commit ( ) ?)
253- . expect ( "Failed to apply updates!" ) ;
251+ action. commit ( self ) . expect ( "Failed to apply updates!" ) ;
254252 }
255253 }
256254
@@ -347,7 +345,7 @@ mod tests {
347345 #[ test]
348346 fn test_upgrade_table_version_v1_to_v2 ( ) {
349347 let table = make_v1_table ( ) ;
350- let tx = Transaction :: new ( & table) ;
348+ let tx = Transaction :: new ( table) ;
351349 let tx = tx. upgrade_table_version ( FormatVersion :: V2 ) . unwrap ( ) ;
352350
353351 assert_eq ! (
@@ -361,7 +359,7 @@ mod tests {
361359 #[ test]
362360 fn test_upgrade_table_version_v2_to_v2 ( ) {
363361 let table = make_v2_table ( ) ;
364- let tx = Transaction :: new ( & table) ;
362+ let tx = Transaction :: new ( table) ;
365363 let tx = tx. upgrade_table_version ( FormatVersion :: V2 ) . unwrap ( ) ;
366364
367365 assert ! (
@@ -377,7 +375,7 @@ mod tests {
377375 #[ test]
378376 fn test_downgrade_table_version ( ) {
379377 let table = make_v2_table ( ) ;
380- let tx = Transaction :: new ( & table) ;
378+ let tx = Transaction :: new ( table) ;
381379 let tx = tx. upgrade_table_version ( FormatVersion :: V1 ) ;
382380
383381 assert ! ( tx. is_err( ) , "Downgrade table version should fail!" ) ;
@@ -386,7 +384,7 @@ mod tests {
386384 #[ test]
387385 fn test_set_table_property ( ) {
388386 let table = make_v2_table ( ) ;
389- let tx = Transaction :: new ( & table) ;
387+ let tx = Transaction :: new ( table) ;
390388 let tx = tx
391389 . set_properties ( HashMap :: from ( [ ( "a" . to_string ( ) , "b" . to_string ( ) ) ] ) )
392390 . unwrap ( ) ;
@@ -402,7 +400,7 @@ mod tests {
402400 #[ test]
403401 fn test_remove_property ( ) {
404402 let table = make_v2_table ( ) ;
405- let tx = Transaction :: new ( & table) ;
403+ let tx = Transaction :: new ( table) ;
406404 let tx = tx
407405 . remove_properties ( vec ! [ "a" . to_string( ) , "b" . to_string( ) ] )
408406 . unwrap ( ) ;
@@ -418,7 +416,7 @@ mod tests {
418416 #[ test]
419417 fn test_set_location ( ) {
420418 let table = make_v2_table ( ) ;
421- let tx = Transaction :: new ( & table) ;
419+ let tx = Transaction :: new ( table) ;
422420 let tx = tx
423421 . set_location ( String :: from ( "s3://bucket/prefix/new_table" ) )
424422 . unwrap ( ) ;
@@ -434,7 +432,7 @@ mod tests {
434432 #[ tokio:: test]
435433 async fn test_transaction_apply_upgrade ( ) {
436434 let table = make_v1_table ( ) ;
437- let tx = Transaction :: new ( & table) ;
435+ let tx = Transaction :: new ( table) ;
438436 // Upgrade v1 to v1, do nothing.
439437 let tx = tx. upgrade_table_version ( FormatVersion :: V1 ) . unwrap ( ) ;
440438 // Upgrade v1 to v2, success.
0 commit comments