Skip to content

Commit 0c3dde1

Browse files
Inline _replace_staged_table into Catalog.replace_table_transaction
After the previous commit collapsed both per-catalog overrides onto Catalog, _replace_staged_table was called from exactly one place and its only role was to hand back a five-element tuple to be re-spread into a constructor call. Removing the helper removes the tuple and the indirection.
1 parent fc4fedf commit 0c3dde1

1 file changed

Lines changed: 8 additions & 35 deletions

File tree

pyiceberg/catalog/__init__.py

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)