@@ -480,38 +480,6 @@ def replace_table_transaction(
480480 Raises:
481481 NoSuchTableError: If the table does not exist.
482482 """
483- staged_table , fresh_schema , fresh_spec , fresh_sort_order , resolved_location = self ._replace_staged_table (
484- identifier , schema , location , partition_spec , sort_order , properties
485- )
486- return ReplaceTableTransaction (
487- table = staged_table ,
488- new_schema = fresh_schema ,
489- new_spec = fresh_spec ,
490- new_sort_order = fresh_sort_order ,
491- new_location = resolved_location ,
492- new_properties = properties ,
493- )
494-
495- def _replace_staged_table (
496- self ,
497- identifier : str | Identifier ,
498- schema : Schema | pa .Schema ,
499- location : str | None ,
500- partition_spec : PartitionSpec ,
501- sort_order : SortOrder ,
502- properties : Properties ,
503- ) -> tuple [StagedTable , Schema , PartitionSpec , SortOrder , str ]:
504- """Load the existing table and build fresh schema/spec/sort-order for replacement.
505-
506- - reuses existing field IDs by name (from the current schema)
507- - reuses partition field IDs by `(source, transform)` across all specs (v2+),
508- or carries forward the current spec with `VoidTransform`s (v1)
509- - reassigns sort field IDs against the fresh schema
510- - resolves `location` to the existing table's location when omitted
511-
512- Returns:
513- A tuple `(staged_table, fresh_schema, fresh_partition_spec, fresh_sort_order, resolved_location)`.
514- """
515483 existing_table = self .load_table (identifier )
516484 existing_metadata = existing_table .metadata
517485
@@ -534,7 +502,6 @@ def _replace_staged_table(
534502 fresh_schema , _ = assign_fresh_schema_ids_for_replace (
535503 iceberg_schema , existing_metadata .schema (), existing_metadata .last_column_id
536504 )
537-
538505 fresh_partition_spec , _ = assign_fresh_partition_spec_ids_for_replace (
539506 partition_spec ,
540507 iceberg_schema ,
@@ -544,7 +511,6 @@ def _replace_staged_table(
544511 format_version = existing_metadata .format_version ,
545512 current_spec = existing_metadata .spec (),
546513 )
547-
548514 fresh_sort_order = assign_fresh_sort_order_ids (sort_order , iceberg_schema , fresh_schema )
549515
550516 resolved_location = location .rstrip ("/" ) if location else existing_metadata .location
@@ -558,7 +524,14 @@ def _replace_staged_table(
558524 io = existing_table .io ,
559525 catalog = self ,
560526 )
561- return staged_table , fresh_schema , fresh_partition_spec , fresh_sort_order , resolved_location
527+ return ReplaceTableTransaction (
528+ table = staged_table ,
529+ new_schema = fresh_schema ,
530+ new_spec = fresh_partition_spec ,
531+ new_sort_order = fresh_sort_order ,
532+ new_location = resolved_location ,
533+ new_properties = properties ,
534+ )
562535
563536 @abstractmethod
564537 def load_table (self , identifier : str | Identifier ) -> Table :
0 commit comments