backendArchitect opened a new pull request, #7795:
URL: https://github.com/apache/datafusion-comet/pull/7795

   …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.
   


-- 
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]

Reply via email to