Repository navigation
Expose catalog labels on Table #4321
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
9e7a265
d1145be
c93fa5f
f1d11c0
17ff34f
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 | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -19,6 +19,7 @@ | |||||||
|
|
||||||||
| import base64 | ||||||||
| import os | ||||||||
| import pickle | ||||||||
| from collections.abc import Callable, Iterator | ||||||||
| from contextlib import contextmanager | ||||||||
| from typing import Any, cast | ||||||||
|
|
@@ -3734,3 +3735,43 @@ def test_load_responses_parse_labels( | |||||||
| assert response_type.model_validate(payload).labels == Labels() | ||||||||
| for invalid in invalid_values: | ||||||||
| assert response_type.model_validate({**payload, "labels": invalid}).labels == Labels() | ||||||||
|
|
||||||||
|
|
||||||||
| def test_table_labels_from_rest_responses( | ||||||||
| rest_mock: Mocker, example_table_metadata_with_snapshot_v1_rest_json: dict[str, Any], table_schema_simple: Schema | ||||||||
| ) -> None: | ||||||||
| response = { | ||||||||
| **example_table_metadata_with_snapshot_v1_rest_json, | ||||||||
| "labels": {"object-labels": {"owner": "team-a"}, "fields": [{"field-id": 1, "labels": {"classification": "pii"}}]}, | ||||||||
| } | ||||||||
| rest_mock.get(f"{TEST_URI}v1/namespaces/fokko/tables/table", json=response, status_code=200, request_headers=TEST_HEADERS) | ||||||||
| rest_mock.post(f"{TEST_URI}v1/namespaces/fokko/tables", json=response, status_code=200, request_headers=TEST_HEADERS) | ||||||||
| rest_mock.post(f"{TEST_URI}v1/namespaces/fokko/register", json=response, status_code=200, request_headers=TEST_HEADERS) | ||||||||
| catalog = RestCatalog("rest", uri=TEST_URI, token=TEST_TOKEN) | ||||||||
| expected = Labels(object_labels={"owner": "team-a"}, fields=[FieldLabel(field_id=1, labels={"classification": "pii"})]) | ||||||||
|
|
||||||||
| table = catalog.load_table(("fokko", "table")) | ||||||||
| created = catalog.create_table(("fokko", "table"), schema=table_schema_simple) | ||||||||
| registered = catalog.register_table(("fokko", "table"), metadata_location="s3://warehouse/database/table/metadata.json") | ||||||||
| for actual in (table, created, registered): | ||||||||
| assert actual.labels == expected | ||||||||
|
|
||||||||
| # A pickled table keeps its labels. Java does not serialize them, because BaseTable.labels is transient. | ||||||||
| assert pickle.loads(pickle.dumps(table)).labels == expected | ||||||||
|
|
||||||||
| # Labels are not table state, so equality ignores them and refresh() keeps the labels from the first load. | ||||||||
| assert table == Table( | ||||||||
| identifier=("fokko", "table"), | ||||||||
| metadata_location=example_table_metadata_with_snapshot_v1_rest_json["metadata-location"], | ||||||||
| metadata=TableMetadataV1(**example_table_metadata_with_snapshot_v1_rest_json["metadata"]), | ||||||||
| io=load_file_io(), | ||||||||
| catalog=catalog, | ||||||||
| ) | ||||||||
| rest_mock.get( | ||||||||
| f"{TEST_URI}v1/namespaces/fokko/tables/table", | ||||||||
| json={**example_table_metadata_with_snapshot_v1_rest_json, "labels": {"object-labels": {"owner": "team-b"}}}, | ||||||||
| status_code=200, | ||||||||
| request_headers=TEST_HEADERS, | ||||||||
| ) | ||||||||
| table.refresh() | ||||||||
| assert table.labels == expected | ||||||||
|
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. Could we pin the pickle behavior here? The description calls it the one difference from Java, where the field is
Suggested change
This also needs
Contributor
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. Done in f1d11c0, with your suggestion and |
||||||||
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.
Could this test also cover
create_tableandregister_table? They hand labels to the same_response_to_table(create, register), but only load is exercised. Mocking the three responses and checkinglabelsin aforloop here would do it, per AGENTS.md's preference for a loop overparametrize.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.
Done in f1d11c0. The test now mocks load, create, and register, and it checks
labelson all three tables. I renamed it totest_table_labels_from_rest_responses.