rdblue commented on code in PR #212:
URL: https://github.com/apache/iceberg-python/pull/212#discussion_r1426017219


##########
pyiceberg/table/name_mapping.py:
##########
@@ -0,0 +1,204 @@
+# 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.
+"""
+Contains everything around the name mapping.
+
+More information can be found on here:
+https://iceberg.apache.org/spec/#name-mapping-serialization
+"""
+from __future__ import annotations
+
+from abc import ABC, abstractmethod
+from collections import ChainMap
+from functools import cached_property, singledispatch
+from typing import Any, Dict, Generic, List, Set, TypeVar, Union
+
+from pydantic import Field, conset, model_serializer
+
+from pyiceberg.schema import Schema, SchemaVisitor, visit
+from pyiceberg.typedef import IcebergBaseModel, IcebergRootModel
+from pyiceberg.types import ListType, MapType, NestedField, PrimitiveType, 
StructType
+
+
+class MappedField(IcebergBaseModel):
+    field_id: int = Field(alias="field-id")
+    names: Set[str] = conset(str, min_length=1)
+    fields: List[MappedField] = Field(default_factory=list)
+
+    @model_serializer
+    def ser_model(self) -> Dict[str, Any]:
+        """Set custom serializer to leave out the field when it is empty."""
+        fields = {'fields': self.fields} if len(self.fields) > 0 else {}
+        return {
+            'field-id': self.field_id,
+            # Sort the names to give a consistent output in json
+            'names': sorted([self.names]),

Review Comment:
   Is it possible to preserve the order of names? I think there could be places 
that rely on order. For example, I've seen JSON conversion using a name mapping 
that looks for a field in the original order and uses the first one that's 
found. This would alter that at commit time.



-- 
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: issues-unsubscr...@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to