Skip to content

Commit 9217fae

Browse files
committed
remove use of catalog identifiers
1 parent 5be6820 commit 9217fae

File tree

8 files changed

+87
-172
lines changed

8 files changed

+87
-172
lines changed

pyiceberg/catalog/__init__.py

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -649,25 +649,6 @@ def identifier_to_tuple_without_catalog(self, identifier: Union[str, Identifier]
649649
identifier_tuple = identifier_tuple[1:]
650650
return identifier_tuple
651651

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-
671652
@staticmethod
672653
def identifier_to_tuple(identifier: Union[str, Identifier]) -> Identifier:
673654
"""Parse an identifier to a tuple.
@@ -809,9 +790,8 @@ def table_exists(self, identifier: Union[str, Identifier]) -> bool:
809790
return False
810791

811792
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)
793+
table = self.load_table(identifier)
794+
self.drop_table(identifier)
815795
io = load_file_io(self.properties, table.metadata_location)
816796
metadata = table.metadata
817797
manifest_lists_to_delete = set()

pyiceberg/catalog/dynamodb.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,7 @@ def drop_table(self, identifier: Union[str, Identifier]) -> None:
257257
Raises:
258258
NoSuchTableError: If a table with the name does not exist, or the identifier is invalid.
259259
"""
260-
identifier_tuple = self._identifier_to_tuple_without_catalog(identifier)
261-
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)
262261

263262
try:
264263
self._delete_dynamo_item(
@@ -288,8 +287,7 @@ def rename_table(self, from_identifier: Union[str, Identifier], to_identifier: U
288287
NoSuchPropertyException: When from table miss some required properties.
289288
NoSuchNamespaceError: When the destination namespace doesn't exist.
290289
"""
291-
from_identifier_tuple = self._identifier_to_tuple_without_catalog(from_identifier)
292-
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)
293291
to_database_name, to_table_name = self.identifier_to_database_and_table(to_identifier)
294292

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

322320
try:
323-
self.drop_table(from_identifier_tuple)
321+
self.drop_table(from_identifier)
324322
except (NoSuchTableError, GenericDynamoDbError) as e:
325323
log_message = f"Failed to drop old table {from_database_name}.{from_table_name}. "
326324

pyiceberg/catalog/glue.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -569,8 +569,7 @@ def drop_table(self, identifier: Union[str, Identifier]) -> None:
569569
Raises:
570570
NoSuchTableError: If a table with the name does not exist, or the identifier is invalid.
571571
"""
572-
identifier_tuple = self._identifier_to_tuple_without_catalog(identifier)
573-
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)
574573
try:
575574
self.glue.delete_table(DatabaseName=database_name, Name=table_name)
576575
except self.glue.exceptions.EntityNotFoundException as e:
@@ -595,8 +594,7 @@ def rename_table(self, from_identifier: Union[str, Identifier], to_identifier: U
595594
NoSuchPropertyException: When from table miss some required properties.
596595
NoSuchNamespaceError: When the destination namespace doesn't exist.
597596
"""
598-
from_identifier_tuple = self._identifier_to_tuple_without_catalog(from_identifier)
599-
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)
600598
to_database_name, to_table_name = self.identifier_to_database_and_table(to_identifier)
601599
try:
602600
get_table_response = self.glue.get_table(DatabaseName=from_database_name, Name=from_table_name)

pyiceberg/catalog/hive.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -547,8 +547,7 @@ def drop_table(self, identifier: Union[str, Identifier]) -> None:
547547
Raises:
548548
NoSuchTableError: If a table with the name does not exist, or the identifier is invalid.
549549
"""
550-
identifier_tuple = self._identifier_to_tuple_without_catalog(identifier)
551-
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)
552551
try:
553552
with self._client as open_client:
554553
open_client.drop_table(dbname=database_name, name=table_name, deleteData=False)
@@ -575,8 +574,7 @@ def rename_table(self, from_identifier: Union[str, Identifier], to_identifier: U
575574
NoSuchTableError: When a table with the name does not exist.
576575
NoSuchNamespaceError: When the destination namespace doesn't exist.
577576
"""
578-
from_identifier_tuple = self._identifier_to_tuple_without_catalog(from_identifier)
579-
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)
580578
to_database_name, to_table_name = self.identifier_to_database_and_table(to_identifier)
581579
try:
582580
with self._client as open_client:

pyiceberg/catalog/rest.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,6 @@ def _create_table(
577577
fresh_partition_spec = assign_fresh_partition_spec_ids(partition_spec, iceberg_schema, fresh_schema)
578578
fresh_sort_order = assign_fresh_sort_order_ids(sort_order, iceberg_schema, fresh_schema)
579579

580-
identifier = self._identifier_to_tuple_without_catalog(identifier)
581580
namespace_and_table = self._split_identifier_for_path(identifier)
582581
if location:
583582
location = location.rstrip("/")
@@ -658,7 +657,6 @@ def register_table(self, identifier: Union[str, Identifier], metadata_location:
658657
Raises:
659658
TableAlreadyExistsError: If the table already exists
660659
"""
661-
identifier = self._identifier_to_tuple_without_catalog(identifier)
662660
namespace_and_table = self._split_identifier_for_path(identifier)
663661
request = RegisterTableRequest(
664662
name=namespace_and_table["table"],
@@ -701,11 +699,8 @@ def load_table(self, identifier: Union[str, Identifier]) -> Table:
701699

702700
@retry(**_RETRY_ARGS)
703701
def drop_table(self, identifier: Union[str, Identifier], purge_requested: bool = False) -> None:
704-
identifier_tuple = self._identifier_to_tuple_without_catalog(identifier)
705702
response = self._session.delete(
706-
self.url(
707-
Endpoints.drop_table, prefixed=True, purge=purge_requested, **self._split_identifier_for_path(identifier_tuple)
708-
),
703+
self.url(Endpoints.drop_table, prefixed=True, purge=purge_requested, **self._split_identifier_for_path(identifier)),
709704
)
710705
try:
711706
response.raise_for_status()
@@ -718,9 +713,8 @@ def purge_table(self, identifier: Union[str, Identifier]) -> None:
718713

719714
@retry(**_RETRY_ARGS)
720715
def rename_table(self, from_identifier: Union[str, Identifier], to_identifier: Union[str, Identifier]) -> Table:
721-
from_identifier_tuple = self._identifier_to_tuple_without_catalog(from_identifier)
722716
payload = {
723-
"source": self._split_identifier_for_json(from_identifier_tuple),
717+
"source": self._split_identifier_for_json(from_identifier),
724718
"destination": self._split_identifier_for_json(to_identifier),
725719
}
726720
response = self._session.post(self.url(Endpoints.rename_table), json=payload)
@@ -877,9 +871,8 @@ def table_exists(self, identifier: Union[str, Identifier]) -> bool:
877871
Returns:
878872
bool: True if the table exists, False otherwise.
879873
"""
880-
identifier_tuple = self._identifier_to_tuple_without_catalog(identifier)
881874
response = self._session.head(
882-
self.url(Endpoints.load_table, prefixed=True, **self._split_identifier_for_path(identifier_tuple))
875+
self.url(Endpoints.load_table, prefixed=True, **self._split_identifier_for_path(identifier))
883876
)
884877

885878
if response.status_code == 404:
@@ -896,11 +889,8 @@ def table_exists(self, identifier: Union[str, Identifier]) -> bool:
896889

897890
@retry(**_RETRY_ARGS)
898891
def drop_view(self, identifier: Union[str]) -> None:
899-
identifier_tuple = self._identifier_to_tuple_without_catalog(identifier)
900892
response = self._session.delete(
901-
self.url(
902-
Endpoints.drop_view, prefixed=True, **self._split_identifier_for_path(identifier_tuple, IdentifierKind.VIEW)
903-
),
893+
self.url(Endpoints.drop_view, prefixed=True, **self._split_identifier_for_path(identifier, IdentifierKind.VIEW)),
904894
)
905895
try:
906896
response.raise_for_status()

pyiceberg/catalog/sql.py

Lines changed: 10 additions & 15 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

@@ -308,10 +306,9 @@ def drop_table(self, identifier: Union[str, Identifier]) -> None:
308306
Raises:
309307
NoSuchTableError: If a table with the name does not exist.
310308
"""
311-
identifier_tuple = self._identifier_to_tuple_without_catalog(identifier)
312-
namespace_tuple = Catalog.namespace_from(identifier_tuple)
309+
namespace_tuple = Catalog.namespace_from(identifier)
313310
namespace = Catalog.namespace_to_string(namespace_tuple)
314-
table_name = Catalog.table_name_from(identifier_tuple)
311+
table_name = Catalog.table_name_from(identifier)
315312
with Session(self.engine) as session:
316313
if self.engine.dialect.supports_sane_rowcount:
317314
res = session.execute(
@@ -355,14 +352,12 @@ def rename_table(self, from_identifier: Union[str, Identifier], to_identifier: U
355352
TableAlreadyExistsError: If a table with the new name already exist.
356353
NoSuchNamespaceError: If the target namespace does not exist.
357354
"""
358-
from_identifier_tuple = self._identifier_to_tuple_without_catalog(from_identifier)
359-
to_identifier_tuple = self._identifier_to_tuple_without_catalog(to_identifier)
360-
from_namespace_tuple = Catalog.namespace_from(from_identifier_tuple)
355+
from_namespace_tuple = Catalog.namespace_from(from_identifier)
361356
from_namespace = Catalog.namespace_to_string(from_namespace_tuple)
362-
from_table_name = Catalog.table_name_from(from_identifier_tuple)
363-
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)
364359
to_namespace = Catalog.namespace_to_string(to_namespace_tuple)
365-
to_table_name = Catalog.table_name_from(to_identifier_tuple)
360+
to_table_name = Catalog.table_name_from(to_identifier)
366361
if not self._namespace_exists(to_namespace):
367362
raise NoSuchNamespaceError(f"Namespace does not exist: {to_namespace}")
368363
with Session(self.engine) as session:

tests/catalog/test_base.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -156,28 +156,28 @@ def commit_table(
156156
return CommitTableResponse(metadata=updated_metadata, metadata_location=new_metadata_location)
157157

158158
def load_table(self, identifier: Union[str, Identifier]) -> Table:
159-
identifier_tuple = self._identifier_to_tuple_without_catalog(identifier)
160159
try:
161-
return self.__tables[identifier_tuple]
160+
identifier = Catalog.identifier_to_tuple(identifier)
161+
return self.__tables[identifier]
162162
except KeyError as error:
163-
raise NoSuchTableError(f"Table does not exist: {identifier_tuple}") from error
163+
raise NoSuchTableError(f"Table does not exist: {identifier}") from error
164164

165165
def drop_table(self, identifier: Union[str, Identifier]) -> None:
166-
identifier_tuple = self._identifier_to_tuple_without_catalog(identifier)
167166
try:
168-
self.__tables.pop(identifier_tuple)
167+
identifier = Catalog.identifier_to_tuple(identifier)
168+
self.__tables.pop(identifier)
169169
except KeyError as error:
170-
raise NoSuchTableError(f"Table does not exist: {identifier_tuple}") from error
170+
raise NoSuchTableError(f"Table does not exist: {identifier}") from error
171171

172172
def purge_table(self, identifier: Union[str, Identifier]) -> None:
173173
self.drop_table(identifier)
174174

175175
def rename_table(self, from_identifier: Union[str, Identifier], to_identifier: Union[str, Identifier]) -> Table:
176-
identifier_tuple = self._identifier_to_tuple_without_catalog(from_identifier)
177176
try:
178-
table = self.__tables.pop(identifier_tuple)
177+
from_identifier = Catalog.identifier_to_tuple(from_identifier)
178+
table = self.__tables.pop(from_identifier)
179179
except KeyError as error:
180-
raise NoSuchTableError(f"Table does not exist: {identifier_tuple}") from error
180+
raise NoSuchTableError(f"Table does not exist: {from_identifier}") from error
181181

182182
to_identifier = Catalog.identifier_to_tuple(to_identifier)
183183
to_namespace = Catalog.namespace_from(to_identifier)
@@ -514,7 +514,7 @@ def test_rename_table(catalog: InMemoryCatalog) -> None:
514514

515515
# Then
516516
assert table._identifier == Catalog.identifier_to_tuple(new_table)
517-
517+
print(f"DEBUG: {table._identifier}")
518518
# And
519519
table = catalog.load_table(new_table)
520520
assert table._identifier == Catalog.identifier_to_tuple(new_table)

0 commit comments

Comments
 (0)