yashdotrv commented on code in PR #27677:
URL: https://github.com/apache/datafusion/pull/27677#discussion_r4755420063
##########
datafusion/physical-plan/src/aggregates/skip_partial.rs:
##########
@@ -54,57 +53,155 @@ pub(super) struct SkipAggregationProbe {
skipped_aggregation_rows: metrics::Count,
}
+enum ProbeState {
+ Probing {
+ input_rows: usize,
+ num_groups: usize,
+ },
+ Skipping {
+ rows_left: usize,
+ },
+}
+
impl SkipAggregationProbe {
pub(super) 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,
+ state: ProbeState::Probing {
+ input_rows: 0,
+ num_groups: 0,
+ },
+ skip_multiplier: INITIAL_REPROBE_SKIP_MULTIPLIER,
skipped_aggregation_rows,
}
}
- /// Updates `SkipAggregationProbe` state:
- /// - adds the input rows of a batch and the groups it created
- /// - on `probe_rows_threshold` exceeded calculates
- /// aggregation ratio and sets `should_skip` flag
- /// - if `should_skip` is set, locks further state updates
+ /// Adds a batch's input rows and newly created groups to the active probe.
pub(super) fn update_state(&mut self, input_rows: usize, new_groups:
usize) {
- if self.is_locked {
+ let ProbeState::Probing {
+ input_rows: total_rows,
+ num_groups,
+ } = &mut self.state
+ else {
return;
- }
- self.input_rows += input_rows;
- self.num_groups += new_groups;
- if self.input_rows >= self.probe_rows_threshold {
- self.should_skip = self.num_groups as f64 / self.input_rows as f64
- > self.probe_ratio_threshold;
- // Set is_locked to true only if we have decided to skip,
otherwise we can try to skip
- // during processing the next record_batch.
- self.is_locked = self.should_skip;
+ };
+ *total_rows += input_rows;
+ *num_groups += new_groups;
+ if *total_rows > 0 && *total_rows >= self.probe_rows_threshold {
+ if *num_groups as f64 / *total_rows as f64 >
self.probe_ratio_threshold {
+ // A long useful phase must not delay recovery after a later
skip.
+ // Account for batches larger than the configured probe window.
+ self.state = ProbeState::Skipping {
+ rows_left: self
+ .probe_rows_threshold
+ .max(input_rows)
Review Comment:
could we add a focused test for the case where `input_rows >
probe_rows_threshold`; given this is important to the retry cadence... using
only `probe_rows_threshold` make an immediate re-probe even though the current
skipped batch already exceeded the configured window. An assertion that the
retry budget is based on `input_rows` `skip_multiplier` would make this
invariant explicit.
cc @2010YOUY01 @comphead
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]