adriangb opened a new pull request, #12456:
URL: https://github.com/apache/arrow-rs/pull/12456

   # Which issue does this PR close?
   
   - Relates to https://github.com/apache/datafusion/issues/24358
   - Follows https://github.com/apache/arrow-rs/issues/10624
   
   # Rationale for this change
   
   A caller that prunes row groups at runtime needs to drop pending row groups 
from a push decoder. Today the only way is `into_builder` plus 
`with_row_group_selections`. That has two problems:
   
   - The decoder does not expose its pending plan. DataFusion keeps a parallel 
queue that mirrors the decoder frontier.
   - A rebuild that passes `None` selections loses the row-group-local 
selections of the kept row groups.
   
   The decoder already owns the pending row groups and their selections. A 
filter on that state removes the parallel queue and keeps the selections.
   
   # What changes are included in this PR?
   
   Two new methods on `ParquetPushDecoder`:
   
   ```rust
   pub fn retain_row_groups(&mut self, f: impl FnMut(usize) -> bool) -> 
Result<(), ParquetError>;
   pub fn remaining_row_groups(&self) -> Vec<usize>;
   ```
   
   | Aspect | Behavior |
   |---|---|
   | Kept row groups | Keep their order and their row-group-local selections. 
With a global `with_row_selection`, the method removes the rows of each dropped 
row group, so each kept row group keeps the same rows. |
   | Active row group | Not affected. The decoder finishes the row group or 
reader that it already started. |
   | Row-group boundary | Not required. The method only changes the queue that 
the decoder has not started. |
   | Offset and limit | The remaining budget applies to the kept row groups, as 
if the dropped row groups were never in the plan. |
   | Buffered bytes | The decoder releases the bytes that neither the kept row 
groups nor the active row group read. |
   | `scan_plan()` | Reflects the kept row groups only. |
   | Finished decoder | No-op. |
   
   `f` takes a row group index. A plan that lists one row group twice keeps or 
drops both entries. `remaining_row_groups` returns a `Vec` because the state is 
behind an enum and the list is short.
   
   Why in place, and not an accessor on the builder after `into_builder`: the 
in-place filter does not need a boundary, does not rebuild the reader builder, 
and cannot change other options by mistake. It is also less code: the change is 
in 
[`Queue::retain`](https://github.com/adriangb/arrow-rs/blob/52422e5380f0a414834e66ad4664ccefe78426aa/parquet/src/arrow/push_decoder/scan_plan/frontier.rs)
 and 
[`RemainingRowGroups::retain_row_groups`](https://github.com/adriangb/arrow-rs/blob/52422e5380f0a414834e66ad4664ccefe78426aa/parquet/src/arrow/push_decoder/remaining.rs).
   
   # Are these changes tested?
   
   Yes. New unit tests in `parquet/src/arrow/push_decoder/mod.rs` assert exact 
output rows:
   
   - `test_retain_row_groups_keeps_local_selections`: four entries with 
selections, drop RG1 after the first row group, the kept RG0 entry keeps its 
selection.
   - `test_retain_row_groups_does_not_read_dropped_row_groups`: the requested 
ranges and `scan_plan` equal those of a decoder that never had RG1.
   - `test_retain_row_groups_releases_buffered_bytes`: dropped bytes are 
released.
   - `test_retain_row_groups_mid_row_group`: call during `try_decode` of an 
active row group.
   - `test_retain_row_groups_with_offset_and_limit` and 
`test_retain_row_groups_mid_scan_with_limit`: budgets apply to the kept row 
groups.
   - `test_retain_row_groups_with_global_selection`: a global selection keeps 
the rows of RG1, also across `into_builder`.
   - `test_retain_row_groups_on_finished_decoder`.
   
   # Are there any significant user-facing changes?
   
   New public API only. No breaking change.
   
   # AI usage disclosure
   
   Claude Code wrote the implementation, tests and this description. A human 
reviews them before the PR leaves draft.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


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