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


##########
python/src/iceberg/avro/reader.py:
##########
@@ -211,26 +282,39 @@ class MapReader(Reader):
 
     def read(self, decoder: BinaryDecoder) -> dict:
         read_items = {}
-        block_count = decoder.read_long()
+        block_count = decoder.read_int()
         while block_count != 0:
             if block_count < 0:
                 block_count = -block_count
                 # We ignore the block size for now
-                _ = decoder.read_long()
+                _ = decoder.read_int()
             for _ in range(block_count):
                 key = self.key.read(decoder)
                 read_items[key] = self.value.read(decoder)
-            block_count = decoder.read_long()
+            block_count = decoder.read_int()
 
         return read_items
 
+    def skip(self, decoder: BinaryDecoder) -> None:
+        block_count = decoder.read_int()
+        while block_count != 0:
+            if block_count < 0:
+                block_count = -block_count
+                block_size = decoder.read_int()
+                decoder.skip(block_size)
+            else:
+                for _ in range(block_count):
+                    self.key.skip(decoder)
+                    self.value.skip(decoder)
+                block_count = decoder.read_int()

Review Comment:
   I've refactored this to a function:
   ```python
   def _skip_map_array(decoder: BinaryDecoder, skip_entry: Callable) -> None:
       """Skips over an array or map
   
       Both the array and map are encoded similar, and we can re-use
       the logic of skipping in an efficient way.
   
       From the Avro spec:
   
       Maps (and arrays) are encoded as a series of blocks.
       Each block consists of a long count value, followed by that many 
key/value pairs in the case of a map,
       and followed by that many array items in the case of an array. A block 
with count zero indicates the
       end of the map. Each item is encoded per the map's value schema.
   
       If a block's count is negative, its absolute value is used, and the 
count is followed immediately by a
       long block size indicating the number of bytes in the block. This block 
size permits fast skipping
       through data, e.g., when projecting a record to a subset of its fields.
   
       Args:
           decoder:
               The decoder that reads the types from the underlying data
           skip_entry:
               Function to skip over the underlying data, element in case of an 
array, and the
               key/value in the case of a map
       """
       block_count = decoder.read_int()
       while block_count != 0:
           if block_count < 0:
               # The length in bytes in encoded, so we can skip over it right 
away
               block_size = decoder.read_int()
               decoder.skip(block_size)
           else:
               [skip_entry() for _ in range(block_count)]
           block_count = decoder.read_int()
   ```



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