Fokko commented on code in PR #4920:
URL: https://github.com/apache/iceberg/pull/4920#discussion_r893419914


##########
python/src/iceberg/avro/reader.py:
##########
@@ -0,0 +1,284 @@
+# 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.
+# pylint: disable=W0621
+"""
+Avro reader for reading Avro files
+"""
+from __future__ import annotations
+
+import json
+from dataclasses import dataclass, field
+from io import SEEK_SET
+from typing import (
+    Any,
+    Dict,
+    List,
+    Type,
+    Union,
+)
+
+from iceberg.avro.codec import KNOWN_CODECS, Codec, NullCodec
+from iceberg.avro.decoder import BinaryDecoder
+from iceberg.files import StructProtocol
+from iceberg.io.base import InputFile, InputStream
+from iceberg.schema import Schema, SchemaVisitor, visit
+from iceberg.types import (
+    BinaryType,
+    BooleanType,
+    DateType,
+    DecimalType,
+    DoubleType,
+    FixedType,
+    FloatType,
+    IntegerType,
+    ListType,
+    LongType,
+    MapType,
+    NestedField,
+    PrimitiveType,
+    StringType,
+    StructType,
+    TimestampType,
+    TimestamptzType,
+    TimeType,
+)
+from iceberg.utils.schema_conversion import AvroSchemaConversion
+
+
+@dataclass(frozen=True)
+class AvroStructProtocol(StructProtocol):
+    _data: List[Union[Any, StructProtocol]] = field(default_factory=list)
+
+    def set(self, pos: int, value: Any) -> None:
+        self._data[pos] = value
+
+    def get(self, pos: int) -> Any:
+        return self._data[pos]
+
+
+class _AvroReader(SchemaVisitor[Union[AvroStructProtocol, Any]]):

Review Comment:
   I've refactored the code and added a reader tree. I love the approach 
because it gives a much nicer decoupling between the actual reading and the 
schema. This will make the reader/writer schema much easier to implement. 
   
   I kept it as simple as possible to not prematurely optimize the code and 
keep the PR a bit more concise. We can add things like reusing structs, dicts 
and lists later on.



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