Jefffrey commented on code in PR #10771:
URL: https://github.com/apache/arrow-rs/pull/10771#discussion_r3827010620


##########
arrow-avro/src/reader/record.rs:
##########
@@ -250,11 +250,15 @@ enum Decoder {
     /// String data encoded as UTF-8 bytes, but mapped to Arrow's 
StringViewArray
     StringView(OffsetBufferBuilder<i32>, Vec<u8>),
     Array(FieldRef, OffsetBufferBuilder<i32>, Box<Decoder>),
+    /// The trailing `usize` counts the rows appended since the last flush. A 
record with no
+    /// fields has no child array to take a length from, so this is the only 
length available to
+    /// it; it is maintained for every record to keep the arms uniform.
     Record(
         Fields,
         Vec<Decoder>,
         Vec<Option<AvroLiteral>>,
         Option<Projector>,
+        usize,

Review Comment:
   perhaps we should name the fields, now that we have many fields
   
   ```rust
   Record {
       fields: Fields,
       decoders: Vec<Decoder>,
       defaults: Vec<Option<AvroLiteral>>,
       projector: Option<Projector>,
       /// Useful when there are no fields (legal edge case)
       row_count: usize
   }
   ```



##########
arrow-avro/src/reader/record.rs:
##########
@@ -1614,12 +1625,20 @@ impl Decoder {
                 let offsets = flush_offsets(offsets);
                 Arc::new(ListArray::try_new(field.clone(), offsets, values, 
nulls)?)
             }
-            Self::Record(fields, encodings, _, _) => {
+            Self::Record(fields, encodings, _, _, len) => {
                 let arrays = encodings
                     .iter_mut()
                     .map(|x| x.flush(None))
                     .collect::<Result<Vec<_>, _>>()?;
-                Arc::new(StructArray::try_new(fields.clone(), arrays, nulls)?)
+                // An Avro record with no fields is legal and encodes to zero 
bytes, so it has to
+                // flush as a zero-field struct of the right length. 
`StructArray::try_new` infers
+                // the length from the first child, of which there is none.

Review Comment:
   ```suggestion
                   // In case there are no fields (legal, encodes to zero 
bytes), we manually specify
                   // the length for the output struct to account for this
   ```



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

Reply via email to