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


##########
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 suggested the other approach for a few reasons. First, I think when it is 
reasonable to match the approach taken by the Java codebase, that's a good 
idea. That way we don't have completely different implementations to validate 
and maintain.
   
   Second, this approach traverses the schema for each record read. That is 
inefficient compared to building a tree of readers that handle this. The reader 
tree approach allows us to create basically a state machine that is ready to 
read records.
   
   Last, this is harder to update. The next step is to reconcile the 
differences between the read and write schemas. Doing that for every record is 
hard to write with this approach. Same thing with reusing structs, dicts, and 
lists.



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