Skip to content

Commit e88fe55

Browse files
committed
PR comments
1 parent f9a2e62 commit e88fe55

4 files changed

Lines changed: 25 additions & 2 deletions

File tree

pyiceberg/catalog/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,7 @@ def rename_view(self, from_identifier: str | Identifier, to_identifier: str | Id
754754
755755
Raises:
756756
NoSuchViewError: If a view with the name does not exist.
757+
ViewAlreadyExistsError: If the target view already exists.
757758
"""
758759

759760
@staticmethod

pyiceberg/catalog/rest/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1508,14 +1508,15 @@ def drop_view(self, identifier: str | Identifier) -> None:
15081508

15091509
@retry(**_RETRY_ARGS)
15101510
def rename_view(self, from_identifier: str | Identifier, to_identifier: str | Identifier) -> None:
1511+
self._check_endpoint(Capability.V1_RENAME_VIEW)
15111512
payload = {
15121513
"source": self._split_identifier_for_json(from_identifier),
15131514
"destination": self._split_identifier_for_json(to_identifier),
15141515
}
15151516

15161517
# Ensure source and destination namespaces exist before rename.
15171518
source_namespace = self._split_identifier_for_json(from_identifier)["namespace"]
1518-
dest_namespace = self._split_identifier_for_path(to_identifier)["namespace"]
1519+
dest_namespace = self._split_identifier_for_json(to_identifier)["namespace"]
15191520

15201521
if not self.namespace_exists(source_namespace):
15211522
raise NoSuchNamespaceError(f"Source namespace does not exist: {source_namespace}")

tests/catalog/test_rest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
Capability.V1_VIEW_EXISTS,
111111
Capability.V1_REGISTER_VIEW,
112112
Capability.V1_DELETE_VIEW,
113+
Capability.V1_RENAME_VIEW,
113114
Capability.V1_SUBMIT_TABLE_SCAN_PLAN,
114115
Capability.V1_TABLE_SCAN_PLAN_TASKS,
115116
]
@@ -3314,4 +3315,4 @@ def test_rename_view_destination_namespace_does_not_exist(rest_mock: Mocker) ->
33143315
catalog = RestCatalog("rest", uri=TEST_URI, token=TEST_TOKEN)
33153316
with pytest.raises(NoSuchNamespaceError) as exc_info:
33163317
catalog.rename_view(from_identifier, to_identifier)
3317-
assert "Destination namespace does not exist: non_existent_namespace" in str(exc_info.value)
3318+
assert "Destination namespace does not exist: ('non_existent_namespace',)" in str(exc_info.value)

tests/integration/test_catalog.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,26 @@ def test_rest_drop_view(
670670

671671

672672
@pytest.mark.integration
673+
def test_rest_rename_view(
674+
rest_catalog: RestCatalog, example_view_metadata_v1: dict[str, Any], database_name: str, view_name: str
675+
) -> None:
676+
from_identifier = (database_name, view_name)
677+
to_identifier = (database_name, f"{view_name}_renamed")
678+
679+
rest_catalog.create_namespace_if_not_exists(database_name)
680+
view = View(from_identifier, ViewMetadata.model_validate(example_view_metadata_v1))
681+
682+
rest_catalog.create_view(from_identifier, view.schema(), view.current_version())
683+
assert rest_catalog.view_exists(from_identifier)
684+
685+
rest_catalog.rename_view(from_identifier, to_identifier)
686+
687+
assert not rest_catalog.view_exists(from_identifier)
688+
assert rest_catalog.view_exists(to_identifier)
689+
690+
691+
@pytest.mark.integration
692+
@pytest.mark.skip(reason="Requires Iceberg REST Fixtures 1.11.x")
673693
def test_rest_custom_namespace_separator(rest_catalog: RestCatalog, table_schema_simple: Schema) -> None:
674694
"""
675695
Tests that the REST catalog correctly picks up the namespace-separator from the config endpoint.

0 commit comments

Comments
 (0)