Skip to content

feat: Add row-group-local RowSelection support to the push decoder - #10702

Open
haohuaijin wants to merge 2 commits into
apache:mainfrom
haohuaijin:push-decoder-row-group-selections
Open

feat: Add row-group-local RowSelection support to the push decoder#10702
haohuaijin wants to merge 2 commits into
apache:mainfrom
haohuaijin:push-decoder-row-group-selections

Conversation

@haohuaijin

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

DataFusion makes row-group-local selection decisions (ParquetAccessPlan), but the reader APIs only accept selected row groups plus a single global RowSelection. Callers must concatenate per-row-group selections into one global selection, which arrow-rs then re-partitions back into per-row-group selections during decoding. This round trip is wasted work and loses each selection's representation (bitmap vs. selector).

What changes are included in this PR?

  • New public API on the push decoder: RowGroupSelection (a row group index plus an optional row-group-local RowSelection) and ParquetPushDecoderBuilder::with_row_group_selections. Entries decode in the supplied order, omitted row groups are skipped, None reads the whole row group, and each selection keeps its bitmap or selector representation.
  • Mutually exclusive with with_row_groups / with_row_selection: the setters share an internal state machine (RowGroupPlan) that reports conflicting combinations as an error from build() regardless of call order. The legacy API combination is unchanged.
  • build() validates per-row-group plans eagerly: out-of-bounds indices and selections longer than their row group are errors; shorter selections skip the trailing rows.
  • ParquetPushDecoder::into_builder preserves remaining local selections (still in local coordinates), so adaptive scans compose with the new API.
  • Minor behavior improvement: an out-of-bounds index from with_row_groups on the push decoder now returns a ParquetError during decoding instead of panicking.

The sync and async builders are unchanged; the async builder already delegates to the push decoder, so extending the API to it is a small follow-up if needed.

Are these changes tested?

Yes, new tests cover bitmap- and selector-backed local selections (including out-of-order row groups and short selections), skip/replace semantics, mutual exclusion in all four call orders, build-time validation, into_builder round-trips, and the unchanged legacy combination. All existing tests pass.

Are there any user-facing changes?

New public API: RowGroupSelection and ParquetPushDecoderBuilder::with_row_group_selections, with doc examples. No breaking changes; one behavior change: out-of-bounds with_row_groups indices on the push decoder now error during decoding instead of panicking.

@github-actions github-actions Bot added the parquet Changes to the parquet crate label Aug 15, 2026
@haohuaijin haohuaijin changed the title parquet: Add row-group-local RowSelection support to the push decoder feat: Add row-group-local RowSelection support to the push decoder Aug 15, 2026
@haohuaijin

Copy link
Copy Markdown
Contributor Author

In my mind the trick will be how to mesh the existing apis (with_row_groups and with_row_selection) and make sure we have a coherent documentation of what will happen if the user calls each one

This PR adds ParquetPushDecoderBuilder::with_row_group_selections so callers can supply row-group-local RowSelections directly. The new configuration is mutually exclusive with with_row_groups / with_row_selection: an internal state machine catches any conflicting combination in any call order and reports it as an error from build(), the legacy APIs keep their exact semantics, and each setter's docs spell out how it interacts with the others.

cc @alamb @zhuqi-lucas

@zhuqi-lucas zhuqi-lucas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @haohuaijin for this work!
From the DataFusion side: root fix for apache/datafusion#24352 / apache/datafusion#24355into_builder preserving local selections is exactly it. Core looks correct and well-tested; small notes inline. Happy to take the DataFusion migration (apache/datafusion#24358) once this lands.

Comment thread parquet/src/arrow/async_reader/mod.rs
Comment thread parquet/src/arrow/push_decoder/mod.rs
Comment thread parquet/src/arrow/push_decoder/remaining.rs
@haohuaijin

Copy link
Copy Markdown
Contributor Author

Thanks for you reviews @zhuqi-lucas, i update in c0369a6

@alamb alamb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @haohuaijin and @zhuqi-lucas -- I spent quite a while reading this one in detail; I think it is looking very good -- I had some comment and encapsulation nits which I would like to fix before merging but I don't think they are strictly required


/// Row-selection configuration shared by the Arrow reader builders.
///
/// `Global` is the legacy configuration formed by `with_row_groups` and

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: it would be nice to put these docs directly on the enum variants, along with a description of what they mean, not just where they came from / what they are used for

Something like this, perhaps:

/// Row-selection configuration shared by the Arrow reader builders.
pub(crate) enum RowGroupPlan {
    /// (IS THIS TRUE?) Selection: first select any row_groups, adn then apply the RowSelection to 
    /// any remaining rows.
    /// formed by `with_row_groups` and ....)
    Global {
...
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I am happy to make these changes myself, but I wanted to double check first)

}

impl RowGroupSelection {
/// Creates a row-group-local selection.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it might be good to define what row-group-local means more precisely -- specifically something like "The selection is relative to the rows in that selection (e.g. row 100 means the 100th row in the row group)"

// `row_groups` and `selection` straddle `projection`/`filter` so that the
// legacy configuration keeps its historical field order; only the
// row-group-local fields are new.
let (row_groups, selection, row_group_selections) = match &self.row_group_plan {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this feels overly complicated. Why not derive Debug for RowGroupPlan and display it as normal here

pub(crate) batch_size: usize,

pub(crate) row_groups: Option<Vec<usize>>,
pub(crate) row_group_plan: RowGroupPlan,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

row_groups: Some(row_groups),
..self
}
///

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are going to keep this wording I suggest making async stream builders a link too -- something like

-    /// On [`ParquetPushDecoderBuilder`] and async stream builders, which
-    /// additionally offer `with_row_group_selections`, this cannot be combined
-    /// with that method; attempting to do so returns an error from `build`.
+    /// On [`ParquetPushDecoderBuilder`] and [`ParquetRecordBatchStreamBuilder`],
+    /// which additionally offer `with_row_group_selections`, this cannot be
+    /// combined with that method; attempting to do so returns an error from
+    /// `build`.
     ///
     /// [`ParquetPushDecoderBuilder`]: crate::arrow::push_decoder::ParquetPushDecoderBuilder
+    /// [`ParquetRecordBatchStreamBuilder`]: crate::arrow::async_reader::ParquetRecordBatchStreamBuilder

has_predicates: _,
} = frontier;
let row_group_plan = match queued {
QueuedRowGroups::Global {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also make this a method on QueuedRowGroups (like queued.into_plan() or something like that?

Comment thread parquet/src/arrow/push_decoder/remaining.rs
) -> Self {
Self {
) -> Result<Self, ParquetError> {
let queued = match row_group_plan {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it would more naturally be a constructor / from impl on RowGroupPlan -- to construct QueuedRowGroups from a RowGroupPlan

That would also encapsulate the compleixty more

/// error from [`Self::build`]. Calling this method more than once replaces
/// the previous row-group-local configuration.
///
/// ```no_run

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It took me some time to figure out (with some help) that we duplicated with_row_group_selections twice because it isn't supported via the serialized reader

/// than its row group skips the trailing rows, while a selection longer
/// than its row group returns an error from [`Self::build`]. Each
/// selection is passed through without being re-partitioned, so no
/// conversion between the bitmap and selector representations is forced

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the mention of different representations of the selection is confusing here (it seems like an irrelevant implementation detail)

@alamb

alamb commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

I also ran cargo llvm-cov and it reports several of the cases in the decoder aren't covered. This might be resolved by refactoring some of the access plans into their own methods

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

parquet Changes to the parquet crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support row-group-local row selections in the Parquet push decoder

3 participants