|
14 | 14 | # KIND, either express or implied. See the License for the |
15 | 15 | # specific language governing permissions and limitations |
16 | 16 | # under the License. |
| 17 | +from enum import Enum |
17 | 18 | from json import JSONDecodeError |
18 | 19 | from typing import ( |
19 | 20 | TYPE_CHECKING, |
@@ -102,6 +103,11 @@ class Endpoints: |
102 | 103 | drop_view: str = "namespaces/{namespace}/views/{view}" |
103 | 104 |
|
104 | 105 |
|
| 106 | +class IdentifierKind(Enum): |
| 107 | + TABLE = "table" |
| 108 | + VIEW = "view" |
| 109 | + |
| 110 | + |
105 | 111 | AUTHORIZATION_HEADER = "Authorization" |
106 | 112 | BEARER_PREFIX = "Bearer" |
107 | 113 | CATALOG_SCOPE = "catalog" |
@@ -395,15 +401,17 @@ def _identifier_to_validated_tuple(self, identifier: Union[str, Identifier]) -> |
395 | 401 | raise NoSuchIdentifierError(f"Missing namespace or invalid identifier: {'.'.join(identifier_tuple)}") |
396 | 402 | return identifier_tuple |
397 | 403 |
|
398 | | - def _split_identifier_for_path(self, identifier: Union[str, Identifier, TableIdentifier], kind: str = "table") -> Properties: |
| 404 | + def _split_identifier_for_path( |
| 405 | + self, identifier: Union[str, Identifier, TableIdentifier], kind: IdentifierKind = IdentifierKind.TABLE |
| 406 | + ) -> Properties: |
399 | 407 | if isinstance(identifier, TableIdentifier): |
400 | 408 | if identifier.namespace.root[0] == self.name: |
401 | | - return {"namespace": NAMESPACE_SEPARATOR.join(identifier.namespace.root[1:]), "table": identifier.name} |
| 409 | + return {"namespace": NAMESPACE_SEPARATOR.join(identifier.namespace.root[1:]), kind.value: identifier.name} |
402 | 410 | else: |
403 | | - return {"namespace": NAMESPACE_SEPARATOR.join(identifier.namespace.root), "table": identifier.name} |
| 411 | + return {"namespace": NAMESPACE_SEPARATOR.join(identifier.namespace.root), kind.value: identifier.name} |
404 | 412 | identifier_tuple = self._identifier_to_validated_tuple(identifier) |
405 | 413 |
|
406 | | - return {"namespace": NAMESPACE_SEPARATOR.join(identifier_tuple[:-1]), kind: identifier_tuple[-1]} |
| 414 | + return {"namespace": NAMESPACE_SEPARATOR.join(identifier_tuple[:-1]), kind.value: identifier_tuple[-1]} |
407 | 415 |
|
408 | 416 | def _split_identifier_for_json(self, identifier: Union[str, Identifier]) -> Dict[str, Union[Identifier, str]]: |
409 | 417 | identifier_tuple = self._identifier_to_validated_tuple(identifier) |
@@ -876,7 +884,9 @@ def table_exists(self, identifier: Union[str, Identifier]) -> bool: |
876 | 884 | def drop_view(self, identifier: Union[str]) -> None: |
877 | 885 | identifier_tuple = self.identifier_to_tuple_without_catalog(identifier) |
878 | 886 | response = self._session.delete( |
879 | | - self.url(Endpoints.drop_view, prefixed=True, **self._split_identifier_for_path(identifier_tuple, kind="view")), |
| 887 | + self.url( |
| 888 | + Endpoints.drop_view, prefixed=True, **self._split_identifier_for_path(identifier_tuple, IdentifierKind.VIEW) |
| 889 | + ), |
880 | 890 | ) |
881 | 891 | try: |
882 | 892 | response.raise_for_status() |
|
0 commit comments