@@ -447,8 +447,46 @@ impl TableUpdate {
447447 /// Applies the update to the table metadata builder.
448448 pub fn apply ( self , builder : TableMetadataBuilder ) -> Result < TableMetadataBuilder > {
449449 match self {
450- TableUpdate :: AssignUuid { uuid } => builder. assign_uuid ( uuid) ,
451- _ => unimplemented ! ( ) ,
450+ TableUpdate :: AssignUuid { uuid } => Ok ( builder. assign_uuid ( uuid) ) ,
451+ TableUpdate :: AddSchema {
452+ schema,
453+ last_column_id,
454+ } => {
455+ if let Some ( last_column_id) = last_column_id {
456+ if builder. last_column_id ( ) > last_column_id {
457+ return Err ( Error :: new (
458+ ErrorKind :: DataInvalid ,
459+ format ! (
460+ "Invalid last column ID: {last_column_id} < {} (previous last column ID)" ,
461+ builder. last_column_id( )
462+ ) ,
463+ ) ) ;
464+ }
465+ } ;
466+ Ok ( builder. add_schema ( schema) )
467+ }
468+ TableUpdate :: SetCurrentSchema { schema_id } => builder. set_current_schema ( schema_id) ,
469+ TableUpdate :: AddSpec { spec } => builder. add_partition_spec ( spec) ,
470+ TableUpdate :: SetDefaultSpec { spec_id } => builder. set_default_partition_spec ( spec_id) ,
471+ TableUpdate :: AddSortOrder { sort_order } => builder. add_sort_order ( sort_order) ,
472+ TableUpdate :: SetDefaultSortOrder { sort_order_id } => {
473+ builder. set_default_sort_order ( sort_order_id)
474+ }
475+ TableUpdate :: AddSnapshot { snapshot } => builder. add_snapshot ( snapshot) ,
476+ TableUpdate :: SetSnapshotRef {
477+ ref_name,
478+ reference,
479+ } => builder. set_ref ( & ref_name, reference) ,
480+ TableUpdate :: RemoveSnapshots { snapshot_ids } => {
481+ Ok ( builder. remove_snapshots ( & snapshot_ids) )
482+ }
483+ TableUpdate :: RemoveSnapshotRef { ref_name } => Ok ( builder. remove_ref ( & ref_name) ) ,
484+ TableUpdate :: SetLocation { location } => Ok ( builder. set_location ( location) ) ,
485+ TableUpdate :: SetProperties { updates } => builder. set_properties ( updates) ,
486+ TableUpdate :: RemoveProperties { removals } => Ok ( builder. remove_properties ( & removals) ) ,
487+ TableUpdate :: UpgradeFormatVersion { format_version } => {
488+ builder. upgrade_format_version ( format_version)
489+ }
452490 }
453491 }
454492}
@@ -1221,16 +1259,21 @@ mod tests {
12211259 let table_metadata = TableMetadataBuilder :: from_table_creation ( table_creation)
12221260 . unwrap ( )
12231261 . build ( )
1224- . unwrap ( ) ;
1225- let table_metadata_builder = TableMetadataBuilder :: new ( table_metadata) ;
1262+ . unwrap ( )
1263+ . metadata ;
1264+ let table_metadata_builder = TableMetadataBuilder :: new_from_metadata (
1265+ table_metadata,
1266+ Some ( "s3://db/table/metadata/metadata1.gz.json" . to_string ( ) ) ,
1267+ ) ;
12261268
12271269 let uuid = uuid:: Uuid :: new_v4 ( ) ;
12281270 let update = TableUpdate :: AssignUuid { uuid } ;
12291271 let updated_metadata = update
12301272 . apply ( table_metadata_builder)
12311273 . unwrap ( )
12321274 . build ( )
1233- . unwrap ( ) ;
1275+ . unwrap ( )
1276+ . metadata ;
12341277 assert_eq ! ( updated_metadata. uuid( ) , uuid) ;
12351278 }
12361279}
0 commit comments