Fix ClassCastException in mixed rollup+raw avg aggregation reduce - #22658
Fix ClassCastException in mixed rollup+raw avg aggregation reduce#22658vaibhoag wants to merge 1 commit into
Conversation
Signed-off-by: Vaibhav Agarwal <vaibhoag@amazon.com>
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
|
❌ Gradle check result for 3995dea: FAILURE Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change? |
| aggregationObjects.addAll(mapReduceAggregation.aggregations); | ||
| } else if (aggregation instanceof InternalAvg avg) { | ||
| aggregationObjects.add(new ScriptedAvg(avg.getSum(), avg.getCount())); | ||
| } |
There was a problem hiding this comment.
Should we throw in else condition?
Description
When an
avgaggregation is executed across a mix of rollup and raw indices under the same aggregation name, the Index Management (ISM) rollup plugin rewritesavgon the rollup shards into ascripted_metricthat emitsScriptedAvg(sum, count), so those shards return anInternalScriptedMetric. The raw-index shards still return a plainInternalAvg.At coordinator reduce,
InternalScriptedMetric.reduce()unconditionally cast every per-shard aggregation toInternalScriptedMetric, throwing:which surfaces to the user as an HTTP 500 and fails the entire query.
Fix: in the
reduce()collection loop, handle theInternalAvgcase by converting it into aScriptedAvg(sum, count)— the same object the rollup combine step emits — so it is folded into the scripted-metric reduce script (sum += a.getSum(); count += a.getCount(); return sum/count) and the raw contribution is blended into the final average instead.Related Issues
Resolves #[Issue number to be closed when this PR is merged]
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.