-
Notifications
You must be signed in to change notification settings - Fork 1.5k
refactor filter pushdown apis #15801
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
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
0071b10
refactor filter pushdown apis
adriangb 3e22402
remove commented out code
adriangb 145a313
fix tests
adriangb ac463e9
fail to fix bug
adriangb c059894
fix
adriangb 6c36992
add/fix docs
adriangb 7d0c68c
lint
adriangb c765a23
add some docstrings, some minimal cleaup
adriangb 838c071
review suggestions
berkaysynnada 907f7c8
add more comments
adriangb d0c1014
fix doc links
adriangb 3b4c4fa
fmt
adriangb a446662
add comments
adriangb 1103c1a
make test deterministic
adriangb 40a71c6
add bench
adriangb 2e5d635
fix bench
adriangb a198143
register bench
adriangb cb6399c
fix bench
adriangb 5fea96b
Merge branch 'main' into filter-pushdown-change
berkaysynnada 98e91f7
cargo fmt
berkaysynnada 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
// 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. | ||
|
||
use arrow::array::RecordBatch; | ||
use arrow::datatypes::{DataType, Field, Schema}; | ||
use bytes::{BufMut, BytesMut}; | ||
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion}; | ||
use datafusion::config::ConfigOptions; | ||
use datafusion::prelude::{ParquetReadOptions, SessionContext}; | ||
use datafusion_execution::object_store::ObjectStoreUrl; | ||
use datafusion_physical_optimizer::filter_pushdown::FilterPushdown; | ||
use datafusion_physical_optimizer::PhysicalOptimizerRule; | ||
use datafusion_physical_plan::ExecutionPlan; | ||
use object_store::memory::InMemory; | ||
use object_store::path::Path; | ||
use object_store::ObjectStore; | ||
use parquet::arrow::ArrowWriter; | ||
use std::sync::Arc; | ||
|
||
async fn create_plan() -> Arc<dyn ExecutionPlan> { | ||
let ctx = SessionContext::new(); | ||
let schema = Arc::new(Schema::new(vec![ | ||
Field::new("id", DataType::Int32, true), | ||
Field::new("name", DataType::Utf8, true), | ||
Field::new("age", DataType::UInt16, true), | ||
Field::new("salary", DataType::Float64, true), | ||
])); | ||
let batch = RecordBatch::new_empty(schema); | ||
|
||
let store = Arc::new(InMemory::new()) as Arc<dyn ObjectStore>; | ||
let mut out = BytesMut::new().writer(); | ||
{ | ||
let mut writer = ArrowWriter::try_new(&mut out, batch.schema(), None).unwrap(); | ||
writer.write(&batch).unwrap(); | ||
writer.finish().unwrap(); | ||
} | ||
let data = out.into_inner().freeze(); | ||
store | ||
.put(&Path::from("test.parquet"), data.into()) | ||
.await | ||
.unwrap(); | ||
ctx.register_object_store( | ||
ObjectStoreUrl::parse("memory://").unwrap().as_ref(), | ||
store, | ||
); | ||
|
||
ctx.register_parquet("t", "memory:///", ParquetReadOptions::default()) | ||
.await | ||
.unwrap(); | ||
|
||
let df = ctx | ||
.sql( | ||
r" | ||
WITH brackets AS ( | ||
SELECT age % 10 AS age_bracket | ||
FROM t | ||
GROUP BY age % 10 | ||
HAVING COUNT(*) > 10 | ||
) | ||
SELECT id, name, age, salary | ||
FROM t | ||
JOIN brackets ON t.age % 10 = brackets.age_bracket | ||
WHERE age > 20 AND t.salary > 1000 | ||
ORDER BY t.salary DESC | ||
LIMIT 100 | ||
", | ||
) | ||
.await | ||
.unwrap(); | ||
|
||
df.create_physical_plan().await.unwrap() | ||
} | ||
|
||
#[derive(Clone)] | ||
struct BenchmarkPlan { | ||
plan: Arc<dyn ExecutionPlan>, | ||
config: ConfigOptions, | ||
} | ||
|
||
impl std::fmt::Display for BenchmarkPlan { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
write!(f, "BenchmarkPlan") | ||
} | ||
} | ||
|
||
fn bench_push_down_filter(c: &mut Criterion) { | ||
// Create a relatively complex plan | ||
let plan = tokio::runtime::Runtime::new() | ||
.unwrap() | ||
.block_on(create_plan()); | ||
let mut config = ConfigOptions::default(); | ||
config.execution.parquet.pushdown_filters = true; | ||
let plan = BenchmarkPlan { plan, config }; | ||
|
||
c.bench_with_input( | ||
BenchmarkId::new("push_down_filter", plan.clone()), | ||
&plan, | ||
|b, plan| { | ||
b.iter(|| { | ||
let optimizer = FilterPushdown::new(); | ||
optimizer | ||
.optimize(Arc::clone(&plan.plan), &plan.config) | ||
.unwrap(); | ||
}); | ||
}, | ||
); | ||
} | ||
|
||
criterion_group!(benches, bench_push_down_filter); | ||
criterion_main!(benches); |
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This actually looks like an improvement to me as now
a = foo
will be evaluated beforeb=bar
as was done in the input plan. This might be important for short circuiting, perhapsThe prior version of this optimization seems to have reordered them