jecsand838 commented on code in PR #7966:
URL: https://github.com/apache/arrow-rs/pull/7966#discussion_r2220389587


##########
arrow-avro/src/reader/mod.rs:
##########
@@ -155,11 +155,17 @@ impl Decoder {
     /// Returns the number of bytes consumed.
     pub fn decode(&mut self, data: &[u8]) -> Result<usize, ArrowError> {
         let mut total_consumed = 0usize;
-        while total_consumed < data.len() && self.decoded_rows < 
self.batch_size {
-            let consumed = self.record_decoder.decode(&data[total_consumed..], 
1)?;
-            if consumed == 0 {
+        while self.decoded_rows < self.batch_size {
+            let buffer = &data[total_consumed..];
+            if buffer.is_empty() {
+                // No more data to process.
                 break;
             }
+            let consumed = self.record_decoder.decode(buffer, 1)?;
+            // A successful call to record_decoder.decode means one row was 
decoded.
+            // If `consumed` is 0 on a non-empty buffer, it implies a valid 
zero-byte record.
+            // We increment `decoded_rows` to mark progress and avoid an 
infinite loop.
+            // We add `consumed` (which can be 0) to `total_consumed`.

Review Comment:
   @scovich I went ahead and changed the code to:
   
   ```rust
           let mut total_consumed = 0usize;
           while total_consumed < data.len() && self.decoded_rows < 
self.batch_size {
               let consumed = 
self.record_decoder.decode(&data[total_consumed..], 1)?;
               // A successful call to record_decoder.decode means one row was 
decoded.
               // If `consumed` is 0 on a non-empty buffer, it implies a valid 
zero-byte record.
               // We increment `decoded_rows` to mark progress and avoid an 
infinite loop.
               // We add `consumed` (which can be 0) to `total_consumed`.
               total_consumed += consumed;
               self.decoded_rows += 1;
           }
   ```
   
   I'm working on a bigger update that covers schema resolution and a schema 
store. I split this code off of that work, which is the reason for the 
difference in structure. 
   
   My plan is to break that update up into two smaller PRs and there's a decent 
chance I'll have a more fundamental refinement for the `decode` loop in one of 
them.



-- 
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: github-unsubscr...@arrow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to