-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Add skipped_aggregation_rows metric to aggregate operator
#11706
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,12 +28,12 @@ use crate::aggregates::{ | |
| PhysicalGroupBy, | ||
| }; | ||
| use crate::common::IPCWriter; | ||
| use crate::metrics::{BaselineMetrics, RecordOutput}; | ||
| use crate::metrics::{BaselineMetrics, MetricBuilder, RecordOutput}; | ||
| use crate::sorts::sort::sort_batch; | ||
| use crate::sorts::streaming_merge; | ||
| use crate::spill::read_spill_as_stream; | ||
| use crate::stream::RecordBatchStreamAdapter; | ||
| use crate::{aggregates, ExecutionPlan, PhysicalExpr}; | ||
| use crate::{aggregates, metrics, ExecutionPlan, PhysicalExpr}; | ||
| use crate::{RecordBatchStream, SendableRecordBatchStream}; | ||
|
|
||
| use arrow::array::*; | ||
|
|
@@ -117,17 +117,30 @@ struct SkipAggregationProbe { | |
| /// Flag indicating that further updates of `SkipAggregationProbe` | ||
| /// state won't make any effect | ||
| is_locked: bool, | ||
|
|
||
| /// Number of rows where state was output without aggregation. | ||
| /// | ||
| /// * If 0, all input rows were aggregated (should_skip was always false) | ||
| /// | ||
| /// * if greater than zero, the number of rows which were output directly | ||
| /// without aggregation | ||
| skipped_aggregation_rows: metrics::Count, | ||
| } | ||
|
|
||
| impl SkipAggregationProbe { | ||
| fn new(probe_rows_threshold: usize, probe_ratio_threshold: f64) -> Self { | ||
| fn new( | ||
| probe_rows_threshold: usize, | ||
| probe_ratio_threshold: f64, | ||
| skipped_aggregation_rows: metrics::Count, | ||
| ) -> Self { | ||
| Self { | ||
| input_rows: 0, | ||
| num_groups: 0, | ||
| probe_rows_threshold, | ||
| probe_ratio_threshold, | ||
| should_skip: false, | ||
| is_locked: false, | ||
| skipped_aggregation_rows, | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -160,6 +173,11 @@ impl SkipAggregationProbe { | |
| self.should_skip = false; | ||
| self.is_locked = true; | ||
| } | ||
|
|
||
| /// Record the number of rows that were output directly without aggregation | ||
| fn record_skipped(&mut self, batch: &RecordBatch) { | ||
| self.skipped_aggregation_rows.add(batch.num_rows()); | ||
| } | ||
| } | ||
|
|
||
| /// HashTable based Grouping Aggregator | ||
|
|
@@ -473,17 +491,17 @@ impl GroupedHashAggregateStream { | |
| .all(|acc| acc.supports_convert_to_state()) | ||
| && agg_group_by.is_single() | ||
| { | ||
| let options = &context.session_config().options().execution; | ||
| let probe_rows_threshold = | ||
| options.skip_partial_aggregation_probe_rows_threshold; | ||
| let probe_ratio_threshold = | ||
| options.skip_partial_aggregation_probe_ratio_threshold; | ||
| let skipped_aggregation_rows = MetricBuilder::new(&agg.metrics) | ||
| .counter("skipped_aggregation_rows", partition); | ||
| Some(SkipAggregationProbe::new( | ||
| context | ||
| .session_config() | ||
| .options() | ||
| .execution | ||
| .skip_partial_aggregation_probe_rows_threshold, | ||
| context | ||
| .session_config() | ||
| .options() | ||
| .execution | ||
| .skip_partial_aggregation_probe_ratio_threshold, | ||
| probe_rows_threshold, | ||
| probe_ratio_threshold, | ||
| skipped_aggregation_rows, | ||
| )) | ||
| } else { | ||
| None | ||
|
|
@@ -611,6 +629,9 @@ impl Stream for GroupedHashAggregateStream { | |
| match ready!(self.input.poll_next_unpin(cx)) { | ||
| Some(Ok(batch)) => { | ||
| let _timer = elapsed_compute.timer(); | ||
| if let Some(probe) = self.skip_aggregation_probe.as_mut() { | ||
| probe.record_skipped(&batch); | ||
|
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. This is the actual call that records the metrics . The rest of the PR is comments and plumbing |
||
| } | ||
| let states = self.transform_to_states(batch)?; | ||
| return Poll::Ready(Some(Ok( | ||
| states.record_output(&self.baseline_metrics) | ||
|
|
||
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.
Agree that it should be better not to add this counter into all group bys (as another baseline metric) by default 👍