Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion pyiceberg/catalog/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion pyiceberg/catalog/dynamodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
MetastoreCatalog,
PropertiesUpdateSummary,
_get_aws_session_with_assumed_role,
_warn_rename_table_return_deprecated,
)
from pyiceberg.exceptions import (
ConditionalCheckFailedException,
Expand Down Expand Up @@ -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.
Expand All @@ -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)

Expand Down
4 changes: 3 additions & 1 deletion pyiceberg/catalog/glue.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
MetastoreCatalog,
PropertiesUpdateSummary,
_get_aws_session_with_assumed_role,
_warn_rename_table_return_deprecated,
)
from pyiceberg.exceptions import (
CommitFailedException,
Expand Down Expand Up @@ -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.
Expand All @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion pyiceberg/catalog/hive.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
URI,
MetastoreCatalog,
PropertiesUpdateSummary,
_warn_rename_table_return_deprecated,
)
from pyiceberg.exceptions import (
CommitFailedException,
Expand Down Expand Up @@ -721,14 +722,15 @@ 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.
NoSuchTableError: When a table with the name does not exist.
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)

Expand Down
11 changes: 10 additions & 1 deletion pyiceberg/catalog/rest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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),
Expand Down
4 changes: 3 additions & 1 deletion pyiceberg/catalog/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
Catalog,
MetastoreCatalog,
PropertiesUpdateSummary,
_warn_rename_table_return_deprecated,
)
from pyiceberg.exceptions import (
CommitFailedException,
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
15 changes: 15 additions & 0 deletions tests/catalog/test_catalog_behaviors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading