Handle Agg Functions with Literal Args When Used with a Union#13561
Handle Agg Functions with Literal Args When Used with a Union#13561Jackie-Jiang merged 2 commits intoapache:masterfrom
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #13561 +/- ##
============================================
+ Coverage 61.75% 62.11% +0.36%
+ Complexity 207 198 -9
============================================
Files 2436 2558 +122
Lines 133233 140927 +7694
Branches 20636 21867 +1231
============================================
+ Hits 82274 87536 +5262
- Misses 44911 46771 +1860
- Partials 6048 6620 +572
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
| @@ -220,7 +221,7 @@ private static PinotLogicalAggregate convertAggFromIntermediateInput(RelOptRuleC | |||
| PinotLogicalExchange exchange, AggType aggType) { | |||
| Aggregate aggRel = call.rel(0); | |||
| RelNode input = PinotRuleUtils.unboxRel(aggRel.getInput()); | |||
There was a problem hiding this comment.
unboxRel is done within findImmediateProjects(), no need to unbox here
| @@ -259,7 +260,7 @@ private static PinotLogicalAggregate convertAggFromIntermediateInput(RelOptRuleC | |||
|
|
|||
| private static List<AggregateCall> buildAggCalls(Aggregate aggRel, AggType aggType) { | |||
| RelNode input = PinotRuleUtils.unboxRel(aggRel.getInput()); | |||
| relNode = PinotRuleUtils.unboxRel(relNode); | ||
| if (relNode instanceof Project) { | ||
| return ((Project) relNode).getProjects(); | ||
| } else if (relNode instanceof Union) { |
There was a problem hiding this comment.
Does this apply to other RelNode other than Union?
There was a problem hiding this comment.
Yeah there could be more. For instance, if we have a Filter or even a Sort, we should ideally be able to hoist a literal up to the aggregate node.
I am a bit concerned if that could have edge-cases, that's why I kept the scope of the change in this PR small.
(digression follows)
Ideally, I think we should do this step in a separate optimization rule (run before agg exchange insert) which is run only for aggregate nodes.
Clubbing this with exchange insertion makes it a bit complicated to reason about.
Attempts to fix #13305.
This is definitely not the most scientific fix (it's more like an empirical approach).
The issue was that aggregate node may not necessarily be on top of a project node. In our case, it was on top of a Union node, so this PR extends the aggregate exchange rule to handle that.
Test Plan
This query was failing before with the error below, but it works now:
Error: