andygrove opened a new issue, #7791:
URL: https://github.com/apache/datafusion-comet/issues/7791

   ## What is the problem?
   
   `spark.comet.exec.aggregate.skipPartial.enabled` (experimental, off by 
default) lets a native partial aggregate stop aggregating once its input looks 
mostly distinct, and send the rest of the task's rows to the shuffle as partial 
states. It admits only partial aggregates whose functions are all 
single-argument `COUNT`. A high-cardinality `GROUP BY` that also computes an 
`AVG` never benefits, because Comet's `AVG` accumulators do not implement 
`GroupsAccumulator::convert_to_state`, which DataFusion uses to build each 
row's partial state.
   
   The same gap on Comet Native Executors is tracked in #7406, where TPC-H q17 
at SF1000 went from about 277 s to about 242 s with skipping and `AVG` support. 
This issue is about Comet on Spark.
   
   ## What was tried
   
   #7543 was closed unmerged to cut down the number of open PRs. The branch is 
`perf-avg-skip-partial-aggregation` on `andygrove/datafusion-comet`. It has 
been reviewed once and the review comments were addressed, but nobody has 
re-reviewed it. The design:
   
   - `AvgGroupsAccumulator` (Comet's Float64 `AVG`, which also serves integral 
inputs after a cast to double, and decimals with precision up to 11 that Spark 
rewrites to `avg(UnscaledValue(x))`) implements `convert_to_state`. Each row 
becomes its value and a count of one, or a zero sum and a zero count for a null 
or filtered-out row, which is what `state()` emits for such a group. With no 
nulls and no filter, the input values buffer is reused as the sums.
   - `configure_skip_partial_aggregation` in 
`native/core/src/execution/jni_api.rs` admits `AVG` next to `COUNT`, only when 
the aggregate's result type is `DOUBLE`. An `AVG` over a decimal with precision 
above 11 is built as `AvgDecimal`, whose `convert_to_state` returns "not 
implemented", so it keeps the plan from skipping, as before.
   - The docs in `CometConf` and the Adaptive Partial Aggregation section of 
the tuning guide list the admitted aggregates.
   - Tests: a Rust test checks that converting rows gives the same states as 
aggregating each row alone, including null, filtered and sliced inputs, and a 
gate test checks which `AVG` shapes are admitted. A `CometAggregateSuite` test 
runs high-cardinality `GROUP BY` queries over `avg` of int, double and decimal 
inputs, with nulls and a `FILTER` clause, and checks the answers against Spark 
and the `skipped_aggregation_rows` metric.
   
   ## What is missing
   
   1. **Measurements on Spark.** The PR has no performance numbers for Comet on 
Spark. A performance change needs a benchmark that shows what produces the gain 
and covers both input where skipping is right (keys almost all distinct) and 
input where it is wrong. #6466 showed that skipping can shuffle many times more 
rows when keys repeat after a distinct start, so the benchmark should include a 
key distribution that is distinct at first and repeats later, and should report 
the shuffle bytes as well as the time.
   2. **A decision on the default.** Skipping is opt-in and the PR leaves it 
that way. Say whether `AVG` support changes the case for turning it on.
   3. **Decimal `AVG` above precision 11.** `AvgDecimal` keeps overflow in the 
shared null buffer of its sum and count, so a per-row conversion has to 
reproduce that exactly. It was left out of #7543.
   
   Rebasing the branch onto `main` and a fresh review are also needed.
   


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