|
19 | 19 |
|
20 | 20 | import base64 |
21 | 21 | import os |
| 22 | +import pickle |
22 | 23 | from collections.abc import Callable, Iterator |
23 | 24 | from contextlib import contextmanager |
24 | 25 | from typing import Any, cast |
@@ -3736,21 +3737,27 @@ def test_load_responses_parse_labels( |
3736 | 3737 | assert response_type.model_validate({**payload, "labels": invalid}).labels == Labels() |
3737 | 3738 |
|
3738 | 3739 |
|
3739 | | -def test_load_table_with_labels(rest_mock: Mocker, example_table_metadata_with_snapshot_v1_rest_json: dict[str, Any]) -> None: |
3740 | | - rest_mock.get( |
3741 | | - f"{TEST_URI}v1/namespaces/fokko/tables/table", |
3742 | | - json={ |
3743 | | - **example_table_metadata_with_snapshot_v1_rest_json, |
3744 | | - "labels": {"object-labels": {"owner": "team-a"}, "fields": [{"field-id": 1, "labels": {"classification": "pii"}}]}, |
3745 | | - }, |
3746 | | - status_code=200, |
3747 | | - request_headers=TEST_HEADERS, |
3748 | | - ) |
| 3740 | +def test_table_labels_from_rest_responses( |
| 3741 | + rest_mock: Mocker, example_table_metadata_with_snapshot_v1_rest_json: dict[str, Any], table_schema_simple: Schema |
| 3742 | +) -> None: |
| 3743 | + response = { |
| 3744 | + **example_table_metadata_with_snapshot_v1_rest_json, |
| 3745 | + "labels": {"object-labels": {"owner": "team-a"}, "fields": [{"field-id": 1, "labels": {"classification": "pii"}}]}, |
| 3746 | + } |
| 3747 | + rest_mock.get(f"{TEST_URI}v1/namespaces/fokko/tables/table", json=response, status_code=200, request_headers=TEST_HEADERS) |
| 3748 | + rest_mock.post(f"{TEST_URI}v1/namespaces/fokko/tables", json=response, status_code=200, request_headers=TEST_HEADERS) |
| 3749 | + rest_mock.post(f"{TEST_URI}v1/namespaces/fokko/register", json=response, status_code=200, request_headers=TEST_HEADERS) |
3749 | 3750 | catalog = RestCatalog("rest", uri=TEST_URI, token=TEST_TOKEN) |
| 3751 | + expected = Labels(object_labels={"owner": "team-a"}, fields=[FieldLabel(field_id=1, labels={"classification": "pii"})]) |
| 3752 | + |
3750 | 3753 | table = catalog.load_table(("fokko", "table")) |
| 3754 | + created = catalog.create_table(("fokko", "table"), schema=table_schema_simple) |
| 3755 | + registered = catalog.register_table(("fokko", "table"), metadata_location="s3://warehouse/database/table/metadata.json") |
| 3756 | + for actual in (table, created, registered): |
| 3757 | + assert actual.labels == expected |
3751 | 3758 |
|
3752 | | - expected = Labels(object_labels={"owner": "team-a"}, fields=[FieldLabel(field_id=1, labels={"classification": "pii"})]) |
3753 | | - assert table.labels == expected |
| 3759 | + # A pickled table keeps its labels. Java does not serialize them, because BaseTable.labels is transient. |
| 3760 | + assert pickle.loads(pickle.dumps(table)).labels == expected |
3754 | 3761 |
|
3755 | 3762 | # Labels are not table state, so equality ignores them and refresh() keeps the labels from the first load. |
3756 | 3763 | assert table == Table( |
|
0 commit comments