-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Introduce load-balanced split_groups_by_statistics
method
#15473
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
alamb
merged 10 commits into
apache:main
from
xudong963:improve_split_groups_by_statistics
Apr 4, 2025
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c0a26ed
Improve split_groups_by_statistics method
xudong963 7cd662e
add benchmark_group name
xudong963 bc12b43
use v2
xudong963 3973c69
add comments and fix tests
xudong963 ecbd327
address partial
xudong963 413990b
refine doc
xudong963 7fe0354
rename
xudong963 e98116b
add tests
xudong963 37f84a5
resolve conflict
xudong963 ecb60f0
move notes
xudong963 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
108 changes: 108 additions & 0 deletions
108
datafusion/datasource/benches/split_groups_by_statistics.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,108 @@ | ||
// 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::datatypes::{DataType, Field, Schema}; | ||
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion}; | ||
use datafusion_datasource::file_scan_config::FileScanConfig; | ||
use datafusion_datasource::{generate_test_files, verify_sort_integrity}; | ||
use datafusion_physical_expr::PhysicalSortExpr; | ||
use datafusion_physical_expr_common::sort_expr::LexOrdering; | ||
use std::sync::Arc; | ||
use std::time::Duration; | ||
|
||
pub fn compare_split_groups_by_statistics_algorithms(c: &mut Criterion) { | ||
let file_schema = Arc::new(Schema::new(vec![Field::new( | ||
"value", | ||
DataType::Float64, | ||
false, | ||
)])); | ||
|
||
let sort_expr = PhysicalSortExpr { | ||
expr: Arc::new(datafusion_physical_expr::expressions::Column::new( | ||
"value", 0, | ||
)), | ||
options: arrow::compute::SortOptions::default(), | ||
}; | ||
let sort_ordering = LexOrdering::from(vec![sort_expr]); | ||
|
||
// Small, medium, large number of files | ||
let file_counts = [10, 100, 1000]; | ||
let overlap_factors = [0.0, 0.2, 0.5, 0.8]; // No, low, medium, high overlap | ||
|
||
let target_partitions: [usize; 4] = [4, 8, 16, 32]; | ||
|
||
let mut group = c.benchmark_group("split_groups"); | ||
group.measurement_time(Duration::from_secs(10)); | ||
|
||
for &num_files in &file_counts { | ||
for &overlap in &overlap_factors { | ||
let file_groups = generate_test_files(num_files, overlap); | ||
// Benchmark original algorithm | ||
group.bench_with_input( | ||
BenchmarkId::new( | ||
"original", | ||
format!("files={},overlap={:.1}", num_files, overlap), | ||
), | ||
&( | ||
file_groups.clone(), | ||
file_schema.clone(), | ||
sort_ordering.clone(), | ||
), | ||
|b, (fg, schema, order)| { | ||
let mut result = Vec::new(); | ||
b.iter(|| { | ||
result = | ||
FileScanConfig::split_groups_by_statistics(schema, fg, order) | ||
.unwrap(); | ||
}); | ||
assert!(verify_sort_integrity(&result)); | ||
}, | ||
); | ||
|
||
// Benchmark new algorithm with different target partitions | ||
for &tp in &target_partitions { | ||
group.bench_with_input( | ||
BenchmarkId::new( | ||
format!("v2_partitions={}", tp), | ||
format!("files={},overlap={:.1}", num_files, overlap), | ||
), | ||
&( | ||
file_groups.clone(), | ||
file_schema.clone(), | ||
sort_ordering.clone(), | ||
tp, | ||
), | ||
|b, (fg, schema, order, target)| { | ||
let mut result = Vec::new(); | ||
b.iter(|| { | ||
result = FileScanConfig::split_groups_by_statistics_with_target_partitions( | ||
schema, fg, order, *target, | ||
) | ||
.unwrap(); | ||
}); | ||
assert!(verify_sort_integrity(&result)); | ||
}, | ||
); | ||
} | ||
} | ||
} | ||
|
||
group.finish(); | ||
} | ||
|
||
criterion_group!(benches, compare_split_groups_by_statistics_algorithms); | ||
criterion_main!(benches); |
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.
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.
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.
Execution Time
Planning phase: ~2x slower for the v2 algorithm
Execution phase: Potentially much better parallelism that could improve overall query performance
(I think it's an expected trade-off, v2's plan cost should be acceptable, with thousands of files in time)
Scaling Behavior:
Overlap Effects:
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.
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.
Yes, fyi: #10336 (comment)
And I think @leoyvens can ouput more
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.
I'm prepared to give this a test run on some real data, by installing
datafusion-cli
from this branch. But I need some way to enable it.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.
Thanks @leoyvens , I enabled it in 3666ae8