Skip to content

Commit 1278e88

Browse files
sungwyFokko
andauthored
Remove support for catalog_name in table identifier string (#963)
* remove catalog identifier * remove deprecated identifier method * lint * nit Co-authored-by: Fokko Driesprong <[email protected]> * nit Co-authored-by: Fokko Driesprong <[email protected]> * Revert "nit" --------- Co-authored-by: Fokko Driesprong <[email protected]>
1 parent 5b5be31 commit 1278e88

File tree

9 files changed

+92
-250
lines changed

9 files changed

+92
-250
lines changed

pyiceberg/catalog/__init__.py

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@
7070
RecursiveDict,
7171
)
7272
from pyiceberg.utils.config import Config, merge_config
73-
from pyiceberg.utils.deprecated import deprecated, deprecation_message
73+
from pyiceberg.utils.deprecated import deprecated as deprecated
74+
from pyiceberg.utils.deprecated import deprecation_message
7475

7576
if TYPE_CHECKING:
7677
import pyarrow as pa
@@ -630,44 +631,6 @@ def drop_view(self, identifier: Union[str, Identifier]) -> None:
630631
NoSuchViewError: If a view with the given name does not exist.
631632
"""
632633

633-
@deprecated(
634-
deprecated_in="0.8.0",
635-
removed_in="0.9.0",
636-
help_message="Support for parsing catalog level identifier in Catalog identifiers is deprecated. Please refer to the table using only its namespace and its table name.",
637-
)
638-
def identifier_to_tuple_without_catalog(self, identifier: Union[str, Identifier]) -> Identifier:
639-
"""Convert an identifier to a tuple and drop this catalog's name from the first element.
640-
641-
Args:
642-
identifier (str | Identifier): Table identifier.
643-
644-
Returns:
645-
Identifier: a tuple of strings with this catalog's name removed
646-
"""
647-
identifier_tuple = Catalog.identifier_to_tuple(identifier)
648-
if len(identifier_tuple) >= 3 and identifier_tuple[0] == self.name:
649-
identifier_tuple = identifier_tuple[1:]
650-
return identifier_tuple
651-
652-
def _identifier_to_tuple_without_catalog(self, identifier: Union[str, Identifier]) -> Identifier:
653-
"""Convert an identifier to a tuple and drop this catalog's name from the first element.
654-
655-
Args:
656-
identifier (str | Identifier): Table identifier.
657-
658-
Returns:
659-
Identifier: a tuple of strings with this catalog's name removed
660-
"""
661-
identifier_tuple = Catalog.identifier_to_tuple(identifier)
662-
if len(identifier_tuple) >= 3 and identifier_tuple[0] == self.name:
663-
deprecation_message(
664-
deprecated_in="0.8.0",
665-
removed_in="0.9.0",
666-
help_message="Support for parsing catalog level identifier in Catalog identifiers is deprecated. Please refer to the table using only its namespace and its table name.",
667-
)
668-
identifier_tuple = identifier_tuple[1:]
669-
return identifier_tuple
670-
671634
@staticmethod
672635
def identifier_to_tuple(identifier: Union[str, Identifier]) -> Identifier:
673636
"""Parse an identifier to a tuple.
@@ -809,9 +772,8 @@ def table_exists(self, identifier: Union[str, Identifier]) -> bool:
809772
return False
810773

811774
def purge_table(self, identifier: Union[str, Identifier]) -> None:
812-
identifier_tuple = self._identifier_to_tuple_without_catalog(identifier)
813-
table = self.load_table(identifier_tuple)
814-
self.drop_table(identifier_tuple)
775+
table = self.load_table(identifier)
776+
self.drop_table(identifier)
815777
io = load_file_io(self.properties, table.metadata_location)
816778
metadata = table.metadata
817779
manifest_lists_to_delete = set()

pyiceberg/catalog/dynamodb.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,7 @@ def load_table(self, identifier: Union[str, Identifier]) -> Table:
244244
Raises:
245245
NoSuchTableError: If a table with the name does not exist, or the identifier is invalid.
246246
"""
247-
identifier_tuple = self._identifier_to_tuple_without_catalog(identifier)
248-
database_name, table_name = self.identifier_to_database_and_table(identifier_tuple, NoSuchTableError)
247+
database_name, table_name = self.identifier_to_database_and_table(identifier, NoSuchTableError)
249248
dynamo_table_item = self._get_iceberg_table_item(database_name=database_name, table_name=table_name)
250249
return self._convert_dynamo_table_item_to_iceberg_table(dynamo_table_item=dynamo_table_item)
251250

@@ -258,8 +257,7 @@ def drop_table(self, identifier: Union[str, Identifier]) -> None:
258257
Raises:
259258
NoSuchTableError: If a table with the name does not exist, or the identifier is invalid.
260259
"""
261-
identifier_tuple = self._identifier_to_tuple_without_catalog(identifier)
262-
database_name, table_name = self.identifier_to_database_and_table(identifier_tuple, NoSuchTableError)
260+
database_name, table_name = self.identifier_to_database_and_table(identifier, NoSuchTableError)
263261

264262
try:
265263
self._delete_dynamo_item(
@@ -289,8 +287,7 @@ def rename_table(self, from_identifier: Union[str, Identifier], to_identifier: U
289287
NoSuchPropertyException: When from table miss some required properties.
290288
NoSuchNamespaceError: When the destination namespace doesn't exist.
291289
"""
292-
from_identifier_tuple = self._identifier_to_tuple_without_catalog(from_identifier)
293-
from_database_name, from_table_name = self.identifier_to_database_and_table(from_identifier_tuple, NoSuchTableError)
290+
from_database_name, from_table_name = self.identifier_to_database_and_table(from_identifier, NoSuchTableError)
294291
to_database_name, to_table_name = self.identifier_to_database_and_table(to_identifier)
295292

296293
from_table_item = self._get_iceberg_table_item(database_name=from_database_name, table_name=from_table_name)
@@ -321,7 +318,7 @@ def rename_table(self, from_identifier: Union[str, Identifier], to_identifier: U
321318
raise TableAlreadyExistsError(f"Table {to_database_name}.{to_table_name} already exists") from e
322319

323320
try:
324-
self.drop_table(from_identifier_tuple)
321+
self.drop_table(from_identifier)
325322
except (NoSuchTableError, GenericDynamoDbError) as e:
326323
log_message = f"Failed to drop old table {from_database_name}.{from_table_name}. "
327324

pyiceberg/catalog/glue.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -556,8 +556,7 @@ def load_table(self, identifier: Union[str, Identifier]) -> Table:
556556
Raises:
557557
NoSuchTableError: If a table with the name does not exist, or the identifier is invalid.
558558
"""
559-
identifier_tuple = self._identifier_to_tuple_without_catalog(identifier)
560-
database_name, table_name = self.identifier_to_database_and_table(identifier_tuple, NoSuchTableError)
559+
database_name, table_name = self.identifier_to_database_and_table(identifier, NoSuchTableError)
561560

562561
return self._convert_glue_to_iceberg(self._get_glue_table(database_name=database_name, table_name=table_name))
563562

@@ -570,8 +569,7 @@ def drop_table(self, identifier: Union[str, Identifier]) -> None:
570569
Raises:
571570
NoSuchTableError: If a table with the name does not exist, or the identifier is invalid.
572571
"""
573-
identifier_tuple = self._identifier_to_tuple_without_catalog(identifier)
574-
database_name, table_name = self.identifier_to_database_and_table(identifier_tuple, NoSuchTableError)
572+
database_name, table_name = self.identifier_to_database_and_table(identifier, NoSuchTableError)
575573
try:
576574
self.glue.delete_table(DatabaseName=database_name, Name=table_name)
577575
except self.glue.exceptions.EntityNotFoundException as e:
@@ -596,8 +594,7 @@ def rename_table(self, from_identifier: Union[str, Identifier], to_identifier: U
596594
NoSuchPropertyException: When from table miss some required properties.
597595
NoSuchNamespaceError: When the destination namespace doesn't exist.
598596
"""
599-
from_identifier_tuple = self._identifier_to_tuple_without_catalog(from_identifier)
600-
from_database_name, from_table_name = self.identifier_to_database_and_table(from_identifier_tuple, NoSuchTableError)
597+
from_database_name, from_table_name = self.identifier_to_database_and_table(from_identifier, NoSuchTableError)
601598
to_database_name, to_table_name = self.identifier_to_database_and_table(to_identifier)
602599
try:
603600
get_table_response = self.glue.get_table(DatabaseName=from_database_name, Name=from_table_name)

pyiceberg/catalog/hive.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -531,8 +531,7 @@ def load_table(self, identifier: Union[str, Identifier]) -> Table:
531531
Raises:
532532
NoSuchTableError: If a table with the name does not exist, or the identifier is invalid.
533533
"""
534-
identifier_tuple = self._identifier_to_tuple_without_catalog(identifier)
535-
database_name, table_name = self.identifier_to_database_and_table(identifier_tuple, NoSuchTableError)
534+
database_name, table_name = self.identifier_to_database_and_table(identifier, NoSuchTableError)
536535

537536
with self._client as open_client:
538537
hive_table = self._get_hive_table(open_client, database_name, table_name)
@@ -548,8 +547,7 @@ def drop_table(self, identifier: Union[str, Identifier]) -> None:
548547
Raises:
549548
NoSuchTableError: If a table with the name does not exist, or the identifier is invalid.
550549
"""
551-
identifier_tuple = self._identifier_to_tuple_without_catalog(identifier)
552-
database_name, table_name = self.identifier_to_database_and_table(identifier_tuple, NoSuchTableError)
550+
database_name, table_name = self.identifier_to_database_and_table(identifier, NoSuchTableError)
553551
try:
554552
with self._client as open_client:
555553
open_client.drop_table(dbname=database_name, name=table_name, deleteData=False)
@@ -576,8 +574,7 @@ def rename_table(self, from_identifier: Union[str, Identifier], to_identifier: U
576574
NoSuchTableError: When a table with the name does not exist.
577575
NoSuchNamespaceError: When the destination namespace doesn't exist.
578576
"""
579-
from_identifier_tuple = self._identifier_to_tuple_without_catalog(from_identifier)
580-
from_database_name, from_table_name = self.identifier_to_database_and_table(from_identifier_tuple, NoSuchTableError)
577+
from_database_name, from_table_name = self.identifier_to_database_and_table(from_identifier, NoSuchTableError)
581578
to_database_name, to_table_name = self.identifier_to_database_and_table(to_identifier)
582579
try:
583580
with self._client as open_client:

pyiceberg/catalog/rest.py

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ def _response_to_table(self, identifier_tuple: Tuple[str, ...], table_response:
532532

533533
def _response_to_staged_table(self, identifier_tuple: Tuple[str, ...], table_response: TableResponse) -> StagedTable:
534534
return StagedTable(
535-
identifier=identifier_tuple if self.name else identifier_tuple,
535+
identifier=identifier_tuple,
536536
metadata_location=table_response.metadata_location, # type: ignore
537537
metadata=table_response.metadata,
538538
io=self._load_file_io(
@@ -578,7 +578,6 @@ def _create_table(
578578
fresh_partition_spec = assign_fresh_partition_spec_ids(partition_spec, iceberg_schema, fresh_schema)
579579
fresh_sort_order = assign_fresh_sort_order_ids(sort_order, iceberg_schema, fresh_schema)
580580

581-
identifier = self._identifier_to_tuple_without_catalog(identifier)
582581
namespace_and_table = self._split_identifier_for_path(identifier)
583582
if location:
584583
location = location.rstrip("/")
@@ -659,7 +658,6 @@ def register_table(self, identifier: Union[str, Identifier], metadata_location:
659658
Raises:
660659
TableAlreadyExistsError: If the table already exists
661660
"""
662-
identifier = self._identifier_to_tuple_without_catalog(identifier)
663661
namespace_and_table = self._split_identifier_for_path(identifier)
664662
request = RegisterTableRequest(
665663
name=namespace_and_table["table"],
@@ -691,25 +689,19 @@ def list_tables(self, namespace: Union[str, Identifier]) -> List[Identifier]:
691689

692690
@retry(**_RETRY_ARGS)
693691
def load_table(self, identifier: Union[str, Identifier]) -> Table:
694-
identifier_tuple = self._identifier_to_tuple_without_catalog(identifier)
695-
response = self._session.get(
696-
self.url(Endpoints.load_table, prefixed=True, **self._split_identifier_for_path(identifier_tuple))
697-
)
692+
response = self._session.get(self.url(Endpoints.load_table, prefixed=True, **self._split_identifier_for_path(identifier)))
698693
try:
699694
response.raise_for_status()
700695
except HTTPError as exc:
701696
self._handle_non_200_response(exc, {404: NoSuchTableError})
702697

703698
table_response = TableResponse(**response.json())
704-
return self._response_to_table(identifier_tuple, table_response)
699+
return self._response_to_table(self.identifier_to_tuple(identifier), table_response)
705700

706701
@retry(**_RETRY_ARGS)
707702
def drop_table(self, identifier: Union[str, Identifier], purge_requested: bool = False) -> None:
708-
identifier_tuple = self._identifier_to_tuple_without_catalog(identifier)
709703
response = self._session.delete(
710-
self.url(
711-
Endpoints.drop_table, prefixed=True, purge=purge_requested, **self._split_identifier_for_path(identifier_tuple)
712-
),
704+
self.url(Endpoints.drop_table, prefixed=True, purge=purge_requested, **self._split_identifier_for_path(identifier)),
713705
)
714706
try:
715707
response.raise_for_status()
@@ -722,9 +714,8 @@ def purge_table(self, identifier: Union[str, Identifier]) -> None:
722714

723715
@retry(**_RETRY_ARGS)
724716
def rename_table(self, from_identifier: Union[str, Identifier], to_identifier: Union[str, Identifier]) -> Table:
725-
from_identifier_tuple = self._identifier_to_tuple_without_catalog(from_identifier)
726717
payload = {
727-
"source": self._split_identifier_for_json(from_identifier_tuple),
718+
"source": self._split_identifier_for_json(from_identifier),
728719
"destination": self._split_identifier_for_json(to_identifier),
729720
}
730721
response = self._session.post(self.url(Endpoints.rename_table), json=payload)
@@ -899,9 +890,8 @@ def table_exists(self, identifier: Union[str, Identifier]) -> bool:
899890
Returns:
900891
bool: True if the table exists, False otherwise.
901892
"""
902-
identifier_tuple = self._identifier_to_tuple_without_catalog(identifier)
903893
response = self._session.head(
904-
self.url(Endpoints.load_table, prefixed=True, **self._split_identifier_for_path(identifier_tuple))
894+
self.url(Endpoints.load_table, prefixed=True, **self._split_identifier_for_path(identifier))
905895
)
906896

907897
if response.status_code == 404:
@@ -918,11 +908,8 @@ def table_exists(self, identifier: Union[str, Identifier]) -> bool:
918908

919909
@retry(**_RETRY_ARGS)
920910
def drop_view(self, identifier: Union[str]) -> None:
921-
identifier_tuple = self._identifier_to_tuple_without_catalog(identifier)
922911
response = self._session.delete(
923-
self.url(
924-
Endpoints.drop_view, prefixed=True, **self._split_identifier_for_path(identifier_tuple, IdentifierKind.VIEW)
925-
),
912+
self.url(Endpoints.drop_view, prefixed=True, **self._split_identifier_for_path(identifier, IdentifierKind.VIEW)),
926913
)
927914
try:
928915
response.raise_for_status()

pyiceberg/catalog/sql.py

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,8 @@ def create_table(
200200
"""
201201
schema: Schema = self._convert_schema_if_needed(schema) # type: ignore
202202

203-
identifier_nocatalog = self._identifier_to_tuple_without_catalog(identifier)
204-
namespace_identifier = Catalog.namespace_from(identifier_nocatalog)
205-
table_name = Catalog.table_name_from(identifier_nocatalog)
203+
namespace_identifier = Catalog.namespace_from(identifier)
204+
table_name = Catalog.table_name_from(identifier)
206205
if not self._namespace_exists(namespace_identifier):
207206
raise NoSuchNamespaceError(f"Namespace does not exist: {namespace_identifier}")
208207

@@ -246,10 +245,9 @@ def register_table(self, identifier: Union[str, Identifier], metadata_location:
246245
TableAlreadyExistsError: If the table already exists
247246
NoSuchNamespaceError: If namespace does not exist
248247
"""
249-
identifier_tuple = self._identifier_to_tuple_without_catalog(identifier)
250-
namespace_tuple = Catalog.namespace_from(identifier_tuple)
248+
namespace_tuple = Catalog.namespace_from(identifier)
251249
namespace = Catalog.namespace_to_string(namespace_tuple)
252-
table_name = Catalog.table_name_from(identifier_tuple)
250+
table_name = Catalog.table_name_from(identifier)
253251
if not self._namespace_exists(namespace):
254252
raise NoSuchNamespaceError(f"Namespace does not exist: {namespace}")
255253

@@ -285,10 +283,9 @@ def load_table(self, identifier: Union[str, Identifier]) -> Table:
285283
Raises:
286284
NoSuchTableError: If a table with the name does not exist.
287285
"""
288-
identifier_tuple = self._identifier_to_tuple_without_catalog(identifier)
289-
namespace_tuple = Catalog.namespace_from(identifier_tuple)
286+
namespace_tuple = Catalog.namespace_from(identifier)
290287
namespace = Catalog.namespace_to_string(namespace_tuple)
291-
table_name = Catalog.table_name_from(identifier_tuple)
288+
table_name = Catalog.table_name_from(identifier)
292289
with Session(self.engine) as session:
293290
stmt = select(IcebergTables).where(
294291
IcebergTables.catalog_name == self.name,
@@ -309,10 +306,9 @@ def drop_table(self, identifier: Union[str, Identifier]) -> None:
309306
Raises:
310307
NoSuchTableError: If a table with the name does not exist.
311308
"""
312-
identifier_tuple = self._identifier_to_tuple_without_catalog(identifier)
313-
namespace_tuple = Catalog.namespace_from(identifier_tuple)
309+
namespace_tuple = Catalog.namespace_from(identifier)
314310
namespace = Catalog.namespace_to_string(namespace_tuple)
315-
table_name = Catalog.table_name_from(identifier_tuple)
311+
table_name = Catalog.table_name_from(identifier)
316312
with Session(self.engine) as session:
317313
if self.engine.dialect.supports_sane_rowcount:
318314
res = session.execute(
@@ -356,14 +352,12 @@ def rename_table(self, from_identifier: Union[str, Identifier], to_identifier: U
356352
TableAlreadyExistsError: If a table with the new name already exist.
357353
NoSuchNamespaceError: If the target namespace does not exist.
358354
"""
359-
from_identifier_tuple = self._identifier_to_tuple_without_catalog(from_identifier)
360-
to_identifier_tuple = self._identifier_to_tuple_without_catalog(to_identifier)
361-
from_namespace_tuple = Catalog.namespace_from(from_identifier_tuple)
355+
from_namespace_tuple = Catalog.namespace_from(from_identifier)
362356
from_namespace = Catalog.namespace_to_string(from_namespace_tuple)
363-
from_table_name = Catalog.table_name_from(from_identifier_tuple)
364-
to_namespace_tuple = Catalog.namespace_from(to_identifier_tuple)
357+
from_table_name = Catalog.table_name_from(from_identifier)
358+
to_namespace_tuple = Catalog.namespace_from(to_identifier)
365359
to_namespace = Catalog.namespace_to_string(to_namespace_tuple)
366-
to_table_name = Catalog.table_name_from(to_identifier_tuple)
360+
to_table_name = Catalog.table_name_from(to_identifier)
367361
if not self._namespace_exists(to_namespace):
368362
raise NoSuchNamespaceError(f"Namespace does not exist: {to_namespace}")
369363
with Session(self.engine) as session:

pyiceberg/table/__init__.py

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@
137137
)
138138
from pyiceberg.utils.concurrent import ExecutorFactory
139139
from pyiceberg.utils.config import Config
140-
from pyiceberg.utils.deprecated import deprecated, deprecation_message
140+
from pyiceberg.utils.deprecated import deprecated
141+
from pyiceberg.utils.deprecated import deprecation_message as deprecation_message
141142
from pyiceberg.utils.properties import property_as_bool
142143

143144
if TYPE_CHECKING:
@@ -881,20 +882,6 @@ def refresh(self) -> Table:
881882
self.metadata_location = fresh.metadata_location
882883
return self
883884

884-
@property
885-
def identifier(self) -> Identifier:
886-
"""Return the identifier of this table.
887-
888-
Returns:
889-
An Identifier tuple of the table name
890-
"""
891-
deprecation_message(
892-
deprecated_in="0.8.0",
893-
removed_in="0.9.0",
894-
help_message="Table.identifier property is deprecated. Please use Table.name() function instead.",
895-
)
896-
return (self.catalog.name,) + self._identifier
897-
898885
def name(self) -> Identifier:
899886
"""Return the identifier of this table.
900887

0 commit comments

Comments
 (0)