Fokko commented on code in PR #4320:
URL: https://github.com/apache/iceberg-python/pull/4320#discussion_r4529583427


##########
pyiceberg/table/labels.py:
##########
@@ -0,0 +1,53 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from typing import Any
+
+from pydantic import Field, model_validator
+
+from pyiceberg.typedef import IcebergBaseModel
+
+
+class FieldLabel(IcebergBaseModel):
+    """Labels attached to a single field, identified by its field ID."""
+
+    field_id: int = Field(alias="field-id")
+    labels: dict[str, str]
+
+
+class Labels(IcebergBaseModel):
+    """Optional labels that a catalog returns with a table or view.
+
+    Labels are enrichment supplied by the catalog, such as ownership or 
classification.
+    They are not table state and are not written to the table metadata.
+    """
+
+    object_labels: dict[str, str] = Field(alias="object-labels", 
default_factory=dict)
+    fields: list[FieldLabel] = Field(default_factory=list)
+
+    @model_validator(mode="before")
+    @classmethod
+    def treat_null_as_absent(cls, data: Any) -> Any:
+        # A null value parses the same as a missing key.
+        if data is None:
+            return {}
+        if isinstance(data, dict):
+            return {key: value for key, value in data.items() if value is not 
None}
+        return data

Review Comment:
   Agreed — pushed `d1145be9` to read non-object `labels` as empty, matching 
the Java parser. Thanks for the catch @laskoviymishka!



##########
tests/table/test_labels.py:
##########
@@ -0,0 +1,67 @@
+# Licensed to the Apache Software Foundation (ASF) under one

Review Comment:
   Following up here: #18047 is merged now, so the fixtures are ready. I'll add 
a fixture-based test as a follow-up.



-- 
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]

Reply via email to