Skip to content

Commit 9b88b83

Browse files
committed
PR comments
1 parent cf1e446 commit 9b88b83

2 files changed

Lines changed: 4 additions & 15 deletions

File tree

pyiceberg/catalog/rest/__init__.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,6 @@ class ListViewsResponse(IcebergBaseModel):
216216
class RestCatalog(Catalog):
217217
uri: str
218218
_session: Session
219-
_supported_endpoints: set[Endpoint]
220219
_namespace_separator: str
221220

222221
def __init__(self, name: str, **properties: str):
@@ -233,6 +232,8 @@ def __init__(self, name: str, **properties: str):
233232
self._fetch_config()
234233
self._session = self._create_session()
235234
separator_from_properties = self.properties.get(NAMESPACE_SEPARATOR_PROPERTY, DEFAULT_NAMESPACE_SEPARATOR)
235+
if not separator_from_properties:
236+
raise ValueError("Namespace separator cannot be an empty string")
236237
self._namespace_separator = unquote(separator_from_properties)
237238

238239
def _create_session(self) -> Session:
@@ -397,8 +398,6 @@ def _identifier_to_validated_tuple(self, identifier: str | Identifier) -> Identi
397398
def _split_identifier_for_path(
398399
self, identifier: str | Identifier | TableIdentifier, kind: IdentifierKind = IdentifierKind.TABLE
399400
) -> Properties:
400-
from urllib.parse import quote
401-
402401
if isinstance(identifier, TableIdentifier):
403402
return {
404403
"namespace": self._encode_namespace_path(tuple(identifier.namespace.root)),
@@ -784,7 +783,7 @@ def list_namespaces(self, namespace: str | Identifier = ()) -> list[Identifier]:
784783
namespace_tuple = self.identifier_to_tuple(namespace)
785784
response = self._session.get(
786785
self.url(
787-
f"{Endpoints.list_namespaces}?parent={self._namespace_separator.join(namespace_tuple)}"
786+
f"{Endpoints.list_namespaces}?parent={self._encode_namespace_path(namespace_tuple)}"
788787
if namespace_tuple
789788
else Endpoints.list_namespaces
790789
),
@@ -832,14 +831,6 @@ def namespace_exists(self, namespace: str | Identifier) -> bool:
832831
namespace_tuple = self._check_valid_namespace_identifier(namespace)
833832
namespace = self._encode_namespace_path(namespace_tuple)
834833

835-
# fallback in order to work with older rest catalog implementations
836-
if Capability.V1_NAMESPACE_EXISTS not in self._supported_endpoints:
837-
try:
838-
self.load_namespace_properties(namespace_tuple)
839-
return True
840-
except NoSuchNamespaceError:
841-
return False
842-
843834
response = self._session.head(self.url(Endpoints.namespace_exists, namespace=namespace))
844835

845836
if response.status_code == 404:

tests/catalog/test_rest.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1899,8 +1899,6 @@ def test_rest_catalog_with_google_credentials_path(
18991899
actual_headers = history[0].headers
19001900
assert actual_headers["Authorization"] == expected_auth_header
19011901

1902-
assert actual_headers["Authorization"] == expected_auth_header
1903-
19041902

19051903
def test_custom_namespace_separator(rest_mock: Mocker) -> None:
19061904
custom_separator = "-"
@@ -1917,7 +1915,7 @@ def test_custom_namespace_separator(rest_mock: Mocker) -> None:
19171915
rest_mock.get(
19181916
f"{TEST_URI}v1/namespaces/{expected_url_path_segment}",
19191917
json={"namespace": [namespace_part1, namespace_part2], "properties": {"prop": "yes"}},
1920-
status_code=204,
1918+
status_code=200,
19211919
request_headers=TEST_HEADERS,
19221920
)
19231921

0 commit comments

Comments
 (0)