alamb commented on code in PR #7524:
URL: https://github.com/apache/arrow-rs/pull/7524#discussion_r2095501882


##########
parquet/src/arrow/arrow_reader/mod.rs:
##########
@@ -808,58 +841,92 @@ impl ParquetRecordBatchReader {
     fn next_inner(&mut self) -> Result<Option<RecordBatch>> {
         let mut read_records = 0;
         let batch_size = self.batch_size();
+
+        let mut mask_builder = BooleanBufferBuilder::new(batch_size);
+
         match self.read_plan.selection_mut() {
             Some(selection) => {
-                while read_records < batch_size && !selection.is_empty() {
-                    let front = selection.pop_front().unwrap();
-                    if front.skip {
-                        let skipped = 
self.array_reader.skip_records(front.row_count)?;
+                while let Some(cur_selection) =
+                    take_next_selection(selection, batch_size - read_records)
+                {
+                    let mut total_read = 0;
+                    let mut total_skip = 0;
+                    for r in cur_selection.iter() {
+                        if r.skip {
+                            total_skip += r.row_count;
+                        } else {
+                            total_read += r.row_count;
+                        }
+                    }
+                    let select_count = cur_selection.iter().count();
+                    let total = total_skip + total_read;
 
-                        if skipped != front.row_count {
-                            return Err(general_err!(
+                    if total < 10 * select_count {
+                        let mut bitmap_builder = 
BooleanBufferBuilder::new(total);

Review Comment:
   Since many of these read selections come from a BooleanBuffer originally 
(the result of evaluating a ArrowPredicate), I wonder what you think about 
potentially avoiding creating `RowSelection`s in the ReadPlan 
   
   Something like
   
   ```rust
   enum DecodeRows {
     /// Decode exactly the rows accoding to the row selection
     RowSelection(RowSelection),
     /// Decode all rows, and then apply a filter to keep only the ones that 
matter
     Bitmask(BooleanBuffer)
   }
     
   impl ReadPlan {
     // instead of Selection, have DecodeRows
     decode_plan: VecDeque<DecodeRows>;
   }
   ```
   
   And then the trick would be some sort of heuristic / adaptive approach to 
turn the result of the ArrowPredicate into a `DecodeRows` plan 
   
   
   
https://github.com/apache/arrow-rs/blob/7bab215351876ffbef8e4e5898bdc1bf766557f5/parquet/src/arrow/arrow_reader/mod.rs#L1013-L1017
   
   🤔 



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