Skip to content

Commit d3bfb41

Browse files
committed
PR comments
1 parent 48ee1ce commit d3bfb41

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
@@ -320,7 +320,6 @@ class ListViewsResponse(IcebergBaseModel):
320320
class RestCatalog(Catalog):
321321
uri: str
322322
_session: Session
323-
_supported_endpoints: set[Endpoint]
324323
_namespace_separator: str
325324

326325
def __init__(self, name: str, **properties: str):
@@ -337,6 +336,8 @@ def __init__(self, name: str, **properties: str):
337336
self._fetch_config()
338337
self._session = self._create_session()
339338
separator_from_properties = self.properties.get(NAMESPACE_SEPARATOR_PROPERTY, DEFAULT_NAMESPACE_SEPARATOR)
339+
if not separator_from_properties:
340+
raise ValueError("Namespace separator cannot be an empty string")
340341
self._namespace_separator = unquote(separator_from_properties)
341342

342343
def _create_session(self) -> Session:
@@ -534,8 +535,6 @@ def _identifier_to_validated_tuple(self, identifier: str | Identifier) -> Identi
534535
def _split_identifier_for_path(
535536
self, identifier: str | Identifier | TableIdentifier, kind: IdentifierKind = IdentifierKind.TABLE
536537
) -> Properties:
537-
from urllib.parse import quote
538-
539538
if isinstance(identifier, TableIdentifier):
540539
return {
541540
"namespace": self._encode_namespace_path(tuple(identifier.namespace.root)),
@@ -933,7 +932,7 @@ def list_namespaces(self, namespace: str | Identifier = ()) -> list[Identifier]:
933932
namespace_tuple = self.identifier_to_tuple(namespace)
934933
response = self._session.get(
935934
self.url(
936-
f"{Endpoints.list_namespaces}?parent={self._namespace_separator.join(namespace_tuple)}"
935+
f"{Endpoints.list_namespaces}?parent={self._encode_namespace_path(namespace_tuple)}"
937936
if namespace_tuple
938937
else Endpoints.list_namespaces
939938
),
@@ -983,14 +982,6 @@ def namespace_exists(self, namespace: str | Identifier) -> bool:
983982
namespace_tuple = self._check_valid_namespace_identifier(namespace)
984983
namespace = self._encode_namespace_path(namespace_tuple)
985984

986-
# fallback in order to work with older rest catalog implementations
987-
if Capability.V1_NAMESPACE_EXISTS not in self._supported_endpoints:
988-
try:
989-
self.load_namespace_properties(namespace_tuple)
990-
return True
991-
except NoSuchNamespaceError:
992-
return False
993-
994985
response = self._session.head(self.url(Endpoints.namespace_exists, namespace=namespace))
995986

996987
if response.status_code == 404:

tests/catalog/test_rest.py

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

1924-
assert actual_headers["Authorization"] == expected_auth_header
1925-
19261924

19271925
def test_custom_namespace_separator(rest_mock: Mocker) -> None:
19281926
custom_separator = "-"
@@ -1939,7 +1937,7 @@ def test_custom_namespace_separator(rest_mock: Mocker) -> None:
19391937
rest_mock.get(
19401938
f"{TEST_URI}v1/namespaces/{expected_url_path_segment}",
19411939
json={"namespace": [namespace_part1, namespace_part2], "properties": {"prop": "yes"}},
1942-
status_code=204,
1940+
status_code=200,
19431941
request_headers=TEST_HEADERS,
19441942
)
19451943

0 commit comments

Comments
 (0)