Skip to content

Commit fc4fedf

Browse files
Collapse duplicate replace_table_transaction onto Catalog
Before: replace_table_transaction was @AbstractMethod on Catalog, with identical 9-line bodies on MetastoreCatalog and RestCatalog (only REST added @Retry). The bodies were identical because the only thing that could vary - the load_table to fetch existing metadata - already lives inside the shared _replace_staged_table helper. This is unlike create_table_transaction, which legitimately needs per-catalog impls (REST uses a server-side stage_create=True endpoint, Metastore stages locally). Replace has no analogous server-side staging, so the abstract-and-duplicate structure earned no symmetry. After: Catalog.replace_table_transaction is concrete and owns the helper-and-construct flow. RestCatalog keeps a thin @retry-only override that delegates to super(). MetastoreCatalog drops its override entirely. NoopCatalog keeps its explicit NotImplementedError stub for consistency with its other every-method-explicit stubs. Net -22 LOC, one less abstract surface to keep in sync.
1 parent e93f019 commit fc4fedf

2 files changed

Lines changed: 12 additions & 34 deletions

File tree

pyiceberg/catalog/__init__.py

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,6 @@ def create_table_if_not_exists(
449449
except TableAlreadyExistsError:
450450
return self.load_table(identifier)
451451

452-
@abstractmethod
453452
def replace_table_transaction(
454453
self,
455454
identifier: str | Identifier,
@@ -481,6 +480,17 @@ def replace_table_transaction(
481480
Raises:
482481
NoSuchTableError: If the table does not exist.
483482
"""
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+
)
484494

485495
def _replace_staged_table(
486496
self,
@@ -1030,28 +1040,6 @@ def create_table_transaction(
10301040
self._create_staged_table(identifier, schema, location, partition_spec, sort_order, properties)
10311041
)
10321042

1033-
@override
1034-
def replace_table_transaction(
1035-
self,
1036-
identifier: str | Identifier,
1037-
schema: Schema | pa.Schema,
1038-
location: str | None = None,
1039-
partition_spec: PartitionSpec = UNPARTITIONED_PARTITION_SPEC,
1040-
sort_order: SortOrder = UNSORTED_SORT_ORDER,
1041-
properties: Properties = EMPTY_DICT,
1042-
) -> ReplaceTableTransaction:
1043-
staged_table, fresh_schema, fresh_spec, fresh_sort_order, resolved_location = self._replace_staged_table(
1044-
identifier, schema, location, partition_spec, sort_order, properties
1045-
)
1046-
return ReplaceTableTransaction(
1047-
table=staged_table,
1048-
new_schema=fresh_schema,
1049-
new_spec=fresh_spec,
1050-
new_sort_order=fresh_sort_order,
1051-
new_location=resolved_location,
1052-
new_properties=properties,
1053-
)
1054-
10551043
@override
10561044
def table_exists(self, identifier: str | Identifier) -> bool:
10571045
try:

pyiceberg/catalog/rest/__init__.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -969,17 +969,7 @@ def replace_table_transaction(
969969
sort_order: SortOrder = UNSORTED_SORT_ORDER,
970970
properties: Properties = EMPTY_DICT,
971971
) -> ReplaceTableTransaction:
972-
staged_table, fresh_schema, fresh_spec, fresh_sort_order, resolved_location = self._replace_staged_table(
973-
identifier, schema, location, partition_spec, sort_order, properties
974-
)
975-
return ReplaceTableTransaction(
976-
table=staged_table,
977-
new_schema=fresh_schema,
978-
new_spec=fresh_spec,
979-
new_sort_order=fresh_sort_order,
980-
new_location=resolved_location,
981-
new_properties=properties,
982-
)
972+
return super().replace_table_transaction(identifier, schema, location, partition_spec, sort_order, properties)
983973

984974
@override
985975
@retry(**_RETRY_ARGS)

0 commit comments

Comments
 (0)