← Back to Pull requests

perf: let a partial aggregate skip aggregation when it computes a dec… #7795

Open
unknown opened this pull request with 384 lines diff across 4 files
View on GitHub
unknown unknown commented on Nov 30, 2026 03:47 UTC
Author

…imal AVG

Which issue does this PR close?

Part of #7791 (item 3, decimal AVG above precision 11). The Float64 AVG is #7543.

Rationale for this change

With spark.comet.exec.aggregate.skipPartial.enabled, a partial aggregate can stop aggregating and send rows to the shuffle as partial states, but only when every aggregate function is a single-argument COUNT. A decimal AVG whose precision is above 11 is built as AvgDecimal, whose convert_to_state returned "not implemented", so a high-cardinality GROUP BY with such an AVG never skips.

What changes are included in this PR?

  • AvgDecimalGroupsAccumulator::convert_to_state gives each row the state that state() emits for a group holding only that row: the value and a count of one, or a zero sum and a zero count for a null or filtered-out row (a null predicate excludes its row). A value outside the sum's precision gets a null sum and count, the overflow marker update_batch sets, which merge_batch keeps and evaluate reports in ANSI mode. Spark's sum type is at least as wide as the input, so this does not happen for valid input; it keeps the two paths identical.

  • configure_skip_partial_aggregation admits an AVG with an input and a decimal result type, which the planner always builds as AvgDecimal. Any other AVG result is Comet's Float64 Avg, which still cannot convert rows, so it still keeps the plan from skipping.

  • filter_to_nulls in collect.rs is pub(super) so avg_decimal.rs can reuse it (#7543 makes the same change).

  • The CometConf doc and the Adaptive Partial Aggregation section of the tuning guide list the admitted aggregates.
  • Skipping stays opt-in.

    How are these changes tested?

  • convert_to_state_matches_one_row_groups (Rust): converting a batch equals update_batch with one group per row followed by state(), for input with and without nulls, with a filter that has false and null predicates, for sliced inputs and filters, and for a value past the sum's precision.

  • skip_partial_eligibility_is_fail_closed: AVG with a decimal result is admitted next to COUNT; AVG without an input, without a result type, or with a DOUBLE result is not.

  • CometAggregateSuite "skip partial aggregation converts decimal AVG rows to partial states": high-cardinality GROUP BY over avg of a DECIMAL(20, 2) with nulls, with a FILTER clause and next to count, and over a DECIMAL(38, 0) whose two-row groups overflow only after the shuffle. Each checks the answer against Spark and that skipped_aggregation_rows is above zero. In ANSI mode the overflow raises ARITHMETIC_OVERFLOW like Spark. avg(CAST(d AS DOUBLE)) still does not skip.
  • The Rust test fails on main (not implemented), and the suite test fails with the gate change reverted ("Expected skipping for avg(d)"). The other skip-partial tests in CometAggregateSuite still pass, and cargo clippy --all-targets -- -D warnings is clean.

    This PR has no performance numbers on Spark. Measuring skipping with AVG on Spark (item 1 of #7791) is still open.

    Diff: 384 lines (+288 / -96) across 4 files Reviewer: sunchao Review duration: 1379m
    All Vouch review confidence checks passed
    Residual risk 0.25 = Change Risk (0.43) × (1 − Review Confidence (0.43)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.43 · 384 lines diff across 4 files
    0.43
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    42%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.356
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #7795"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 43.0% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 43% (MEDIUM) · Higher = larger blast radius
    43%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 43.0% · Lower = rushed or shallow review
    43.0%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 24.5% · Safe to merge
    24.5%