Skip to content

Commit 02b6a83

Browse files
rambleraptorkevinjqliu
authored andcommitted
PR comments
1 parent 0f1187d commit 02b6a83

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
@@ -1861,14 +1861,15 @@ def drop_view(self, identifier: str | Identifier) -> None:
18611861

18621862
@retry(**_RETRY_ARGS)
18631863
def rename_view(self, from_identifier: str | Identifier, to_identifier: str | Identifier) -> None:
1864+
self._check_endpoint(Capability.V1_RENAME_VIEW)
18641865
payload = {
18651866
"source": self._split_identifier_for_json(from_identifier),
18661867
"destination": self._split_identifier_for_json(to_identifier),
18671868
}
18681869

18691870
# Ensure source and destination namespaces exist before rename.
18701871
source_namespace = self._split_identifier_for_json(from_identifier)["namespace"]
1871-
dest_namespace = self._split_identifier_for_path(to_identifier)["namespace"]
1872+
dest_namespace = self._split_identifier_for_json(to_identifier)["namespace"]
18721873

18731874
if not self.namespace_exists(source_namespace):
18741875
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
@@ -121,6 +121,7 @@
121121
Capability.V1_CREATE_VIEW,
122122
Capability.V1_REGISTER_VIEW,
123123
Capability.V1_DELETE_VIEW,
124+
Capability.V1_RENAME_VIEW,
124125
Capability.V1_SUBMIT_TABLE_SCAN_PLAN,
125126
Capability.V1_TABLE_SCAN_PLAN_TASKS,
126127
]
@@ -3710,4 +3711,4 @@ def test_rename_view_destination_namespace_does_not_exist(rest_mock: Mocker) ->
37103711
catalog = RestCatalog("rest", uri=TEST_URI, token=TEST_TOKEN)
37113712
with pytest.raises(NoSuchNamespaceError) as exc_info:
37123713
catalog.rename_view(from_identifier, to_identifier)
3713-
assert "Destination namespace does not exist: non_existent_namespace" in str(exc_info.value)
3714+
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
@@ -767,6 +767,26 @@ def test_rest_identifiers_with_special_characters(
767767

768768

769769
@pytest.mark.integration
770+
def test_rest_rename_view(
771+
rest_catalog: RestCatalog, example_view_metadata_v1: dict[str, Any], database_name: str, view_name: str
772+
) -> None:
773+
from_identifier = (database_name, view_name)
774+
to_identifier = (database_name, f"{view_name}_renamed")
775+
776+
rest_catalog.create_namespace_if_not_exists(database_name)
777+
view = View(from_identifier, ViewMetadata.model_validate(example_view_metadata_v1))
778+
779+
rest_catalog.create_view(from_identifier, view.schema(), view.current_version())
780+
assert rest_catalog.view_exists(from_identifier)
781+
782+
rest_catalog.rename_view(from_identifier, to_identifier)
783+
784+
assert not rest_catalog.view_exists(from_identifier)
785+
assert rest_catalog.view_exists(to_identifier)
786+
787+
788+
@pytest.mark.integration
789+
@pytest.mark.skip(reason="Requires Iceberg REST Fixtures 1.11.x")
770790
def test_rest_custom_namespace_separator(rest_catalog: RestCatalog, table_schema_simple: Schema) -> None:
771791
"""
772792
Tests that the REST catalog correctly picks up the namespace-separator from the config endpoint.

0 commit comments

Comments
 (0)