-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Add focused benchmark for Parquet pruning setup cache #24323
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
kosiew
wants to merge
2
commits into
apache:main
Choose a base branch
from
kosiew:schema_caching-90-21554
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.
+115
−1
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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,110 @@ | ||
| // 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. | ||
|
|
||
| //! Benchmarks end-to-end Parquet scan cost for a cache-favourable workload. | ||
| //! | ||
| //! The 128 files share one physical schema and use the same predicate and target | ||
| //! partition count, so pruning setup is reusable in a cache-enabled comparison | ||
| //! branch. The predicate matches every file, so each scan must adapt the | ||
| //! predicate and build (or reuse) pruning setup for all files. | ||
| //! | ||
| //! This is a focused baseline for comparing cache-disabled and cache-enabled | ||
| //! branches. It is not a general DataFusion benchmark and must not be | ||
| //! interpreted as a ClickBench performance result. | ||
|
|
||
| use std::{fs::File, sync::Arc}; | ||
|
|
||
| use arrow::{ | ||
| array::Int64Array, | ||
| datatypes::{DataType, Field, Schema}, | ||
| record_batch::RecordBatch, | ||
| }; | ||
| use criterion::{Criterion, criterion_group, criterion_main}; | ||
| use datafusion::prelude::{SessionConfig, SessionContext}; | ||
| use parquet::arrow::ArrowWriter; | ||
| use tempfile::TempDir; | ||
|
|
||
| const FILES: usize = 128; | ||
| const ROWS_PER_FILE: usize = 128; | ||
|
|
||
| fn write_files() -> TempDir { | ||
| let directory = tempfile::tempdir().unwrap(); | ||
| let schema = Arc::new(Schema::new(vec![Field::new("id", DataType::Int64, false)])); | ||
|
|
||
| for file_index in 0..FILES { | ||
| let start = i64::try_from(file_index * ROWS_PER_FILE).unwrap(); | ||
| let values = Int64Array::from_iter_values( | ||
| start..start + i64::try_from(ROWS_PER_FILE).unwrap(), | ||
| ); | ||
| let batch = | ||
| RecordBatch::try_new(Arc::clone(&schema), vec![Arc::new(values)]).unwrap(); | ||
| let file = | ||
| File::create(directory.path().join(format!("{file_index}.parquet"))).unwrap(); | ||
| let mut writer = ArrowWriter::try_new(file, Arc::clone(&schema), None).unwrap(); | ||
| writer.write(&batch).unwrap(); | ||
| writer.close().unwrap(); | ||
| } | ||
|
|
||
| directory | ||
| } | ||
|
|
||
| fn criterion_benchmark(criterion: &mut Criterion) { | ||
| let directory = write_files(); | ||
| let runtime = tokio::runtime::Runtime::new().unwrap(); | ||
| let context = runtime.block_on(async { | ||
| let context = SessionContext::new_with_config( | ||
| SessionConfig::new().with_target_partitions(1), | ||
| ); | ||
| context | ||
| .register_parquet("t", directory.path().to_str().unwrap(), Default::default()) | ||
| .await | ||
| .unwrap(); | ||
| context | ||
| }); | ||
|
|
||
| runtime.block_on(async { | ||
| let batches = context | ||
| .sql("SELECT id FROM t WHERE id >= 0") | ||
| .await | ||
| .unwrap() | ||
| .collect() | ||
| .await | ||
| .unwrap(); | ||
| assert_eq!( | ||
| batches.iter().map(RecordBatch::num_rows).sum::<usize>(), | ||
| FILES * ROWS_PER_FILE | ||
| ); | ||
| }); | ||
|
|
||
| criterion.bench_function( | ||
| "parquet_pruning_setup_cache/same_schema_files", | ||
| |bencher| { | ||
| bencher.to_async(&runtime).iter(|| async { | ||
| context | ||
| .sql("SELECT id FROM t WHERE id >= 0") | ||
| .await | ||
| .unwrap() | ||
| .collect() | ||
| .await | ||
| .unwrap() | ||
| }); | ||
| }, | ||
| ); | ||
| } | ||
|
|
||
| criterion_group!(benches, criterion_benchmark); | ||
| criterion_main!(benches); | ||
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.
what would happen if the schema is not the same? or schema is already merged?
Uh oh!
There was an error while loading. Please reload this page.
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 benchmark's purpose is to evaluate whether addressing #21554 improves performance: that issue targets avoiding repeated per-file schema adaptation, predicate rewrites, and pruning-predicate construction when many files have the same physical schema.
Schema evolution/merged-schema behavior is a separate workload and would dilute this focused benchmark.
Existing clickbench_partitioned benchmarks do not show significant improvement, I think because: