mzabaluev commented on code in PR #11751:
URL: https://github.com/apache/arrow-rs/pull/11751#discussion_r4606490103


##########
arrow-avro/src/reader/async_reader/mod.rs:
##########
@@ -422,59 +416,43 @@ impl<R: AsyncFileReader + Unpin + 'static> 
AsyncAvroFileReader<R> {
 
                     if matches!(self.block_decoder.state(), 
BlockDecoderState::Finished) {
                         // We've already flushed, so if no batch was produced, 
we are simply done.
-                        self.finishing_partial_block = false;
                         self.start_flushing();
                         continue;
                     }
 
-                    // If we've tried the following stage before, and still 
can't decode,
-                    // this means the file is truncated or corrupted.
-                    if self.finishing_partial_block {
-                        return self.finish_with_error(AvroError::EOF(
-                            "Unexpected EOF while reading last Avro 
block".into(),
-                        ));
-                    }
-
-                    // Avro splitting case: block is incomplete, we need to:
+                    // Avro splitting case: the data ran out in a block this 
range owns, we need to:
                     // 1. Parse the length so we know how much to read
                     // 2. Fetch more data from the reader
-                    // 3. Create a new block data from the remaining slice and 
the newly fetched data
-                    // 4. Continue decoding until end of block
-                    self.finishing_partial_block = true;
-
-                    // Mid-block, but we don't know how many bytes are missing 
yet
-                    if matches!(
-                        self.block_decoder.state(),
-                        BlockDecoderState::Count | BlockDecoderState::Size
-                    ) {
-                        // Max VLQ header is 20 bytes (10 bytes each for count 
and size).
-                        // Fetch just enough to complete it.
-                        const MAX_VLQ_HEADER_SIZE: u64 = 20;
-                        let fetch_end = (self.range.end + 
MAX_VLQ_HEADER_SIZE).min(self.file_size);
-
-                        // If there is nothing more to fetch, error out
-                        if fetch_end == self.range.end {
-                            return self.finish_with_error(AvroError::EOF(
-                                "Unexpected EOF while reading Avro block 
header".into(),
-                            ));
+                    // 3. Continue decoding until end of block
+                    // Every fetch extends `range.end`, so this terminates at 
the end of the file.
+                    let range_to_fetch = match self.block_decoder.state() {
+                        // Mid-block, but we don't know how many bytes are 
missing yet
+                        BlockDecoderState::Count | BlockDecoderState::Size => {
+                            // Max VLQ header is 20 bytes (10 bytes each for 
count and size).
+                            // Fetch just enough to complete it.
+                            const MAX_VLQ_HEADER_SIZE: u64 = 20;
+                            let fetch_end =
+                                (self.range.end + 
MAX_VLQ_HEADER_SIZE).min(self.file_size);
+
+                            if fetch_end == self.range.end {
+                                if matches!(self.block_decoder.state(), 
BlockDecoderState::Size) {

Review Comment:
   Thank you, fixed in 
[ed627cd](https://github.com/apache/arrow-rs/pull/11751/commits/ed627cda0bcc9c896769ca5c18ccf82c4de8e42c)



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