Skip to content

Commit eca9870

Browse files
authored
Deprecate Redundant Identifier Support in TableIdentifier, and row_filter (#994)
1 parent debda66 commit eca9870

File tree

12 files changed

+156
-101
lines changed

12 files changed

+156
-101
lines changed

pyiceberg/catalog/__init__.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
RecursiveDict,
6868
)
6969
from pyiceberg.utils.config import Config, merge_config
70-
from pyiceberg.utils.deprecated import deprecation_message
70+
from pyiceberg.utils.deprecated import deprecated, deprecation_message
7171

7272
if TYPE_CHECKING:
7373
import pyarrow as pa
@@ -613,6 +613,11 @@ def update_namespace_properties(
613613
ValueError: If removals and updates have overlapping keys.
614614
"""
615615

616+
@deprecated(
617+
deprecated_in="0.8.0",
618+
removed_in="0.9.0",
619+
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.",
620+
)
616621
def identifier_to_tuple_without_catalog(self, identifier: Union[str, Identifier]) -> Identifier:
617622
"""Convert an identifier to a tuple and drop this catalog's name from the first element.
618623
@@ -627,6 +632,25 @@ def identifier_to_tuple_without_catalog(self, identifier: Union[str, Identifier]
627632
identifier_tuple = identifier_tuple[1:]
628633
return identifier_tuple
629634

635+
def _identifier_to_tuple_without_catalog(self, identifier: Union[str, Identifier]) -> Identifier:
636+
"""Convert an identifier to a tuple and drop this catalog's name from the first element.
637+
638+
Args:
639+
identifier (str | Identifier): Table identifier.
640+
641+
Returns:
642+
Identifier: a tuple of strings with this catalog's name removed
643+
"""
644+
identifier_tuple = Catalog.identifier_to_tuple(identifier)
645+
if len(identifier_tuple) >= 3 and identifier_tuple[0] == self.name:
646+
deprecation_message(
647+
deprecated_in="0.8.0",
648+
removed_in="0.9.0",
649+
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.",
650+
)
651+
identifier_tuple = identifier_tuple[1:]
652+
return identifier_tuple
653+
630654
@staticmethod
631655
def identifier_to_tuple(identifier: Union[str, Identifier]) -> Identifier:
632656
"""Parse an identifier to a tuple.
@@ -769,7 +793,7 @@ def table_exists(self, identifier: Union[str, Identifier]) -> bool:
769793
return False
770794

771795
def purge_table(self, identifier: Union[str, Identifier]) -> None:
772-
identifier_tuple = self.identifier_to_tuple_without_catalog(identifier)
796+
identifier_tuple = self._identifier_to_tuple_without_catalog(identifier)
773797
table = self.load_table(identifier_tuple)
774798
self.drop_table(identifier_tuple)
775799
io = load_file_io(self.properties, table.metadata_location)
@@ -823,7 +847,7 @@ def _create_staged_table(
823847
)
824848
io = self._load_file_io(properties=properties, location=metadata_location)
825849
return StagedTable(
826-
identifier=(self.name, database_name, table_name),
850+
identifier=(database_name, table_name),
827851
metadata=metadata,
828852
metadata_location=metadata_location,
829853
io=io,

pyiceberg/catalog/dynamodb.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ def load_table(self, identifier: Union[str, Identifier]) -> Table:
246246
Raises:
247247
NoSuchTableError: If a table with the name does not exist, or the identifier is invalid.
248248
"""
249-
identifier_tuple = self.identifier_to_tuple_without_catalog(identifier)
249+
identifier_tuple = self._identifier_to_tuple_without_catalog(identifier)
250250
database_name, table_name = self.identifier_to_database_and_table(identifier_tuple, NoSuchTableError)
251251
dynamo_table_item = self._get_iceberg_table_item(database_name=database_name, table_name=table_name)
252252
return self._convert_dynamo_table_item_to_iceberg_table(dynamo_table_item=dynamo_table_item)
@@ -260,7 +260,7 @@ def drop_table(self, identifier: Union[str, Identifier]) -> None:
260260
Raises:
261261
NoSuchTableError: If a table with the name does not exist, or the identifier is invalid.
262262
"""
263-
identifier_tuple = self.identifier_to_tuple_without_catalog(identifier)
263+
identifier_tuple = self._identifier_to_tuple_without_catalog(identifier)
264264
database_name, table_name = self.identifier_to_database_and_table(identifier_tuple, NoSuchTableError)
265265

266266
try:
@@ -291,7 +291,7 @@ def rename_table(self, from_identifier: Union[str, Identifier], to_identifier: U
291291
NoSuchPropertyException: When from table miss some required properties.
292292
NoSuchNamespaceError: When the destination namespace doesn't exist.
293293
"""
294-
from_identifier_tuple = self.identifier_to_tuple_without_catalog(from_identifier)
294+
from_identifier_tuple = self._identifier_to_tuple_without_catalog(from_identifier)
295295
from_database_name, from_table_name = self.identifier_to_database_and_table(from_identifier_tuple, NoSuchTableError)
296296
to_database_name, to_table_name = self.identifier_to_database_and_table(to_identifier)
297297

@@ -638,7 +638,7 @@ def _convert_dynamo_table_item_to_iceberg_table(self, dynamo_table_item: Dict[st
638638
file = io.new_input(metadata_location)
639639
metadata = FromInputFile.table_metadata(file)
640640
return Table(
641-
identifier=(self.name, database_name, table_name),
641+
identifier=(database_name, table_name),
642642
metadata=metadata,
643643
metadata_location=metadata_location,
644644
io=self._load_file_io(metadata.properties, metadata_location),

pyiceberg/catalog/glue.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ def _convert_glue_to_iceberg(self, glue_table: TableTypeDef) -> Table:
346346
file = io.new_input(metadata_location)
347347
metadata = FromInputFile.table_metadata(file)
348348
return Table(
349-
identifier=(self.name, database_name, table_name),
349+
identifier=(database_name, table_name),
350350
metadata=metadata,
351351
metadata_location=metadata_location,
352352
io=self._load_file_io(metadata.properties, metadata_location),
@@ -462,7 +462,7 @@ def _commit_table(self, table_request: CommitTableRequest) -> CommitTableRespons
462462
NoSuchTableError: If a table with the given identifier does not exist.
463463
CommitFailedException: Requirement not met, or a conflict with a concurrent commit.
464464
"""
465-
identifier_tuple = self.identifier_to_tuple_without_catalog(
465+
identifier_tuple = self._identifier_to_tuple_without_catalog(
466466
tuple(table_request.identifier.namespace.root + [table_request.identifier.name])
467467
)
468468
database_name, table_name = self.identifier_to_database_and_table(identifier_tuple)
@@ -541,7 +541,7 @@ def load_table(self, identifier: Union[str, Identifier]) -> Table:
541541
Raises:
542542
NoSuchTableError: If a table with the name does not exist, or the identifier is invalid.
543543
"""
544-
identifier_tuple = self.identifier_to_tuple_without_catalog(identifier)
544+
identifier_tuple = self._identifier_to_tuple_without_catalog(identifier)
545545
database_name, table_name = self.identifier_to_database_and_table(identifier_tuple, NoSuchTableError)
546546

547547
return self._convert_glue_to_iceberg(self._get_glue_table(database_name=database_name, table_name=table_name))
@@ -555,7 +555,7 @@ def drop_table(self, identifier: Union[str, Identifier]) -> None:
555555
Raises:
556556
NoSuchTableError: If a table with the name does not exist, or the identifier is invalid.
557557
"""
558-
identifier_tuple = self.identifier_to_tuple_without_catalog(identifier)
558+
identifier_tuple = self._identifier_to_tuple_without_catalog(identifier)
559559
database_name, table_name = self.identifier_to_database_and_table(identifier_tuple, NoSuchTableError)
560560
try:
561561
self.glue.delete_table(DatabaseName=database_name, Name=table_name)
@@ -581,7 +581,7 @@ def rename_table(self, from_identifier: Union[str, Identifier], to_identifier: U
581581
NoSuchPropertyException: When from table miss some required properties.
582582
NoSuchNamespaceError: When the destination namespace doesn't exist.
583583
"""
584-
from_identifier_tuple = self.identifier_to_tuple_without_catalog(from_identifier)
584+
from_identifier_tuple = self._identifier_to_tuple_without_catalog(from_identifier)
585585
from_database_name, from_table_name = self.identifier_to_database_and_table(from_identifier_tuple, NoSuchTableError)
586586
to_database_name, to_table_name = self.identifier_to_database_and_table(to_identifier)
587587
try:

pyiceberg/catalog/hive.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -289,15 +289,15 @@ def _convert_hive_into_iceberg(self, table: HiveTable) -> Table:
289289
file = io.new_input(metadata_location)
290290
metadata = FromInputFile.table_metadata(file)
291291
return Table(
292-
identifier=(self.name, table.dbName, table.tableName),
292+
identifier=(table.dbName, table.tableName),
293293
metadata=metadata,
294294
metadata_location=metadata_location,
295295
io=self._load_file_io(metadata.properties, metadata_location),
296296
catalog=self,
297297
)
298298

299299
def _convert_iceberg_into_hive(self, table: Table) -> HiveTable:
300-
identifier_tuple = self.identifier_to_tuple_without_catalog(table.identifier)
300+
identifier_tuple = self._identifier_to_tuple_without_catalog(table.identifier)
301301
database_name, table_name = self.identifier_to_database_and_table(identifier_tuple, NoSuchTableError)
302302
current_time_millis = int(time.time() * 1000)
303303

@@ -431,7 +431,7 @@ def _commit_table(self, table_request: CommitTableRequest) -> CommitTableRespons
431431
NoSuchTableError: If a table with the given identifier does not exist.
432432
CommitFailedException: Requirement not met, or a conflict with a concurrent commit.
433433
"""
434-
identifier_tuple = self.identifier_to_tuple_without_catalog(
434+
identifier_tuple = self._identifier_to_tuple_without_catalog(
435435
tuple(table_request.identifier.namespace.root + [table_request.identifier.name])
436436
)
437437
database_name, table_name = self.identifier_to_database_and_table(identifier_tuple, NoSuchTableError)
@@ -477,7 +477,7 @@ def _commit_table(self, table_request: CommitTableRequest) -> CommitTableRespons
477477
# Table does not exist, create it.
478478
hive_table = self._convert_iceberg_into_hive(
479479
StagedTable(
480-
identifier=(self.name, database_name, table_name),
480+
identifier=(database_name, table_name),
481481
metadata=updated_staged_table.metadata,
482482
metadata_location=updated_staged_table.metadata_location,
483483
io=updated_staged_table.io,
@@ -509,7 +509,7 @@ def load_table(self, identifier: Union[str, Identifier]) -> Table:
509509
Raises:
510510
NoSuchTableError: If a table with the name does not exist, or the identifier is invalid.
511511
"""
512-
identifier_tuple = self.identifier_to_tuple_without_catalog(identifier)
512+
identifier_tuple = self._identifier_to_tuple_without_catalog(identifier)
513513
database_name, table_name = self.identifier_to_database_and_table(identifier_tuple, NoSuchTableError)
514514

515515
with self._client as open_client:
@@ -526,7 +526,7 @@ def drop_table(self, identifier: Union[str, Identifier]) -> None:
526526
Raises:
527527
NoSuchTableError: If a table with the name does not exist, or the identifier is invalid.
528528
"""
529-
identifier_tuple = self.identifier_to_tuple_without_catalog(identifier)
529+
identifier_tuple = self._identifier_to_tuple_without_catalog(identifier)
530530
database_name, table_name = self.identifier_to_database_and_table(identifier_tuple, NoSuchTableError)
531531
try:
532532
with self._client as open_client:
@@ -554,7 +554,7 @@ def rename_table(self, from_identifier: Union[str, Identifier], to_identifier: U
554554
NoSuchTableError: When a table with the name does not exist.
555555
NoSuchNamespaceError: When the destination namespace doesn't exist.
556556
"""
557-
from_identifier_tuple = self.identifier_to_tuple_without_catalog(from_identifier)
557+
from_identifier_tuple = self._identifier_to_tuple_without_catalog(from_identifier)
558558
from_database_name, from_table_name = self.identifier_to_database_and_table(from_identifier_tuple, NoSuchTableError)
559559
to_database_name, to_table_name = self.identifier_to_database_and_table(to_identifier)
560560
try:

pyiceberg/catalog/rest.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ def add_headers(self, request: PreparedRequest, **kwargs: Any) -> None: # pylin
495495

496496
def _response_to_table(self, identifier_tuple: Tuple[str, ...], table_response: TableResponse) -> Table:
497497
return Table(
498-
identifier=(self.name,) + identifier_tuple if self.name else identifier_tuple,
498+
identifier=identifier_tuple,
499499
metadata_location=table_response.metadata_location, # type: ignore
500500
metadata=table_response.metadata,
501501
io=self._load_file_io(
@@ -506,7 +506,7 @@ def _response_to_table(self, identifier_tuple: Tuple[str, ...], table_response:
506506

507507
def _response_to_staged_table(self, identifier_tuple: Tuple[str, ...], table_response: TableResponse) -> StagedTable:
508508
return StagedTable(
509-
identifier=(self.name,) + identifier_tuple if self.name else identifier_tuple,
509+
identifier=identifier_tuple if self.name else identifier_tuple,
510510
metadata_location=table_response.metadata_location, # type: ignore
511511
metadata=table_response.metadata,
512512
io=self._load_file_io(
@@ -664,7 +664,7 @@ def list_tables(self, namespace: Union[str, Identifier]) -> List[Identifier]:
664664

665665
@retry(**_RETRY_ARGS)
666666
def load_table(self, identifier: Union[str, Identifier]) -> Table:
667-
identifier_tuple = self.identifier_to_tuple_without_catalog(identifier)
667+
identifier_tuple = self._identifier_to_tuple_without_catalog(identifier)
668668
response = self._session.get(
669669
self.url(Endpoints.load_table, prefixed=True, **self._split_identifier_for_path(identifier_tuple))
670670
)
@@ -678,7 +678,7 @@ def load_table(self, identifier: Union[str, Identifier]) -> Table:
678678

679679
@retry(**_RETRY_ARGS)
680680
def drop_table(self, identifier: Union[str, Identifier], purge_requested: bool = False) -> None:
681-
identifier_tuple = self.identifier_to_tuple_without_catalog(identifier)
681+
identifier_tuple = self._identifier_to_tuple_without_catalog(identifier)
682682
response = self._session.delete(
683683
self.url(
684684
Endpoints.drop_table, prefixed=True, purge=purge_requested, **self._split_identifier_for_path(identifier_tuple)
@@ -695,7 +695,7 @@ def purge_table(self, identifier: Union[str, Identifier]) -> None:
695695

696696
@retry(**_RETRY_ARGS)
697697
def rename_table(self, from_identifier: Union[str, Identifier], to_identifier: Union[str, Identifier]) -> Table:
698-
from_identifier_tuple = self.identifier_to_tuple_without_catalog(from_identifier)
698+
from_identifier_tuple = self._identifier_to_tuple_without_catalog(from_identifier)
699699
payload = {
700700
"source": self._split_identifier_for_json(from_identifier_tuple),
701701
"destination": self._split_identifier_for_json(to_identifier),
@@ -830,7 +830,7 @@ def table_exists(self, identifier: Union[str, Identifier]) -> bool:
830830
Returns:
831831
bool: True if the table exists, False otherwise.
832832
"""
833-
identifier_tuple = self.identifier_to_tuple_without_catalog(identifier)
833+
identifier_tuple = self._identifier_to_tuple_without_catalog(identifier)
834834
response = self._session.head(
835835
self.url(Endpoints.load_table, prefixed=True, **self._split_identifier_for_path(identifier_tuple))
836836
)

pyiceberg/catalog/sql.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def _convert_orm_to_iceberg(self, orm_table: IcebergTables) -> Table:
155155
file = io.new_input(metadata_location)
156156
metadata = FromInputFile.table_metadata(file)
157157
return Table(
158-
identifier=(self.name,) + Catalog.identifier_to_tuple(table_namespace) + (table_name,),
158+
identifier=Catalog.identifier_to_tuple(table_namespace) + (table_name,),
159159
metadata=metadata,
160160
metadata_location=metadata_location,
161161
io=self._load_file_io(metadata.properties, metadata_location),
@@ -192,7 +192,7 @@ def create_table(
192192
"""
193193
schema: Schema = self._convert_schema_if_needed(schema) # type: ignore
194194

195-
identifier_nocatalog = self.identifier_to_tuple_without_catalog(identifier)
195+
identifier_nocatalog = self._identifier_to_tuple_without_catalog(identifier)
196196
namespace_identifier = Catalog.namespace_from(identifier_nocatalog)
197197
table_name = Catalog.table_name_from(identifier_nocatalog)
198198
if not self._namespace_exists(namespace_identifier):
@@ -238,7 +238,7 @@ def register_table(self, identifier: Union[str, Identifier], metadata_location:
238238
TableAlreadyExistsError: If the table already exists
239239
NoSuchNamespaceError: If namespace does not exist
240240
"""
241-
identifier_tuple = self.identifier_to_tuple_without_catalog(identifier)
241+
identifier_tuple = self._identifier_to_tuple_without_catalog(identifier)
242242
namespace_tuple = Catalog.namespace_from(identifier_tuple)
243243
namespace = Catalog.namespace_to_string(namespace_tuple)
244244
table_name = Catalog.table_name_from(identifier_tuple)
@@ -277,7 +277,7 @@ def load_table(self, identifier: Union[str, Identifier]) -> Table:
277277
Raises:
278278
NoSuchTableError: If a table with the name does not exist.
279279
"""
280-
identifier_tuple = self.identifier_to_tuple_without_catalog(identifier)
280+
identifier_tuple = self._identifier_to_tuple_without_catalog(identifier)
281281
namespace_tuple = Catalog.namespace_from(identifier_tuple)
282282
namespace = Catalog.namespace_to_string(namespace_tuple)
283283
table_name = Catalog.table_name_from(identifier_tuple)
@@ -301,7 +301,7 @@ def drop_table(self, identifier: Union[str, Identifier]) -> None:
301301
Raises:
302302
NoSuchTableError: If a table with the name does not exist.
303303
"""
304-
identifier_tuple = self.identifier_to_tuple_without_catalog(identifier)
304+
identifier_tuple = self._identifier_to_tuple_without_catalog(identifier)
305305
namespace_tuple = Catalog.namespace_from(identifier_tuple)
306306
namespace = Catalog.namespace_to_string(namespace_tuple)
307307
table_name = Catalog.table_name_from(identifier_tuple)
@@ -348,8 +348,8 @@ def rename_table(self, from_identifier: Union[str, Identifier], to_identifier: U
348348
TableAlreadyExistsError: If a table with the new name already exist.
349349
NoSuchNamespaceError: If the target namespace does not exist.
350350
"""
351-
from_identifier_tuple = self.identifier_to_tuple_without_catalog(from_identifier)
352-
to_identifier_tuple = self.identifier_to_tuple_without_catalog(to_identifier)
351+
from_identifier_tuple = self._identifier_to_tuple_without_catalog(from_identifier)
352+
to_identifier_tuple = self._identifier_to_tuple_without_catalog(to_identifier)
353353
from_namespace_tuple = Catalog.namespace_from(from_identifier_tuple)
354354
from_namespace = Catalog.namespace_to_string(from_namespace_tuple)
355355
from_table_name = Catalog.table_name_from(from_identifier_tuple)
@@ -407,7 +407,7 @@ def _commit_table(self, table_request: CommitTableRequest) -> CommitTableRespons
407407
NoSuchTableError: If a table with the given identifier does not exist.
408408
CommitFailedException: Requirement not met, or a conflict with a concurrent commit.
409409
"""
410-
identifier_tuple = self.identifier_to_tuple_without_catalog(
410+
identifier_tuple = self._identifier_to_tuple_without_catalog(
411411
tuple(table_request.identifier.namespace.root + [table_request.identifier.name])
412412
)
413413
namespace_tuple = Catalog.namespace_from(identifier_tuple)

0 commit comments

Comments
 (0)