Repository navigation
Conversation
5b511a9 to
b8d5540
Compare
b8d5540 to
7381d5b
Compare
7381d5b to
4da708a
Compare
97cbcad to
81e434a
Compare
…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>
81e434a to
26c0a9a
Compare
|
oh, boy -- I will put this on my review queue |
26c0a9a to
e06d67c
Compare
e06d67c to
ada19c4
Compare
… 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>
ada19c4 to
29553db
Compare
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 🙏🏻 |
d81d186 to
0019a34
Compare
… 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>
|
I didnt' make this one today -- tomorrow hopefully |
alamb
left a comment
There was a problem hiding this comment.
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
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. |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
NeedsDataGranularityRequestGranularity
| /// * 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. |
There was a problem hiding this comment.
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
| /// * 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. |
| /// without an offset index, the decoder requests the full column chunk. | ||
| /// * A `batch_size` greater than 0. | ||
| /// | ||
| /// # I/O |
There was a problem hiding this comment.
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
Happy to have you give it a go! It’s only fair that you write some code and I do some review 😅 |
|
@alamb I asked an agent to implement your idea: #11613. In general it looks much better. The one loss I see is that |
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 ... |
|
FYI I have been swamped this week fighting with 4 arrow-rs releases along with the apache CI runner debacle. |
|
No worries! Happy to look at your implementation proposal whenever it’s ready and we can iterate RowFilter into it later. |
|
I also tried to write down what we are trying to accomplish here: |
|
I'm going to mark this as draft until we're ready to come back to it |
9c5fa2c to
d444b52
Compare
…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>
|
@alamb I came back to this and pushed a new version here. It's the #11613 approach you suggested (loop back through I think the RowFilter part came out pretty nice: the decoder cuts the row group into windows of It also releases pages as it goes and respects 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. |
…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>
a0d2619 to
83d392b
Compare
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>
|
@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. |
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>
…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>
e2d4b66 to
0913d53
Compare
…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>
0913d53 to
f956033
Compare
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>
Which issue does this PR close?
Rationale for this change
Today,
ParquetPushDecoderreturns 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:
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
Incrementaldecoder state and aPageStore. Review asked for a design that uses the existing states. This version has no new state and no page store:batch_sizerows.ColumnChunkData::Shared, which is a view of thePushBuffersof 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:
push_decoder/decodeandpush_decoder/decode_8192benchmarks, formainscan_ranges_from_selectorsandColumnFetch::newfind the pages of a selection with a binary searchThe four commits of this PR follow. Each commit builds and passes clippy on its own.
c934b12e0WaitingOnData, tests, and thebatchvariant of the benchmarks. This is #11613. In this commit, a scan with aRowFilterstill requests the full row group for the predicates.0ff1cf631RowFilteris evaluated one window at a time. A predicate can leave fewer thanbatch_sizerows 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.30c2d6dfdf95603373RowSelectionPolicy. 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:
enum RequestGranularity { RowGroup, Batch }#[non_exhaustive], defaultRowGroupParquetPushDecoderBuilder::with_request_granularityDesign decisions
batch_size.#[non_exhaustive]lets us add a variant later.ArrowPredicate::evaluatemakes no promise about batch boundaries.NeedsDataasks 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
LIMITis already satisfied inside a window. The limit applies per window throughRowBudget.buffered_bytes(), but the allocation stays alive until all its pages are released.fetch_rangestocolumn_fetches).Are these changes tested?
Yes.
push_decoder_equivalence.rs(the harness from test(parquet): differential tests ofParquetPushDecoderagainst the sync reader #11485) checks for eachproptestscan that batch mode returns the same batches as row-group mode, and that the decoder holds no bytes after the scan.push_decoder_incremental.rshas the tests for behavior that is specific to batch mode. Examples:test_predicates_do_not_wait_for_the_row_groupRowFilter, the first batch arrives before the row group is pushedtest_releases_bytes_pushed_ahead,test_predicates_release_bytes_pushed_aheadtest_row_group_read_two_timestest_dictionary_page_is_requested_once_per_column_chunkBenchmarks
benches/push_decoder.rs, GCPc4a-standard-16, two interleaved rounds per build, mean of the two medians. The benchmark groups are from #12486. This PR adds theirbatchvariant.Default path (
RequestGranularity::RowGroup),mainagainst this PR:main1buf/1000ranges1buf/10000ranges1buf/100000ranges1buf/500000rangesNbuf/1000rangesNbuf/10000rangesNbuf/100000rangesdecode/row_group/10pages_100batchdecode/row_group/100pages_10batchTwo 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_8192reads onef32column and one string column (1,000,000 rows, default writer properties) in batches of 8,192 rows:decode_8192/*/low_cardinalitydecode_8192/*/uniquedecodeuses batches of 10 and 100 rows (10f32columns, 1,000 rows) to isolate the cost of one request:decode/*/10pages_100batchdecode/*/100pages_10batchNeedsData, stores the pushed ranges, runs the decoder states, and releases the passed pages. Row-group mode does this one time per row group.decodeonly because those batches have 10 and 100 rows.100pages_10batch. It changes nothing when a batch is one page.RowFilteryet. 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:
RequestGranularityandParquetPushDecoderBuilder::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