diff --git a/pyiceberg/catalog/__init__.py b/pyiceberg/catalog/__init__.py index 5af504f8ac..2e304de633 100644 --- a/pyiceberg/catalog/__init__.py +++ b/pyiceberg/catalog/__init__.py @@ -69,6 +69,7 @@ TableVersion, ) from pyiceberg.utils.config import Config, merge_config +from pyiceberg.utils.deprecated import deprecation_message from pyiceberg.utils.properties import property_as_bool from pyiceberg.view import View from pyiceberg.view.metadata import ViewVersion @@ -393,6 +394,15 @@ class PropertiesUpdateSummary: missing: list[str] +def _warn_rename_table_return_deprecated() -> None: + deprecation_message( + deprecated_in="0.13.0", + removed_in="1.0.0", + help_message="The Table returned by rename_table is deprecated and will be None in 1.0.0; " + "use load_table() to load the renamed table", + ) + + class Catalog(ABC): """Base Catalog for table operations like - create, drop, load, list and others. @@ -592,7 +602,7 @@ def rename_table(self, from_identifier: str | Identifier, to_identifier: str | I to_identifier (str | Identifier): New table identifier. Returns: - Table: the updated table instance with its metadata. + Table: the updated table instance with its metadata. Deprecated: will return None in 1.0.0. Raises: NoSuchTableError: If a table with the name does not exist. diff --git a/pyiceberg/catalog/dynamodb.py b/pyiceberg/catalog/dynamodb.py index 2157c76e39..82fc12f164 100644 --- a/pyiceberg/catalog/dynamodb.py +++ b/pyiceberg/catalog/dynamodb.py @@ -35,6 +35,7 @@ MetastoreCatalog, PropertiesUpdateSummary, _get_aws_session_with_assumed_role, + _warn_rename_table_return_deprecated, ) from pyiceberg.exceptions import ( ConditionalCheckFailedException, @@ -328,7 +329,7 @@ def rename_table(self, from_identifier: str | Identifier, to_identifier: str | I to_identifier: New table identifier. Returns: - Table: the updated table instance with its metadata. + Table: the updated table instance with its metadata. Deprecated: will return None in 1.0.0. Raises: ValueError: When from table identifier is invalid. @@ -337,6 +338,7 @@ def rename_table(self, from_identifier: str | Identifier, to_identifier: str | I NoSuchPropertyException: When from table miss some required properties. NoSuchNamespaceError: When the destination namespace doesn't exist. """ + _warn_rename_table_return_deprecated() from_database_name, from_table_name = self.identifier_to_database_and_table(from_identifier, NoSuchTableError) to_database_name, to_table_name = self.identifier_to_database_and_table(to_identifier) diff --git a/pyiceberg/catalog/glue.py b/pyiceberg/catalog/glue.py index 9ba8775747..24eff60967 100644 --- a/pyiceberg/catalog/glue.py +++ b/pyiceberg/catalog/glue.py @@ -40,6 +40,7 @@ MetastoreCatalog, PropertiesUpdateSummary, _get_aws_session_with_assumed_role, + _warn_rename_table_return_deprecated, ) from pyiceberg.exceptions import ( CommitFailedException, @@ -804,7 +805,7 @@ def rename_table(self, from_identifier: str | Identifier, to_identifier: str | I to_identifier: New table identifier. Returns: - Table: the updated table instance with its metadata. + Table: the updated table instance with its metadata. Deprecated: will return None in 1.0.0. Raises: ValueError: When from table identifier is invalid. @@ -813,6 +814,7 @@ def rename_table(self, from_identifier: str | Identifier, to_identifier: str | I NoSuchPropertyException: When from table miss some required properties. NoSuchNamespaceError: When the destination namespace doesn't exist. """ + _warn_rename_table_return_deprecated() from_database_name, from_table_name = self.identifier_to_database_and_table(from_identifier, NoSuchTableError) to_database_name, to_table_name = self.identifier_to_database_and_table(to_identifier) try: diff --git a/pyiceberg/catalog/hive.py b/pyiceberg/catalog/hive.py index 0f43bbfb81..5bc3a6ce0a 100644 --- a/pyiceberg/catalog/hive.py +++ b/pyiceberg/catalog/hive.py @@ -64,6 +64,7 @@ URI, MetastoreCatalog, PropertiesUpdateSummary, + _warn_rename_table_return_deprecated, ) from pyiceberg.exceptions import ( CommitFailedException, @@ -721,7 +722,7 @@ def rename_table(self, from_identifier: str | Identifier, to_identifier: str | I to_identifier: New table identifier. Returns: - Table: the updated table instance with its metadata. + Table: the updated table instance with its metadata. Deprecated: will return None in 1.0.0. Raises: ValueError: When from table identifier is invalid. @@ -729,6 +730,7 @@ def rename_table(self, from_identifier: str | Identifier, to_identifier: str | I NoSuchNamespaceError: When the destination namespace doesn't exist. TableAlreadyExistsError: When the destination table already exists. """ + _warn_rename_table_return_deprecated() from_database_name, from_table_name = self.identifier_to_database_and_table(from_identifier, NoSuchTableError) to_database_name, to_table_name = self.identifier_to_database_and_table(to_identifier) diff --git a/pyiceberg/catalog/rest/__init__.py b/pyiceberg/catalog/rest/__init__.py index d9496f5711..4636a0be0a 100644 --- a/pyiceberg/catalog/rest/__init__.py +++ b/pyiceberg/catalog/rest/__init__.py @@ -39,7 +39,15 @@ from urllib3.util.retry import Retry from pyiceberg import __version__ -from pyiceberg.catalog import BOTOCORE_SESSION, TOKEN, URI, WAREHOUSE_LOCATION, Catalog, PropertiesUpdateSummary +from pyiceberg.catalog import ( + BOTOCORE_SESSION, + TOKEN, + URI, + WAREHOUSE_LOCATION, + Catalog, + PropertiesUpdateSummary, + _warn_rename_table_return_deprecated, +) from pyiceberg.catalog.rest.auth import AUTH_MANAGER, AuthManager, AuthManagerAdapter, AuthManagerFactory, LegacyOAuth2AuthManager from pyiceberg.catalog.rest.response import _handle_non_200_response from pyiceberg.catalog.rest.scan_planning import ( @@ -1541,6 +1549,7 @@ def purge_table(self, identifier: str | Identifier) -> None: @retry(**_RETRY_ARGS) @override def rename_table(self, from_identifier: str | Identifier, to_identifier: str | Identifier) -> Table: + _warn_rename_table_return_deprecated() self._check_endpoint(Capability.V1_RENAME_TABLE) payload = { "source": self._split_identifier_for_json(from_identifier), diff --git a/pyiceberg/catalog/sql.py b/pyiceberg/catalog/sql.py index d2c34a692e..f9910d6070 100644 --- a/pyiceberg/catalog/sql.py +++ b/pyiceberg/catalog/sql.py @@ -51,6 +51,7 @@ Catalog, MetastoreCatalog, PropertiesUpdateSummary, + _warn_rename_table_return_deprecated, ) from pyiceberg.exceptions import ( CommitFailedException, @@ -424,13 +425,14 @@ def rename_table(self, from_identifier: str | Identifier, to_identifier: str | I to_identifier (str | Identifier): New table identifier. Returns: - Table: the updated table instance with its metadata. + Table: the updated table instance with its metadata. Deprecated: will return None in 1.0.0. Raises: NoSuchTableError: If a table with the name does not exist. TableAlreadyExistsError: If a table with the new name already exist. NoSuchNamespaceError: If the target namespace does not exist. """ + _warn_rename_table_return_deprecated() from_namespace_tuple = Catalog.namespace_from(from_identifier) from_namespace = Catalog.namespace_to_string(from_namespace_tuple) from_table_name = Catalog.table_name_from(from_identifier) diff --git a/pyproject.toml b/pyproject.toml index dc5f7df558..56380a5f3c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -261,6 +261,8 @@ filterwarnings = [ "ignore:The copy keyword is deprecated and will be removed in a future version.*", # Ignore pyarrow's use of Series.values on tz-aware data under pandas 3.1 "ignore:Series.values returning an ndarray that drops timezone information.*", + # rename_table still returns a Table until 1.0.0 + "ignore:Deprecated in .*The Table returned by rename_table is deprecated.*:DeprecationWarning", ] [tool.mypy] diff --git a/tests/catalog/test_catalog_behaviors.py b/tests/catalog/test_catalog_behaviors.py index 4e51a4dbda..5d00529b80 100644 --- a/tests/catalog/test_catalog_behaviors.py +++ b/tests/catalog/test_catalog_behaviors.py @@ -474,6 +474,21 @@ def test_rename_table( catalog.load_table(test_table_identifier) +def test_rename_table_warns_about_deprecated_return_value( + catalog: Catalog, table_schema_nested: Schema, test_table_identifier: Identifier, another_table_identifier: Identifier +) -> None: + from_namespace = Catalog.namespace_from(test_table_identifier) + to_namespace = Catalog.namespace_from(another_table_identifier) + catalog.create_namespace(from_namespace) + catalog.create_namespace(to_namespace) + catalog.create_table(test_table_identifier, table_schema_nested) + + with pytest.warns(DeprecationWarning, match="rename_table"): + renamed_table = catalog.rename_table(test_table_identifier, another_table_identifier) + + assert renamed_table.name() == another_table_identifier + + def test_rename_table_from_self_identifier( catalog: Catalog, table_schema_nested: Schema, test_table_identifier: Identifier, another_table_identifier: Identifier ) -> None: