-
Notifications
You must be signed in to change notification settings - Fork 2.1k
feat(parquet): runtime row-group early stop via TopK dynamic filter #22450
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
zhuqi-lucas
wants to merge
5
commits into
apache:main
Choose a base branch
from
zhuqi-lucas:feat/topk-rg-level-dynamic-pruning
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
28c1da7
feat(parquet): apply TopK threshold to row-group statistics mid-scan
zhuqi-lucas 68f70ba
fix: CI failures from dynamic_rg_pruning=eligible marker
zhuqi-lucas 691926f
fix: another broken intra-doc link uncovered by --document-private-items
zhuqi-lucas f3adbeb
Merge branch 'main' into feat/topk-rg-level-dynamic-pruning
zhuqi-lucas 0828f1b
fix(parquet): split RowGroupPruner errors into creation vs evaluation
zhuqi-lucas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
117 changes: 117 additions & 0 deletions
117
datafusion/core/tests/parquet/dynamic_row_group_pruning.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| //! End-to-end test for **runtime row-group pruning** driven by a TopK | ||
| //! `SortExec`'s `DynamicFilterPhysicalExpr`. | ||
| //! | ||
| //! A 5-row-group parquet file is constructed with disjoint statistics on | ||
| //! the sort column (`v`): row group `i` contains values | ||
| //! `[i*100, (i+1)*100)`. The query `ORDER BY v DESC LIMIT 5` fills the | ||
| //! TopK heap from the row group with the largest values; the threshold | ||
| //! then proves the remaining row groups cannot contribute. The runtime | ||
| //! `RowGroupPruner` in the parquet scan must observe the tightened | ||
| //! threshold and increment `row_groups_pruned_dynamic_filter`. | ||
| //! | ||
| //! We assert a property (`pruned >= 1`) rather than an exact count | ||
| //! because batch-arrival timing affects how soon the TopK heap fills, | ||
| //! and we don't want this test to become flaky. | ||
|
|
||
| use std::sync::Arc; | ||
|
|
||
| use arrow::array::{ArrayRef, Int64Array, RecordBatch}; | ||
| use arrow_schema::{DataType, Field, Schema}; | ||
|
|
||
| use crate::parquet::Unit::RowGroup; | ||
| use crate::parquet::{ContextWithParquet, Scenario}; | ||
|
|
||
| /// Build five `RecordBatch`es whose `v` column ranges are disjoint: | ||
| /// batch `i` carries `v` values `[i*100, (i+1)*100)`. When written with | ||
| /// `max_row_group_row_count = 100` each batch lands in its own row group. | ||
| fn build_five_disjoint_batches(schema: &Arc<Schema>) -> Vec<RecordBatch> { | ||
| (0..5i64) | ||
| .map(|rg| { | ||
| let base = rg * 100; | ||
| let values: Vec<i64> = (base..base + 100).collect(); | ||
| let col: ArrayRef = Arc::new(Int64Array::from(values)); | ||
| RecordBatch::try_new(Arc::clone(schema), vec![col]).unwrap() | ||
| }) | ||
| .collect() | ||
| } | ||
|
|
||
| /// `ORDER BY v DESC LIMIT 5` against a 5-RG file with disjoint per-RG | ||
| /// stats must trigger runtime RG pruning: the first RG read fills the | ||
| /// heap, and the tightened threshold proves every other RG unreachable. | ||
| #[tokio::test] | ||
| async fn dynamic_rg_pruning_metric_fires_for_topk_descending_limit() { | ||
| let schema = Arc::new(Schema::new(vec![Field::new("v", DataType::Int64, false)])); | ||
| let batches = build_five_disjoint_batches(&schema); | ||
|
|
||
| // `with_custom_data` honors the custom schema + batches and ignores | ||
| // `Scenario`. `Unit::RowGroup(100)` enables `pushdown_filters`, which | ||
| // is required for the TopK dynamic filter to reach the parquet scan. | ||
| let mut ctx = ContextWithParquet::with_custom_data( | ||
| Scenario::Int, | ||
| RowGroup(100), | ||
| Arc::clone(&schema), | ||
| batches, | ||
| ) | ||
| .await; | ||
|
|
||
| let output = ctx.query("SELECT v FROM t ORDER BY v DESC LIMIT 5").await; | ||
|
|
||
| assert_eq!(output.result_rows, 5, "query must return LIMIT rows",); | ||
|
|
||
| let pruned = output | ||
| .row_groups_pruned_dynamic_filter() | ||
| .expect("`row_groups_pruned_dynamic_filter` metric must be registered"); | ||
| assert!( | ||
| pruned >= 1, | ||
| "dynamic RG pruner must skip at least one row group; \ | ||
| pruned={pruned}\n{}", | ||
| output.description(), | ||
| ); | ||
| } | ||
|
|
||
| /// A query without ORDER BY does not produce a TopK and therefore no | ||
| /// `DynamicFilterPhysicalExpr` reaches the scan. The runtime pruner must | ||
| /// stay quiet — the metric should be 0. | ||
| #[tokio::test] | ||
| async fn dynamic_rg_pruning_metric_quiet_without_topk() { | ||
| let schema = Arc::new(Schema::new(vec![Field::new("v", DataType::Int64, false)])); | ||
| let batches = build_five_disjoint_batches(&schema); | ||
|
|
||
| let mut ctx = ContextWithParquet::with_custom_data( | ||
| Scenario::Int, | ||
| RowGroup(100), | ||
| Arc::clone(&schema), | ||
| batches, | ||
| ) | ||
| .await; | ||
|
|
||
| // Plain `SELECT *` — no sort, no limit, no dynamic filter. | ||
| let output = ctx.query("SELECT v FROM t").await; | ||
| assert_eq!(output.result_rows, 500); | ||
|
|
||
| let pruned = output.row_groups_pruned_dynamic_filter().unwrap_or(0); | ||
| assert_eq!( | ||
| pruned, | ||
| 0, | ||
| "without TopK there is no dynamic filter, so the runtime pruner \ | ||
| must not fire; pruned={pruned}\n{}", | ||
| output.description(), | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.