Skip to content

feat(parquet): let ParquetPushDecoder decode a batch as soon as its pages are pushed - #11238

Draft
adriangb wants to merge 6 commits into
apache:mainfrom
pydantic:claude/push-decoder-batch-granularity
Draft

adriangb wants to merge 6 commits into
apache:mainfrom
pydantic:claude/push-decoder-batch-granularity

Conversation

@adriangb

@adriangb adriangb commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

Today, ParquetPushDecoder returns no rows of a row group until the caller has pushed all bytes that the row group reads (#11218 shows this). For a large row group on object storage, the first batch waits for the full row group.

With this PR, a caller can opt in to get each batch as soon as its pages are pushed:

let mut decoder = ParquetPushDecoderBuilder::try_new_decoder(metadata)?
    .with_batch_size(100)
    .with_request_granularity(RequestGranularity::Batch) // new
    .build()?;

// NeedsData asks for the pages of the first 100 rows only
let DecodeResult::NeedsData(ranges) = decoder.try_decode()? else { panic!() };
decoder.push_ranges(ranges, fetch(&ranges).await?)?;

// The first batch is ready. The rest of the row group was not requested.
let DecodeResult::Data(batch) = decoder.try_decode()? else { panic!() };

The default (RequestGranularity::RowGroup) is not changed. Both modes return the same batches in the same order.

Design change

The first version of this PR added a separate Incremental decoder state and a PageStore. Review asked for a design that uses the existing states. This version has no new state and no page store:

Start ──► Filters ──► WaitingOnFilterData ──► StartData ──► WaitingOnData
  ▲          ▲                │  (one loop per predicate)        │
  │          └────────────────┘                                  │
  └──────────────────────── next window ─────────────────────────┘
  • The decoder splits the selected rows of a row group into windows of batch_size rows.
  • Each window runs the existing states and requests only its own pages.
  • The array readers live for the full row group. They read ColumnChunkData::Shared, which is a view of the PushBuffers of the decoder, so they see the pages that arrive for later windows.

What changes are included in this PR?

This PR is stacked on two small PRs, and it is a draft until they merge. Their commits are the first two commits here:

PR Content
#12486 The push_decoder/decode and push_decoder/decode_8192 benchmarks, for main
#12487 scan_ranges_from_selectors and ColumnFetch::new find the pages of a selection with a binary search

The four commits of this PR follow. Each commit builds and passes clippy on its own.

Commit Content
c934b12e0 The API, batch-granular decoding through WaitingOnData, tests, and the batch variant of the benchmarks. This is #11613. In this commit, a scan with a RowFilter still requests the full row group for the predicates.
0ff1cf631 A RowFilter is evaluated one window at a time. A predicate can leave fewer than batch_size rows in a window, so the output reader keeps rows until a full batch is ready. The predicate cache is shared by all windows of a row group.
30c2d6dfd The decoder releases the pages of a window after it decodes them. It keeps dictionary pages. It keeps all pages of a row group that the scan reads again.
f95603373 Batch mode honors the configured RowSelectionPolicy. With the mask strategy, a reader decodes the rows between two selected runs if their pages are loaded, and filters them out of the batch.

New public items:

Item Notes
enum RequestGranularity { RowGroup, Batch } #[non_exhaustive], default RowGroup
ParquetPushDecoderBuilder::with_request_granularity
Design decisions
Question Decision
API shape: an enum, a row count, or a separate method? An enum. A row count is a second option next to batch_size. #[non_exhaustive] lets us add a variant later.
A predicate can see other batch boundaries than in row-group mode Accepted. ArrowPredicate::evaluate makes no promise about batch boundaries.
A scan that reads one row group two times The decoder keeps the pages of that row group until the last read.
Who decides how far to read ahead? The caller. NeedsData asks only for the next window, and the caller can push more ranges before the decoder asks. scan_plan() gives the ranges. DataFusion reads ahead in apache/datafusion#24086.
Known limits
  • The decoder does not stop a predicate early when a LIMIT is already satisfied inside a window. The limit applies per window through RowBudget.
  • The decoder always stores predicate results as selectors. The mask policy changes how the readers read rows, not how the decoder stores the selection.
  • A release of pages inside one large pushed buffer lowers buffered_bytes(), but the allocation stays alive until all its pages are released.
  • refactor(parquet): share the stage fetch logic between the push decoder and ScanPlan #11609 touches the same fetch code. A rebase on it is small (one file with conflicts, plus a port from fetch_ranges to column_fetches).

Are these changes tested?

Yes.

Test Asserts
test_predicates_do_not_wait_for_the_row_group With a RowFilter, the first batch arrives before the row group is pushed
test_releases_bytes_pushed_ahead, test_predicates_release_bytes_pushed_ahead The resident bytes go down after each batch, to exact values
test_row_group_read_two_times A scan can read one row group two times
test_dictionary_page_is_requested_once_per_column_chunk The decoder requests a dictionary page one time

Benchmarks

benches/push_decoder.rs, GCP c4a-standard-16, two interleaved rounds per build, mean of the two medians. The benchmark groups are from #12486. This PR adds their batch variant.

Default path (RequestGranularity::RowGroup), main against this PR:

Benchmark main This PR Change
1buf/1000ranges 571.5 µs 581.4 µs +1.7%
1buf/10000ranges 5.804 ms 5.871 ms +1.2%
1buf/100000ranges 67.19 ms 66.50 ms -1.0%
1buf/500000ranges 351.0 ms 356.4 ms +1.5%
Nbuf/1000ranges 654.0 µs 664.6 µs +1.6%
Nbuf/10000ranges 6.833 ms 6.871 ms +0.6%
Nbuf/100000ranges 80.85 ms 80.67 ms -0.2%
decode/row_group/10pages_100batch 60.47 µs 60.21 µs -0.4%
decode/row_group/100pages_10batch 489.8 µs 494.0 µs +0.9%

Two rounds of the same build differ by up to 3%, so these changes are noise.

Batch mode without a RowFilter, all data in memory. decode_8192 reads one f32 column and one string column (1,000,000 rows, default writer properties) in batches of 8,192 rows:

Benchmark Row-group mode Batch mode Overhead Extra per batch
decode_8192/*/low_cardinality 4.240 ms 4.458 ms +5.1% 1.8 µs
decode_8192/*/unique 5.101 ms 5.250 ms +2.9% 1.2 µs

decode uses batches of 10 and 100 rows (10 f32 columns, 1,000 rows) to isolate the cost of one request:

Benchmark Row-group mode Batch mode, without #12487 Batch mode, this PR Extra per batch
decode/*/10pages_100batch 60.2 µs 93.2 µs 94.1 µs 3.4 µs
decode/*/100pages_10batch 494.0 µs 1038.8 µs 904.3 µs 4.1 µs
  • Both modes decode the same batches. Batch mode adds a fixed cost per batch: it maps the next rows to page ranges, returns NeedsData, stores the pushed ranges, runs the decoder states, and releases the passed pages. Row-group mode does this one time per row group.
  • The cost is about 0.4 to 0.9 µs per column per batch. It is 3% to 5% of a scan with 8,192-row batches. It reads as 1.56x and 1.83x in decode only because those batches have 10 and 100 rows.
  • The binary search of perf(parquet): find the pages of a row selection without a scan of all pages #12487 gives the 13% on 100pages_10batch. It changes nothing when a batch is one page.
  • No benchmark has a RowFilter yet. The windowed filter path and the mask policy have tests for correctness, and no timing.

Are there any significant user-facing changes?

A new opt-in API: RequestGranularity and ParquetPushDecoderBuilder::with_request_granularity. There are no breaking changes.

AI usage disclosure

Claude Code wrote the code, the tests and this description, under my direction.

🤖 Generated with Claude Code

@github-actions github-actions Bot added the parquet parquet crate label Sep 27, 2026
@adriangb
adriangb force-pushed the claude/push-decoder-batch-granularity branch from 5b511a9 to b8d5540 Compare September 28, 2026 21:12
@adriangb
adriangb force-pushed the claude/push-decoder-batch-granularity branch from b8d5540 to 7381d5b Compare September 28, 2026 21:42
@adriangb
adriangb force-pushed the claude/push-decoder-batch-granularity branch from 7381d5b to 4da708a Compare October 1, 2026 13:50
@adriangb
adriangb marked this pull request as draft October 1, 2026 13:50
@adriangb
adriangb force-pushed the claude/push-decoder-batch-granularity branch 2 times, most recently from 97cbcad to 81e434a Compare October 5, 2026 01:44
mbutrovich pushed a commit to mbutrovich/arrow-rs that referenced this pull request Oct 9, 2026
…ing (apache#10555)

# Which issue does this PR close?

- Part of apache#6946.
- Follows apache#11330, which is
merged. The planner uses the decoder's own `ColumnFetch` and
`StageSchedule` from that PR, so it does not keep a copy of the decoder
logic.
- Related: apache#8668,
apache#11165 (API discussion).

# Rationale for this change

An application that drives `ParquetPushDecoder` learns what to fetch
only from `NeedsData`. So it cannot fetch data for later row groups
while the current row group decodes. If the application calculates the
ranges itself, its plan can be different from what the decoder reads.

This PR gives the application the decoder's own plan. It does not change
decoding.

| PR | Result |
|---|---|
| This PR | The application can read ahead. |
| apache#11238 (draft, tracked in
apache#11234) | The decoder decodes
one batch at a time. |
| Both | Early first batch, and memory smaller than one row group. |

# What changes are included in this PR?

`ParquetPushDecoder::scan_plan()` returns `ScanPlan`, a lazy iterator of
`PlannedRange { range, row_group, column, kind }`, in the order that
decoding needs them.

- The plan comes from the current state of the decoder. It is a superset
of the ranges that the decoder can still request. To get the full scan,
call `scan_plan()` one time after `build()`.
- There is one entry for each page if the column has an offset index. If
not, there is one entry for the column chunk.
- With a `RowFilter`, the plan also contains ranges that the predicates
can make unnecessary.
- The plan does not depend on pushed data, and it does no I/O.

Keep the fetched ranges in your own cache, and answer each `NeedsData`
with exactly the requested ranges. The docs and the doctest show this.

# Reviewer guide

About half of the diff is tests.

| Part | Where | Lines (approximate) |
|---|---|---|
| Tests | `push_decoder/scan_plan/tests.rs` | 920 |
| Planner | `push_decoder/scan_plan/mod.rs`, from `struct Planner` | 550
|
| Public types, docs and doctest | `push_decoder/scan_plan/mod.rs`,
before `struct Planner` | 230 |
| Decoder changes | `push_decoder/mod.rs`, `remaining.rs`,
`reader_builder/mod.rs`, `reader_builder/stages.rs` | 80 |
| Benchmark | `benches/push_decoder.rs` | 80 |

Recommended reading order:

1. The docs of `ScanPlan` and its example. They give the contract.
2. The decoder changes. `RemainingRowGroups` keeps the row group that
the decoder fetches now (`active_row_group`), so a plan can start in the
middle of a scan. `RowGroupReaderBuilder` shares its `StageSchedule`
with the plan through an `Arc`.
3. The planner, in three steps:
- `Planner::plan_next_row_group` gets the next row group and applies
offset and limit. It uses the decoder's `RowGroupFrontier` and
`RowBudget`.
- `RowGroupContext::column_cursor` lists the pages of one column chunk.
It uses the decoder's `ColumnFetch`.
- `RowGroupRanges::next` merges the column chunks of one decoding stage
by first row. This step is new in this PR.
4. The tests.

The invariant to check: at each step of a scan, the plan covers every
byte that the decoder requests later.

- `plan_covers_later_requests_at_every_step` makes a plan before each
`try_decode` call and compares it with all later requests. It does this
with and without a `RowFilter`.
- `decode_from_plan_in` is the helper that most other tests use. It
fails if the planned ranges do not cover a request, and it compares the
output with a normal scan.

Changes after the last review:

-
apache@5634dd0
moves the tests to `scan_plan/tests.rs`. The tests do not change.
-
apache@fd6b9ae
removes the crate-private `stage` and `conditional` fields of
`PlannedRange`. Only tests read them.
-
apache@7904ea8
makes `PlannedRange` equality compare the public fields only.
-
apache@80202f2
releases the unused capacity of the column list of a stage.
-
apache@ab83391
corrects two statements in the `ScanPlan` docs.
-
apache@a3b72c1
removes the `#[inline]` hints from `in_memory_row_group.rs`. This PR now
has no change in that file.

# Are these changes tested?

Yes:

- At each step of a scan, the plan contains every range that the decoder
requests later. This is tested with and without a `RowFilter`, and in
the middle of a row group.
- End to end: plan, fetch into a cache, answer `NeedsData`, decode. The
output is the same as a normal scan, and no bytes stay buffered.
- Cases: selections, offset and limit, no page index, a partial offset
index, nested columns, and the predicate cache.

The `push_decoder/scan_plan` benchmark measures the planning cost. The
first range takes:

| Columns × pages | Time |
|---|---|
| 1,000 × 100 | 21 µs |
| 10,000 × 10 | 202 µs |
| 10,000 × 10, with a row selection | 2.1 ms |

# Are there any user-facing changes?

New public API only: `scan_plan()`, `ScanPlan`, `PlannedRange` and
`PageKind`. `PlannedRange` and `PageKind` are `#[non_exhaustive]`.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@adriangb
adriangb marked this pull request as ready for review October 9, 2026 19:13
@adriangb
adriangb force-pushed the claude/push-decoder-batch-granularity branch from 81e434a to 26c0a9a Compare October 9, 2026 19:13
@alamb

alamb commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

oh, boy -- I will put this on my review queue

@adriangb
adriangb force-pushed the claude/push-decoder-batch-granularity branch from 26c0a9a to e06d67c Compare October 10, 2026 04:06
@adriangb
adriangb marked this pull request as draft October 10, 2026 04:07
@adriangb
adriangb force-pushed the claude/push-decoder-batch-granularity branch from e06d67c to ada19c4 Compare October 10, 2026 04:31
Jefffrey pushed a commit to Jefffrey/arrow-rs that referenced this pull request Oct 10, 2026
… goes past its column chunk (apache#11484)

# Which issue does this PR close?

- Part of apache#11234.

# Rationale for this change

If the offset index gives a page size that goes past the end of the
column chunk, the async reader and the push decoder panic in
`Bytes::slice`. A reader must return an error for a malformed file, not
panic.

```rust
// offset index of column 0: the last page is 1 byte too long
let mut decoder = ParquetPushDecoderBuilder::try_new_decoder(metadata)?.build()?;
// ... push the requested ranges ...
decoder.try_decode()  // panic: range end out of bounds: 127 <= 126
```

This PR is split out of apache#11238 to
make that PR smaller.

# What changes are included in this PR?

`ColumnChunkData::get_bytes` checks the length before it slices:

```diff
 fn get_bytes(&self, start: u64, length: usize) -> Result<Bytes> {
-    Ok(self.get(start)?.slice(..length))
+    let data = self.get(start)?;
+    if data.len() < length {
+        return Err(general_err!("... has {} bytes, expected {length}"));
+    }
+    Ok(data.slice(..length))
 }
```

This PR does not change `ColumnChunkData::get`, which can still panic if
the start offset is outside the column chunk.

# Are these changes tested?

Yes, with two new tests:
`test_decoder_offset_index_page_past_column_chunk` (through the push
decoder) and `get_bytes_errors_on_short_data` (unit test).

- **Before:** `panicked at bytes-1.12.1/src/bytes.rs:374:28: range end
out of bounds: 127 <= 126`
- **After:** `Parquet error: column chunk data at offset ... has 126
bytes, expected 127`

# Are there any user-facing changes?

A read of a file with such an offset index returns an error. Before, it
caused a panic.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@adriangb
adriangb force-pushed the claude/push-decoder-batch-granularity branch from ada19c4 to 29553db Compare October 10, 2026 12:11
@adriangb

adriangb commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor Author

oh, boy -- I will put this on my review queue

To try to make it a bit easier I've split this PR up: #11234 (comment).

The starting point would be #11485 which is only tests.

I hope this helps 🙏🏻

@adriangb
adriangb force-pushed the claude/push-decoder-batch-granularity branch 2 times, most recently from d81d186 to 0019a34 Compare October 10, 2026 12:46
mbutrovich pushed a commit to mbutrovich/arrow-rs that referenced this pull request Oct 12, 2026
… sync reader (apache#11485)

# Which issue does this PR close?

- Part of apache#11234.
- Stack of PRs and review order:
apache#11234 (comment)

# Rationale for this change

`ParquetPushDecoder` has no test that compares it with the sync reader
across many scan configurations. This PR adds one. It has value on
`main`, and apache#11238 will use the
same harness to check its new mode. This PR is split out of that PR to
make it smaller.

# What changes are included in this PR?

Tests only: one new file and one new dev-dependency.

```text
Scan { batch_size, projection, row_groups, selection, limit, offset, predicates, policy, .. }
  ├── push_decoder()  ──▶ drive_file ──▶ rows ─┐
  └── sync_batches()  ─────────────────▶ rows ─┴─ assert_same_rows
```

- Two test files with list and struct columns: one with a new page each
25 rows or less, one where the page boundaries differ a lot between
columns.
- Two property tests with
[`proptest`](https://crates.io/crates/proptest)
(`test_fuzz_equivalence`, `test_fuzz_equivalence_heterogeneous_pages`),
1,000 scans each. The strategies combine batch size, projection, row
groups, row selection, selection policy, predicates, predicate cache
size, offset and limit. They include the edge values: batch sizes next
to the size of a page and of a row group, a limit of 0, and an offset
after the last row.
- If a scan fails, `proptest` shrinks it to a smaller scan that fails.

`proptest` is a new dev-dependency of `parquet`. `parquet-variant`
already uses it. Two choices that differ from the `proptest` defaults:

| Choice | Reason |
|---|---|
| The scans are the same in each run (fixed seed) | A failure in CI
comes from the change under test |
| No `proptest-regressions` files | The tests are in `src/`, and the
fixed seed makes a failure reproducible without them |

Each test fails if less than two thirds of its scans return rows, so
that it does not compare empty results only.

The tests compare rows, not batch boundaries: the sync reader lets a
batch span two row groups, and the push decoder does not.

# Are these changes tested?

The 4 new tests pass on `main` in about 3 seconds (debug build). To
check that they can fail, I removed the last row of each batch of
exactly 7 rows in `drive_file`. Both property tests failed, and
`proptest` reduced the failing scan to one with a batch size of 26 and
two predicates.

# Are there any user-facing changes?

No.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@alamb

alamb commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

I didnt' make this one today -- tomorrow hopefully

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

I started going through this design in detail -- thank you very much for pushing this long @adriangb

I found the new RowGroupDecoderState::Incremental state confusing -- it seems like it is sort of a special case that was bolted on to the existing state machine and has a lot of duplication (e.g. the need for a second PageStore rather than just using the same PushBuffers instance 🤔

I guess I was expecting some logic that put the state machine back into RowGroupDecoderState::WaitingOnData when the readers ran out, rather rather than an entire new state

And then when the reader needed more data, the push decoder would get them, and then update the InMemoryRowGroup

https://github.com/apache/arrow-rs/blob/3d5428da8478e8a74fa8fca3adbe1cb2166b5de5/parquet/examples/read_with_rowgroup.rs#L109-L108

I went back and forth with claude code a bunch, and it claimed this was possible

If you prefer, I can try to implement this alternate approach so we can see what it would look like.

/// Request and decode a full row group at a time. This is the default.
///
/// [`DecodeResult::NeedsData`] asks for all bytes that the row group
/// reads, and the first batch is ready after all of them are pushed.

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.

maybe we can say this offers good decode speed but will buffer all the pages needed for decode in the row group; For larger row groups (e.g. that have many strings) this can may require substantial memory

fetch_granularity: FetchGranularity,
}

/// How [`ParquetPushDecoder::try_decode`] requests data and decodes row

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.

Naming:

The push decoder isn't actually 'fetching' anything, so calling this enumFetchGranularity feels strange to me. Maybe using something more connected to request or NeedsData would be more natural? Perhaps

  • NeedsDataGranularity
  • RequestGranularity

Comment thread parquet/src/arrow/push_decoder/mod.rs Outdated
Comment on lines +238 to +241
/// * The offset index, to find the pages of a batch. Load it with
/// [`ArrowReaderOptions::with_page_index_policy`]. For a column chunk
/// without an offset index, the decoder requests the full column chunk.
/// * A `batch_size` greater than 0.

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 don't think a batch_size of zero is common and I doubt the decoder will work with it (if so we should probably reject it).

Also, I think we could potentially clarify this a bit like

Suggested change
/// * The offset index, to find the pages of a batch. Load it with
/// [`ArrowReaderOptions::with_page_index_policy`]. For a column chunk
/// without an offset index, the decoder requests the full column chunk.
/// * A `batch_size` greater than 0.
/// * The [`ParquetMetaData`] must have an offset index, for all requested columns
/// to find the pages of a batch (see
/// [`ArrowReaderOptions::with_page_index_policy`]). The decoder will request the full
/// column chunk for all columns without an offset index.

Comment thread parquet/src/arrow/push_decoder/mod.rs Outdated
/// without an offset index, the decoder requests the full column chunk.
/// * A `batch_size` greater than 0.
///
/// # I/O

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 like the wrong place to document how to do I/O for the reader as it is very deeply buried -- maybe we could move the documentation it to the PushDecoder struct itself and leave a reference to that struct here?

Similarly, how the PushDecoder buffers / needs memory is probably something we should put on the PushDecoder documentation itself rather than here on an enum variant

@adriangb

Copy link
Copy Markdown
Contributor Author

If you prefer, I can try to implement this alternate approach so we can see what it would look like.

Happy to have you give it a go! It’s only fair that you write some code and I do some review 😅

@adriangb

Copy link
Copy Markdown
Contributor Author

@alamb I asked an agent to implement your idea: #11613. In general it looks much better. The one loss I see is that RowFilters are not eagerly emitted once their pages are buffered and we have a whole batch of data. They require the entire row group's worth of pages to be buffered. Maybe you see a way to address that when you do your implementation?

@alamb

alamb commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

@alamb I asked an agent to implement your idea: #11613. In general it looks much better. The one loss I see is that RowFilters are not eagerly emitted once their pages are buffered and we have a whole batch of data. They require the entire row group's worth of pages to be buffered. Maybe you see a way to address that when you do your implementation?

Yeah I think we'll need to handle the state of "evaluating predicates" as its own separate state -- basically if we have enough data to evaluate a row filter partially then if we have the pages to produce data immediately we would have to switch to a state that produced output before evaluating more data pages

One thing I have been thinking is that maybe I can make some more I/O pattern tests so it is celarer what we are triyng to accomplish. I'll try and do that ...

@alamb

alamb commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

FYI I have been swamped this week fighting with 4 arrow-rs releases along with the apache CI runner debacle.

@adriangb

Copy link
Copy Markdown
Contributor Author

No worries! Happy to look at your implementation proposal whenever it’s ready and we can iterate RowFilter into it later.

@alamb

alamb commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

I also tried to write down what we are trying to accomplish here:

@adriangb

Copy link
Copy Markdown
Contributor Author

I'm going to mark this as draft until we're ready to come back to it

@adriangb
adriangb marked this pull request as draft November 12, 2026 07:32
@adriangb
adriangb force-pushed the claude/push-decoder-batch-granularity branch from 9c5fa2c to d444b52 Compare November 27, 2026 18:00
adriangb added a commit to pydantic/arrow-rs that referenced this pull request Nov 27, 2026
…ages are pushed (WaitingOnData variant)

Alternative design to apache#11238: batch mode runs through the
existing row group state machine. The output reader reads from the decoder's
PushBuffers, and the state returns to WaitingOnData for the pages of each
batch. Predicates are evaluated on the full row group.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@adriangb

Copy link
Copy Markdown
Contributor Author

@alamb I came back to this and pushed a new version here. It's the #11613 approach you suggested (loop back through WaitingOnData, no new state, no PageStore), plus the RowFilter piece that was missing from it.

I think the RowFilter part came out pretty nice: the decoder cuts the row group into windows of batch_size rows and each window just runs the existing Filters → WaitingOnData states, so a filtered scan emits batches as soon as that window's pages are there.

It also releases pages as it goes and respects RowSelectionPolicy, so I think it covers what #11240 was going to do.

Benchmarks are in the description. Default path is unchanged; batch mode costs some CPU overhead on in-memory data, which is the price of a request per batch.

I closed #11613 in favor of this one. It'll conflict a little with #11609, happy to rebase on top if you want to land that first. No rush on any of this, I know you've been buried.

adriangb added a commit to pydantic/arrow-rs that referenced this pull request Nov 27, 2026
…ages are pushed (WaitingOnData variant)

Alternative design to apache#11238: batch mode runs through the
existing row group state machine. The output reader reads from the decoder's
PushBuffers, and the state returns to WaitingOnData for the pages of each
batch. Predicates are evaluated on the full row group.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@adriangb
adriangb force-pushed the claude/push-decoder-batch-granularity branch from a0d2619 to 83d392b Compare November 27, 2026 18:16
adriangb added a commit to pydantic/datafusion that referenced this pull request Nov 27, 2026
EXPERIMENT. DataFusion needs `RequestGranularity::Batch` of
`ParquetPushDecoder` (apache/arrow-rs#11238), which no arrow-rs release
has yet.

Patch every arrow crate to pydantic/arrow-rs at d3dc9a193. That commit is
the 60.2.0 release plus the squashed diff of apache/arrow-rs#11238, so the
pin adds no other unreleased arrow-rs change.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@adriangb

Copy link
Copy Markdown
Contributor Author

@alamb a suggestion to make this PR smaller / easier to review: I split the benchmarks out into #12486 and the binary search on the page index into #12487, and your existing refactor in #11609 covers the fetch logic. Happy to help get those three across the line and then come back here, if you agree that's a good path.

adriangb and others added 2 commits November 27, 2026 10:45
The `push_decoder` benchmarks measure `push_ranges`, `prefetch` and
`scan_plan`. None of them decodes a file, so they do not show the cost of
the decoder between a request and a batch.

Add two groups that decode a file with `try_decode`:

- `push_decoder/decode`: 10 `f32` columns, 1,000 rows, batches of 10 and
  100 rows. The decode work is small, so the cost of a request shows.
- `push_decoder/decode_8192`: one `f32` column and one string column,
  1,000,000 rows, batches of 8,192 rows.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…l pages

`RowSelection::scan_ranges` visits each page of the column chunk, also
the pages that a skip covers. `ColumnFetch::new` then visits each page
again to map the ranges to page indexes. Both are O(pages) for each call.
A caller that reads a column chunk in many small selections pays that
cost for each selection.

A skip now moves to its last page with a binary search, and
`ColumnFetch::new` finds each page with a binary search from the previous
page.

One difference: a selector that selects 0 rows no longer adds the page at
its position. The readers ignore such a selector.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
adriangb added a commit to pydantic/arrow-rs that referenced this pull request Nov 27, 2026
…ages are pushed (WaitingOnData variant)

Alternative design to apache#11238: batch mode runs through the
existing row group state machine. The output reader reads from the decoder's
PushBuffers, and the state returns to WaitingOnData for the pages of each
batch. Predicates are evaluated on the full row group.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@adriangb
adriangb force-pushed the claude/push-decoder-batch-granularity branch from e2d4b66 to 0913d53 Compare November 27, 2026 18:53
adriangb and others added 4 commits December 3, 2026 14:07
…ages are pushed (WaitingOnData variant)

Alternative design to apache#11238: batch mode runs through the
existing row group state machine. The output reader reads from the decoder's
PushBuffers, and the state returns to WaitingOnData for the pages of each
batch. Predicates are evaluated on the full row group.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nular push decoding

Batch mode read the predicates for the full row group before the first
batch. A filtered scan thus waited for the full predicate column chunks,
which is the case that the DataFusion read-ahead work needs most.

The row group now runs the existing states once per window of
`batch_size` selected rows: Filters, WaitingOnFilterData, StartData,
WaitingOnData, then back to Start for the next window. Predicate and
output readers live for the full row group and read the shared
PushBuffers. The output reader keeps the rows of a window until
`batch_size` rows are ready, so the batches match row-group mode.

This replaces BatchOutput. A scan without predicates is the same loop
with zero predicates.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…push decoder has decoded them

Batch mode kept every pushed page until the row group ended, so the
decoder held a full row group. A caller that bounds read-ahead by the
bytes the decoder holds (DataFusion) could not read ahead past one
window.

The decoder now releases the pages that lie before the next window when
it has decoded a window. It keeps the dictionary pages, and the pages of
the current predicate cache batch. It keeps all pages of a row group
that the queue reads again.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…decoding

Each window read its rows with one skip and one read for each selected
run, also with `RowSelectionPolicy::Mask` or `Auto`. For a fragmented
selection, that is slower than decoding the rows between the runs and
filtering them out.

The decoder now resolves the policy for each window. With the mask
strategy, a reader decodes the unselected rows between two selected
runs when their pages are loaded, and removes them with a mask when it
returns the batch.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@adriangb
adriangb force-pushed the claude/push-decoder-batch-granularity branch from 0913d53 to f956033 Compare December 3, 2026 20:08
adriangb added a commit to pydantic/datafusion that referenced this pull request Dec 4, 2026
EXPERIMENT. DataFusion needs `RequestGranularity::Batch` of
`ParquetPushDecoder` (apache/arrow-rs#11238), which no arrow-rs release
has yet.

Patch every arrow crate to pydantic/arrow-rs at d3dc9a193. That commit is
the 60.2.0 release plus the squashed diff of apache/arrow-rs#11238, so the
pin adds no other unreleased arrow-rs change.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

This branch has not been deployed

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

Labels

parquet parquet crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants