rdblue commented on a change in pull request #4318:
URL: https://github.com/apache/iceberg/pull/4318#discussion_r835955482



##########
File path: python/src/iceberg/table/schema.py
##########
@@ -0,0 +1,346 @@
+# 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.
+
+import sys
+from typing import Iterable, Tuple
+
+if sys.version_info >= (3, 8):  # pragma: no cover
+    from functools import singledispatchmethod
+    from typing import Protocol
+else:  # pragma: no cover
+    from typing_extensions import Protocol  # type: ignore
+    from singledispatch import singledispatchmethod  # type: ignore
+
+from iceberg.types import IcebergType, ListType, MapType, NestedField, 
StructType
+
+
+class SchemaVisitor(Protocol):
+    def visit(self, node) -> None:  # pragma: no cover
+        ...
+
+
+class Schema:
+    """Schema of a table
+
+    Example:
+        >>> from iceberg.table.schema import Schema
+        >>> from iceberg.types import BooleanType, IntegerType, NestedField, 
StringType
+        >>> fields = [ \
+            NestedField(field_id=1, name="foo", field_type=StringType(), 
is_optional=False), \
+            NestedField(field_id=2, name="bar", field_type=IntegerType(), 
is_optional=True), \
+            NestedField(field_id=3, name="baz", field_type=BooleanType(), 
is_optional=False), \
+        ]
+        >>> table_schema = Schema(fields=fields, schema_id=1, aliases={"qux": 
3})
+        >>> print(table_schema)
+        1: name=foo, type=string, required=True
+        2: name=bar, type=int, required=False
+        3: name=baz, type=boolean, required=True
+    """
+
+    def __init__(self, fields: Iterable[NestedField], schema_id: int, aliases: 
dict = {}):

Review comment:
       Instead of adding aliases right now, I recommend adding 
`identifier_field_ids`. Iceberg tables now track the fields that identify rows. 
Since this is a core part of the schema, I'd add it now. (This was probably 
missing from the python legacy codebase)
   
   The aliases map is primarily for reading Parquet files because we need to 
keep track of the name that was used in a file for projection. I would 
implement that later when we get to reading Parquet.




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