diff --git a/pyiceberg/catalog/rest.py b/pyiceberg/catalog/rest.py index 28d1a85da5..cc6d891e63 100644 --- a/pyiceberg/catalog/rest.py +++ b/pyiceberg/catalog/rest.py @@ -14,6 +14,7 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. +from enum import Enum from json import JSONDecodeError from typing import ( TYPE_CHECKING, @@ -102,6 +103,11 @@ class Endpoints: drop_view: str = "namespaces/{namespace}/views/{view}" +class IdentifierKind(Enum): + TABLE = "table" + VIEW = "view" + + AUTHORIZATION_HEADER = "Authorization" BEARER_PREFIX = "Bearer" CATALOG_SCOPE = "catalog" @@ -395,15 +401,17 @@ def _identifier_to_validated_tuple(self, identifier: Union[str, Identifier]) -> raise NoSuchIdentifierError(f"Missing namespace or invalid identifier: {'.'.join(identifier_tuple)}") return identifier_tuple - def _split_identifier_for_path(self, identifier: Union[str, Identifier, TableIdentifier], kind: str = "table") -> Properties: + def _split_identifier_for_path( + self, identifier: Union[str, Identifier, TableIdentifier], kind: IdentifierKind = IdentifierKind.TABLE + ) -> Properties: if isinstance(identifier, TableIdentifier): if identifier.namespace.root[0] == self.name: - return {"namespace": NAMESPACE_SEPARATOR.join(identifier.namespace.root[1:]), "table": identifier.name} + return {"namespace": NAMESPACE_SEPARATOR.join(identifier.namespace.root[1:]), kind.value: identifier.name} else: - return {"namespace": NAMESPACE_SEPARATOR.join(identifier.namespace.root), "table": identifier.name} + return {"namespace": NAMESPACE_SEPARATOR.join(identifier.namespace.root), kind.value: identifier.name} identifier_tuple = self._identifier_to_validated_tuple(identifier) - return {"namespace": NAMESPACE_SEPARATOR.join(identifier_tuple[:-1]), kind: identifier_tuple[-1]} + return {"namespace": NAMESPACE_SEPARATOR.join(identifier_tuple[:-1]), kind.value: identifier_tuple[-1]} def _split_identifier_for_json(self, identifier: Union[str, Identifier]) -> Dict[str, Union[Identifier, str]]: identifier_tuple = self._identifier_to_validated_tuple(identifier) @@ -876,7 +884,9 @@ def table_exists(self, identifier: Union[str, Identifier]) -> bool: def drop_view(self, identifier: Union[str]) -> None: identifier_tuple = self.identifier_to_tuple_without_catalog(identifier) response = self._session.delete( - self.url(Endpoints.drop_view, prefixed=True, **self._split_identifier_for_path(identifier_tuple, kind="view")), + self.url( + Endpoints.drop_view, prefixed=True, **self._split_identifier_for_path(identifier_tuple, IdentifierKind.VIEW) + ), ) try: response.raise_for_status()