-
Notifications
You must be signed in to change notification settings - Fork 2.3k
refactor(hash-aggr): Support spilling for single mode aggregation #23965
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
2010YOUY01
wants to merge
1
commit into
apache:main
Choose a base branch
from
2010YOUY01:split-aggr-spill-single
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1274,12 +1274,7 @@ impl AggregateExec { | |
| && self.group_by.is_single() | ||
| } | ||
|
|
||
| fn should_use_single_hash_stream(&self, context: &TaskContext) -> bool { | ||
| // TODO: implement memory-limited path and remove this limitation | ||
| if matches!(context.memory_pool().memory_limit(), MemoryLimit::Finite(_)) { | ||
| return false; | ||
| } | ||
|
|
||
| fn should_use_single_hash_stream(&self, _context: &TaskContext) -> bool { | ||
| matches!( | ||
| self.mode, | ||
| AggregateMode::Single | AggregateMode::SinglePartitioned | ||
|
|
@@ -3767,7 +3762,7 @@ mod tests { | |
| let aggregates_v0: Vec<Arc<AggregateFunctionExpr>> = | ||
| vec![Arc::new(test_median_agg_expr(Arc::clone(&input_schema))?)]; | ||
|
|
||
| // use fast-path in `grouped_hash_stream.rs`. | ||
| // Use the fast path in `single_stream.rs`. | ||
| let aggregates_v2: Vec<Arc<AggregateFunctionExpr>> = vec![Arc::new( | ||
| AggregateExprBuilder::new(avg_udaf(), vec![col("b", &input_schema)?]) | ||
| .schema(Arc::clone(&input_schema)) | ||
|
|
@@ -3800,7 +3795,7 @@ mod tests { | |
| assert!(matches!(stream, StreamType::GroupedHash(_))); | ||
| } | ||
| 2 => { | ||
| assert!(matches!(stream, StreamType::GroupedHash(_))); | ||
| assert!(matches!(stream, StreamType::SingleHash(_))); | ||
| } | ||
| _ => panic!("Unknown version: {version}"), | ||
| } | ||
|
|
@@ -4135,15 +4130,14 @@ mod tests { | |
| Ok(()) | ||
| } | ||
|
|
||
| /// Spilling behavior is not implemented for single hash stream yet, so fall | ||
| /// back to the existing `GroupedHashAggregateStream`. | ||
| /// Single hash aggregation supports finite memory. | ||
| #[tokio::test] | ||
| async fn single_aggregate_with_memory_limit_planning() -> Result<()> { | ||
| let single = single_test_aggregate()?; | ||
| let task_ctx = new_finite_memory_migrated_hash_ctx(2, 1024 * 1024)?; | ||
|
|
||
| let stream = single.execute_typed(0, &task_ctx)?; | ||
| assert!(matches!(stream, StreamType::GroupedHash(_))); | ||
| assert!(matches!(stream, StreamType::SingleHash(_))); | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
@@ -5664,9 +5658,11 @@ mod tests { | |
| Field::new("b", DataType::Float64, false), | ||
| ])); | ||
|
|
||
| let group_keys = [2, 3, 4, 4].repeat(1_000); | ||
| let values = [1.0, 2.0, 3.0, 4.0].repeat(1_000); | ||
| let batches = vec![ | ||
| create_record_batch(&schema, (vec![2, 3, 4, 4], vec![1.0, 2.0, 3.0, 4.0]))?, | ||
| create_record_batch(&schema, (vec![2, 3, 4, 4], vec![1.0, 2.0, 3.0, 4.0]))?, | ||
| create_record_batch(&schema, (group_keys.clone(), values.clone()))?, | ||
| create_record_batch(&schema, (group_keys, values))?, | ||
| ]; | ||
| let plan: Arc<dyn ExecutionPlan> = | ||
| TestMemoryExec::try_new_exec(&[batches], Arc::clone(&schema), None)?; | ||
|
|
@@ -5766,9 +5762,9 @@ mod tests { | |
| #[tokio::test] | ||
| async fn test_aggregate_with_spill_if_necessary() -> Result<()> { | ||
| // test with spill | ||
| run_test_with_spill_pool_if_necessary(2_000, true).await?; | ||
| run_test_with_spill_pool_if_necessary(20_000, true).await?; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here is the same as the previous note on test change. |
||
| // test without spill | ||
| run_test_with_spill_pool_if_necessary(20_000, false).await?; | ||
| run_test_with_spill_pool_if_necessary(200_000, false).await?; | ||
| Ok(()) | ||
| } | ||
|
|
||
|
|
@@ -6744,11 +6740,6 @@ mod tests { | |
| matches!(root, DataFusionError::ResourcesExhausted(_)), | ||
| "Expected ResourcesExhausted, got: {root}", | ||
| ); | ||
| let msg = root.to_string(); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Above check on error type is enough I think, here it also assert the exact error message |
||
| assert!( | ||
| msg.contains("Failed to reserve memory for sort during spill"), | ||
| "Expected sort reservation error, got: {msg}", | ||
| ); | ||
| } | ||
| } | ||
|
|
||
|
|
||
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.
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.
The old implementation set a very tight memory budget, and the refactored implementation might have minor implementation difference, making this test fail.
Here it just try to scale up the test input size and memory limit, the test target is the same.