Skip to content
Open
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
7 changes: 4 additions & 3 deletions pyiceberg/catalog/rest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1368,7 +1368,7 @@ def create_view(
try:
response.raise_for_status()
except HTTPError as exc:
_handle_non_200_response(exc, {409: ViewAlreadyExistsError})
_handle_non_200_response(exc, {404: NoSuchNamespaceError, 409: ViewAlreadyExistsError})

view_response = ViewResponse.model_validate_json(response.text)
return self._response_to_view(self.identifier_to_tuple(identifier), view_response)
Expand All @@ -1388,6 +1388,7 @@ def register_table(self, identifier: str | Identifier, metadata_location: str, o

Raises:
TableAlreadyExistsError: If the table already exists
NoSuchNamespaceError: If the namespace does not exist
"""
self._check_endpoint(Capability.V1_REGISTER_TABLE)
namespace_and_table = self._split_identifier_for_path(identifier)
Expand All @@ -1405,7 +1406,7 @@ def register_table(self, identifier: str | Identifier, metadata_location: str, o
try:
response.raise_for_status()
except HTTPError as exc:
_handle_non_200_response(exc, {409: TableAlreadyExistsError})
_handle_non_200_response(exc, {404: NoSuchNamespaceError, 409: TableAlreadyExistsError})

table_response = TableResponse.model_validate_json(response.text)
return self._response_to_table(self.identifier_to_tuple(identifier), table_response)
Expand Down Expand Up @@ -1893,7 +1894,7 @@ def register_view(self, identifier: str | Identifier, metadata_location: str) ->
try:
response.raise_for_status()
except HTTPError as exc:
_handle_non_200_response(exc, {409: ViewAlreadyExistsError})
_handle_non_200_response(exc, {404: NoSuchNamespaceError, 409: ViewAlreadyExistsError})

view_response = ViewResponse.model_validate_json(response.text)
return self._response_to_view(self.identifier_to_tuple(identifier), view_response)
Expand Down
82 changes: 82 additions & 0 deletions tests/catalog/test_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1853,6 +1853,28 @@ def test_create_table_409(rest_mock: Mocker, table_schema_simple: Schema) -> Non
assert "Table already exists" in str(e.value)


def test_register_table_404(rest_mock: Mocker) -> None:
rest_mock.post(
f"{TEST_URI}v1/namespaces/fokko/register",
json={
"error": {
"message": "Namespace does not exist: fokko in warehouse 8bcb0838-50fc-472d-9ddb-8feb89ef5f1e",
"type": "NoSuchNamespaceException",
"code": 404,
}
},
status_code=404,
request_headers=TEST_HEADERS,
)

catalog = RestCatalog("rest", uri=TEST_URI, token=TEST_TOKEN)
with pytest.raises(NoSuchNamespaceError) as e:
catalog.register_table(
identifier=("fokko", "registered_table"), metadata_location="s3://warehouse/database/table/metadata.json"
)
assert "Namespace does not exist" in str(e.value)


def test_create_view_200(rest_mock: Mocker, table_schema_simple: Schema, example_view_metadata_rest_json: dict[str, Any]) -> None:
rest_mock.post(
f"{TEST_URI}v1/namespaces/fokko/views",
Expand Down Expand Up @@ -1942,6 +1964,66 @@ def test_create_view_409(
assert "View already exists" in str(e.value)


def test_register_view_404(rest_mock: Mocker) -> None:
rest_mock.head(
f"{TEST_URI}v1/namespaces/fokko/tables/registered_view",
status_code=404,
request_headers=TEST_HEADERS,
)
rest_mock.post(
f"{TEST_URI}v1/namespaces/fokko/register-view",
json={
"error": {
"message": "Namespace does not exist: fokko in warehouse 8bcb0838-50fc-472d-9ddb-8feb89ef5f1e",
"type": "NoSuchNamespaceException",
"code": 404,
}
},
status_code=404,
request_headers=TEST_HEADERS,
)

catalog = RestCatalog("rest", uri=TEST_URI, token=TEST_TOKEN)
with pytest.raises(NoSuchNamespaceError) as e:
catalog.register_view(
identifier=("fokko", "registered_view"), metadata_location="s3://warehouse/database/view/metadata.json"
)
assert "Namespace does not exist" in str(e.value)


def test_create_view_404(
rest_mock: Mocker,
table_schema_simple: Schema,
) -> None:
rest_mock.post(
f"{TEST_URI}v1/namespaces/fokko/views",
json={
"error": {
"message": "Namespace does not exist: fokko in warehouse 8bcb0838-50fc-472d-9ddb-8feb89ef5f1e",
"type": "NoSuchNamespaceException",
"code": 404,
}
},
status_code=404,
request_headers=TEST_HEADERS,
)

with pytest.raises(NoSuchNamespaceError) as e:
RestCatalog("rest", uri=TEST_URI, token=TEST_TOKEN).create_view(
identifier=("fokko", "fokko2"),
schema=table_schema_simple,
view_version=ViewVersion(
schema_id=1,
summary={"engine-name": "spark", "engineVersion": "3.3"},
representations=[],
default_namespace=[],
),
location=None,
properties={"owner": "fokko"},
)
assert "Namespace does not exist" in str(e.value)


def test_load_view_200(rest_mock: Mocker, example_view_metadata_rest_json: dict[str, Any]) -> None:
rest_mock.get(
f"{TEST_URI}v1/namespaces/fokko/views/view",
Expand Down
Loading