linyiru opened a new issue, #12496:
URL: https://github.com/apache/arrow-rs/issues/12496

   ### Describe the bug
   
   `parquet-testing/data/repeated_no_annotation.parquet` (written by 
`parquet-rs version 0.3.0`) has `FileMetaData.num_rows = 0` and one row group 
with `num_rows = 6`. `ParquetRecordBatchReader` reads it as an empty file, 
without an error. The record API (`get_row_iter`) returns the 6 rows, and so 
does pyarrow 26.0.1.
   
   The cause is the batch size clamp, which uses the file-level count:
   
   ```rust
   // parquet/src/arrow/arrow_reader/mod.rs:312 (with_batch_size) and :1371 
(build)
   let batch_size = batch_size.min(metadata.file_metadata().num_rows() as 
usize);
   ```
   
   A batch size of 0 ends the iteration before the first batch.
   
   ### To Reproduce
   
   ```rust
   use std::fs::File;
   
   use parquet::arrow::arrow_reader::ParquetRecordBatchReaderBuilder;
   use parquet::file::reader::{FileReader, SerializedFileReader};
   
   fn main() {
       let path = "parquet-testing/data/repeated_no_annotation.parquet";
   
       let builder = 
ParquetRecordBatchReaderBuilder::try_new(File::open(path).unwrap()).unwrap();
       let metadata = builder.metadata().clone();
       println!("file num_rows = {}", metadata.file_metadata().num_rows());
       println!("row group num_rows = {}", metadata.row_group(0).num_rows());
   
       let rows: usize = builder.build().unwrap().map(|b| 
b.unwrap().num_rows()).sum();
       println!("ParquetRecordBatchReader: {rows} rows");
   
       let reader = 
SerializedFileReader::new(File::open(path).unwrap()).unwrap();
       println!("get_row_iter: {} rows", 
reader.get_row_iter(None).unwrap().count());
   }
   ```
   
   Output on 60.2.0 and on main (d470f2d54):
   
   ```
   file num_rows = 0
   row group num_rows = 6
   ParquetRecordBatchReader: 0 rows
   get_row_iter: 6 rows
   ```
   
   ### Expected behavior
   
   6 rows. The clamp exists to avoid a large allocation for a small file, and 
the row groups are what the reader decodes, so their row counts are the bound 
to use.
   
   ### Additional context
   
   More generally, a file-level `num_rows` smaller than the row groups' total 
silently caps every batch at that size.
   
   This report was prepared with AI assistance (Claude Code). The reproduction 
was run against 60.2.0 and main.
   
   ### Willingness to contribute
   
   I plan to contribute a fix for this bug independently
   


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