Skip to content

Commit 792f1ed

Browse files
Add labels support to LoadTableResponse and Table
Adds optional labels field to IRC LoadTableResponse, parsed by the REST catalog client and exposed on Table objects. - TableResponse: new labels dict field (default empty, backward compatible) - Table: labels property + table_labels, column_labels, get_column_label() - Column labels keyed by field-id for stability across schema evolution Proof-of-concept for the IRC Labels proposal.
1 parent 3e35d1b commit 792f1ed

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

pyiceberg/catalog/rest/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ class TableResponse(IcebergBaseModel):
278278
metadata: TableMetadata
279279
config: Properties = Field(default_factory=dict)
280280
storage_credentials: list[StorageCredential] = Field(alias="storage-credentials", default_factory=list)
281+
labels: dict[str, Any] = Field(default_factory=dict)
281282

282283

283284
class ViewResponse(IcebergBaseModel):
@@ -805,6 +806,7 @@ def _response_to_table(self, identifier_tuple: tuple[str, ...], table_response:
805806
),
806807
catalog=self,
807808
config=table_response.config,
809+
labels=table_response.labels,
808810
)
809811

810812
def _response_to_staged_table(self, identifier_tuple: tuple[str, ...], table_response: TableResponse) -> StagedTable:

pyiceberg/table/__init__.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,6 +1049,7 @@ class Table:
10491049
io: FileIO
10501050
catalog: Catalog
10511051
config: dict[str, str]
1052+
labels: dict[str, Any]
10521053

10531054
def __init__(
10541055
self,
@@ -1058,13 +1059,32 @@ def __init__(
10581059
io: FileIO,
10591060
catalog: Catalog,
10601061
config: dict[str, str] = EMPTY_DICT,
1062+
labels: dict[str, Any] | None = None,
10611063
) -> None:
10621064
self._identifier = identifier
10631065
self.metadata = metadata
10641066
self.metadata_location = metadata_location
10651067
self.io = io
10661068
self.catalog = catalog
10671069
self.config = config
1070+
self.labels = labels or {}
1071+
1072+
@property
1073+
def table_labels(self) -> dict[str, str]:
1074+
"""Table-level labels from catalog enrichment."""
1075+
return self.labels.get("table", {})
1076+
1077+
@property
1078+
def column_labels(self) -> list[dict]:
1079+
"""Column-level labels from catalog enrichment."""
1080+
return self.labels.get("columns", [])
1081+
1082+
def get_column_label(self, field_id: int) -> dict[str, str]:
1083+
"""Get labels for a specific column by field-id."""
1084+
for col in self.column_labels:
1085+
if col.get("field-id") == field_id:
1086+
return col.get("labels", {})
1087+
return {}
10681088

10691089
def transaction(self) -> Transaction:
10701090
"""Create a new transaction object to first stage the changes, and then commit them to the catalog.

0 commit comments

Comments
 (0)