-
Notifications
You must be signed in to change notification settings - Fork 473
feat: add load_view to REST catalog #3224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -103,6 +103,7 @@ | |||||||||||||||||
| Capability.V1_RENAME_TABLE, | ||||||||||||||||||
| Capability.V1_REGISTER_TABLE, | ||||||||||||||||||
| Capability.V1_LIST_VIEWS, | ||||||||||||||||||
| Capability.V1_LOAD_VIEW, | ||||||||||||||||||
| Capability.V1_VIEW_EXISTS, | ||||||||||||||||||
| Capability.V1_DELETE_VIEW, | ||||||||||||||||||
| Capability.V1_SUBMIT_TABLE_SCAN_PLAN, | ||||||||||||||||||
|
|
@@ -1449,6 +1450,38 @@ def test_create_view_409( | |||||||||||||||||
| assert "View already exists" in str(e.value) | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
| def test_load_view_200(rest_mock: Mocker, example_view_metadata_rest_json: dict[str, Any]) -> None: | ||||||||||||||||||
| rest_mock.get( | ||||||||||||||||||
| f"{TEST_URI}v1/namespaces/fokko/views/view", | ||||||||||||||||||
| json=example_view_metadata_rest_json, | ||||||||||||||||||
| status_code=200, | ||||||||||||||||||
| request_headers=TEST_HEADERS, | ||||||||||||||||||
| ) | ||||||||||||||||||
| catalog = RestCatalog("rest", uri=TEST_URI, token=TEST_TOKEN) | ||||||||||||||||||
| actual = catalog.load_view(("fokko", "view")) | ||||||||||||||||||
| expected = View(identifier=("fokko", "view"), metadata=ViewMetadata(**example_view_metadata_rest_json["metadata"])) | ||||||||||||||||||
| assert actual == expected | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
| def test_load_view_404(rest_mock: Mocker) -> None: | ||||||||||||||||||
| rest_mock.get( | ||||||||||||||||||
| f"{TEST_URI}v1/namespaces/fokko/views/non_existent_view", | ||||||||||||||||||
| json={ | ||||||||||||||||||
| "error": { | ||||||||||||||||||
| "message": "View does not exist: examples.non_existent_view in warehouse 8bcb0838-50fc-472d-9ddb-8feb89ef5f1e", | ||||||||||||||||||
| "type": "NoSuchNamespaceErrorException", | ||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this NoSuchNamespaceErrorException instead of NoSuchViewException? 404:
description:
Not Found - NoSuchViewException, view to load does not exist
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorModel'
examples:
ViewToLoadDoesNotExist:
$ref: '#/components/examples/NoSuchViewError'
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch. I agree, this should be a There are a two tests for tables in the same file that also return the wrong error type. These should return iceberg-python/tests/catalog/test_rest.py Lines 1157 to 1160 in b67b724
iceberg-python/tests/catalog/test_rest.py Lines 1218 to 1221 in b67b724
Should I fix all of these in one go or create a issue for the table tests? |
||||||||||||||||||
| "code": 404, | ||||||||||||||||||
| } | ||||||||||||||||||
| }, | ||||||||||||||||||
| status_code=404, | ||||||||||||||||||
| request_headers=TEST_HEADERS, | ||||||||||||||||||
| ) | ||||||||||||||||||
|
|
||||||||||||||||||
| with pytest.raises(NoSuchViewError) as e: | ||||||||||||||||||
| RestCatalog("rest", uri=TEST_URI, token=TEST_TOKEN).load_view(("fokko", "non_existent_view")) | ||||||||||||||||||
| assert "View does not exist" in str(e.value) | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
| def test_create_table_if_not_exists_200( | ||||||||||||||||||
| rest_mock: Mocker, table_schema_simple: Schema, example_table_metadata_no_snapshot_v1_rest_json: dict[str, Any] | ||||||||||||||||||
| ) -> None: | ||||||||||||||||||
|
|
||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would also add a test that should return a view does not exists when trying to load a table with loadView
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct me if I'm wrong, but isn't this case already covered with the
test_load_view_404test?If no view with the same identifier as the table identifier is found in the warehouse, this would be the same case as loading a non existent view.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is implementation dependent on the server, so this is an edge case to return the correct exception
But the test is better placed in integration tests rather than mocking
Would be cool to also add integration tests to the test_catalog.py