kevinjqliu commented on code in PR #4151:
URL: https://github.com/apache/iceberg-python/pull/4151#discussion_r4369097852
##########
pyiceberg/catalog/rest/__init__.py:
##########
@@ -1825,15 +1825,14 @@ def view_exists(self, identifier: str | Identifier) ->
bool:
def register_view(self, identifier: str | Identifier, metadata_location:
str) -> View:
self._check_endpoint(Capability.V1_REGISTER_VIEW)
namespace_and_view = self._split_identifier_for_path(identifier,
IdentifierKind.VIEW)
- namespace = namespace_and_view["namespace"]
- view = namespace_and_view["view"]
+ identifier_tuple = self._identifier_to_validated_tuple(identifier)
if self.table_exists(identifier):
- raise TableAlreadyExistsError(f"Table {namespace}.{view} already
exists")
+ raise TableAlreadyExistsError(f"Table {'.'.join(identifier_tuple)}
already exists")
- request = RegisterViewRequest(name=view,
metadata_location=metadata_location)
+ request = RegisterViewRequest(name=identifier_tuple[-1],
metadata_location=metadata_location)
serialized_json = request.model_dump_json().encode(UTF8)
response = self._session.post(
- self.url(Endpoints.register_view, namespace=namespace),
+ self.url(Endpoints.register_view,
namespace=namespace_and_view["namespace"]),
Review Comment:
follows register_table
https://github.com/apache/iceberg-python/blob/12d4a9a3ced73da290626bde6019ac2835d5c636/pyiceberg/catalog/rest/__init__.py#L1352-L1360
##########
tests/integration/test_catalog.py:
##########
@@ -719,6 +719,42 @@ def test_rest_drop_view(
assert not rest_catalog.view_exists(identifier)
[email protected]
+def test_rest_identifiers_with_special_characters(
Review Comment:
integration test that checks special character handling on relevant endpoints
##########
pyiceberg/catalog/rest/__init__.py:
##########
@@ -1311,7 +1311,7 @@ def create_view(
location = location.rstrip("/")
request = CreateViewRequest(
- name=namespace_and_view["view"],
+ name=self._identifier_to_validated_tuple(identifier)[-1],
Review Comment:
use `_identifier_to_validated_tuple` for request bodies so names aren't
escaped, and escape only in URL paths.
mirrors `CreateTableRequest`
https://github.com/apache/iceberg-python/blob/12d4a9a3ced73da290626bde6019ac2835d5c636/pyiceberg/catalog/rest/__init__.py#L1230-L1238
##########
pyiceberg/catalog/rest/__init__.py:
##########
Review Comment:
The bug was using the wrong helper in the request body. The body should not
be escaped, the URL should be. We should probably do some refactoring here
(esp. with the naming).
| Helper | Escaped? | Returns for `("ns", "my view")` | Use for |
| --- | --- | --- | --- |
| `_identifier_to_validated_tuple(identifier)` | No | `("ns", "my view")` |
JSON body, error messages. Raises `NoSuchIdentifierError` if there's no
namespace |
| `_split_identifier_for_path(identifier, kind)` | Yes | `{"namespace":
"ns", "view": "my%20view"}` | URL path only |
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]