yyanyy opened a new pull request, #60425:
URL: https://github.com/apache/spark/pull/60425
### What changes were proposed in this pull request?
Mark `kll_sketch_agg_bigint/float/double` and
`kll_merge_agg_bigint/float/double` as nondeterministic. Add optimizer
regressions for all six functions with default and explicit `k`, and SQL tests
for reused sketch CTEs with adaptive execution enabled and disabled.
### Why are the changes needed?
KLL compaction randomly chooses retained values. These aggregates currently
inherit `deterministic = true`, so optimizer rules can treat repeated
evaluations as interchangeable. For example, `InlineCTE` duplicates a multiply
referenced CTE containing a KLL aggregate, allowing its references to compute
different sketches. The existing nondeterministic-expression guards should
apply to these aggregates.
### Does this PR introduce _any_ user-facing change?
Yes. A multiply referenced CTE containing a KLL aggregate is preserved for
shared evaluation rather than inlined based on incorrect determinism metadata.
Separate aggregate evaluations remain approximate and can produce different
sketches. Sketch formats, parameters and quantile algorithms are unchanged.
### How was this patch tested?
Before production changes, all 12 new optimizer cases failed because their
reused CTEs were inlined; the SQL regression also failed its CTE-sharing
assertion. With the fix, local validation passed:
```text
build/sbt -batch \
'catalyst/testOnly *InlineCTESuite *AggregateExpressionSuite
*PhysicalAggregationSuite' \
'sql/testOnly *DataFrameAggregateSuite -- -z kll' \
'catalyst/Compile/scalastyle' \
'catalyst/Test/scalastyle' \
'sql/Test/scalastyle'
```
The suites ran 27 Catalyst tests and 17 SQL aggregate tests. The SQL
regression covers bigint/float/double with AQE on/off and checks eight
self-joined groups with no sketch-byte or median mismatches. The optimizer
checks avoid depending on random outputs differing.
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: OpenAI Codex CLI 0.167.1 (GPT-6).
--
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]