HippoBaro commented on code in PR #9804:
URL: https://github.com/apache/arrow-rs/pull/9804#discussion_r3142787324


##########
parquet/src/arrow/push_decoder/remaining.rs:
##########
@@ -17,29 +17,179 @@
 
 use crate::DecodeResult;
 use crate::arrow::arrow_reader::{ParquetRecordBatchReader, RowSelection};
-use crate::arrow::push_decoder::reader_builder::RowGroupReaderBuilder;
+use crate::arrow::push_decoder::reader_builder::{
+    RowBudget, RowGroupBuildResult, RowGroupReaderBuilder,
+};
 use crate::errors::ParquetError;
 use crate::file::metadata::ParquetMetaData;
 use bytes::Bytes;
 use std::collections::VecDeque;
 use std::ops::Range;
 use std::sync::Arc;
 
+#[derive(Debug, Clone, Copy, Eq, PartialEq)]
+enum QueuedRowGroupDecision {
+    NeedThis,
+    SkipThis { remaining_budget: RowBudget },
+    SkipAllRemaining,
+}
+#[derive(Debug)]
+struct NextRowGroup {
+    row_group_idx: usize,
+    row_count: usize,
+    selection: Option<RowSelection>,
+    budget: RowBudget,
+}
+
+#[derive(Debug)]
+struct SelectionFrontier {
+    selection: Option<RowSelection>,
+}
+
+impl SelectionFrontier {
+    fn new(selection: Option<RowSelection>) -> Self {
+        Self { selection }
+    }
+
+    fn is_exhausted(&self) -> bool {
+        self.selection
+            .as_ref()
+            .is_some_and(|selection| !selection.selects_any())
+    }
+
+    fn clear(&mut self) {
+        self.selection = None;
+    }
+
+    fn take_for_row_group(&mut self, row_count: usize) -> Option<RowSelection> 
{
+        self.selection.as_mut().map(|s| s.split_off(row_count))
+    }
+}
+
+#[derive(Debug)]
+struct RowGroupFrontier {
+    parquet_metadata: Arc<ParquetMetaData>,
+    row_groups: VecDeque<usize>,
+    selection: SelectionFrontier,
+    budget: RowBudget,
+    has_predicates: bool,
+}
+
+impl RowGroupFrontier {
+    fn new(
+        parquet_metadata: Arc<ParquetMetaData>,
+        row_groups: Vec<usize>,
+        selection: Option<RowSelection>,
+        budget: RowBudget,
+        has_predicates: bool,
+    ) -> Self {
+        Self {
+            parquet_metadata,
+            row_groups: VecDeque::from(row_groups),
+            selection: SelectionFrontier::new(selection),
+            budget,
+            has_predicates,
+        }
+    }
+
+    fn row_group_num_rows(&self, row_group_idx: usize) -> Result<usize, 
ParquetError> {
+        self.parquet_metadata
+            .row_group(row_group_idx)
+            .num_rows()
+            .try_into()
+            .map_err(|e| ParquetError::General(format!("Row count overflow: 
{e}")))
+    }
+
+    fn advance_budget(&mut self, budget: RowBudget) {
+        self.budget = budget;
+    }
+
+    fn selection_exhausted(&self) -> bool {
+        self.selection.is_exhausted()
+    }
+
+    fn clear_remaining(&mut self) {

Review Comment:
   Yes, when the selection is exhausted, the budget is exhausted, or planning 
determines no later row groups can be read



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