-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[fix](nereids) Fix not in aggregate's output err after eliminate by uniform when group sets exist #56942
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[fix](nereids) Fix not in aggregate's output err after eliminate by uniform when group sets exist #56942
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,12 +29,16 @@ | |
| import org.apache.doris.nereids.trees.expressions.Expression; | ||
| import org.apache.doris.nereids.trees.expressions.Slot; | ||
| import org.apache.doris.nereids.trees.expressions.SlotReference; | ||
| import org.apache.doris.nereids.trees.expressions.VirtualSlotReference; | ||
| import org.apache.doris.nereids.trees.expressions.functions.scalar.GroupingScalarFunction; | ||
| import org.apache.doris.nereids.trees.expressions.visitor.DefaultExpressionRewriter; | ||
| import org.apache.doris.nereids.trees.plans.Plan; | ||
|
|
||
| import com.google.common.collect.ImmutableList; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Optional; | ||
|
|
||
| /** replace SlotReference ExprId in logical plans */ | ||
| public class ExprIdRewriter extends ExpressionRewrite { | ||
|
|
@@ -75,18 +79,10 @@ public Plan rewriteExpr(Plan plan, Map<ExprId, ExprId> replaceMap) { | |
| * SlotReference:a#0 -> a#3, a#1 -> a#7 | ||
| * */ | ||
| public static class ReplaceRule implements ExpressionPatternRuleFactory { | ||
| private final Map<ExprId, ExprId> replaceMap; | ||
|
|
||
| public ReplaceRule(Map<ExprId, ExprId> replaceMap) { | ||
| this.replaceMap = replaceMap; | ||
| } | ||
|
|
||
| @Override | ||
| public List<ExpressionPatternMatcher<? extends Expression>> buildRules() { | ||
| return ImmutableList.of( | ||
| matchesType(SlotReference.class).thenApply(ctx -> { | ||
| Slot slot = ctx.expr; | ||
|
|
||
| private static final DefaultExpressionRewriter<Map<ExprId, ExprId>> SLOT_REPLACER = | ||
| new DefaultExpressionRewriter<Map<ExprId, ExprId>>() { | ||
| @Override | ||
| public Expression visitSlotReference(SlotReference slot, Map<ExprId, ExprId> replaceMap) { | ||
| ExprId newId = replaceMap.get(slot.getExprId()); | ||
| if (newId == null) { | ||
| return slot; | ||
|
|
@@ -100,7 +96,44 @@ public List<ExpressionPatternMatcher<? extends Expression>> buildRules() { | |
| lastId = newId; | ||
| } | ||
| } | ||
| }).toRule(ExpressionRuleType.EXPR_ID_REWRITE_REPLACE) | ||
| } | ||
| }; | ||
| private final Map<ExprId, ExprId> replaceMap; | ||
|
|
||
| public ReplaceRule(Map<ExprId, ExprId> replaceMap) { | ||
| this.replaceMap = replaceMap; | ||
| } | ||
|
|
||
| @Override | ||
| public List<ExpressionPatternMatcher<? extends Expression>> buildRules() { | ||
| return ImmutableList.of( | ||
| matchesType(SlotReference.class).thenApply(ctx -> { | ||
| Slot slot = ctx.expr; | ||
| return slot.accept(SLOT_REPLACER, replaceMap); | ||
| }).toRule(ExpressionRuleType.EXPR_ID_REWRITE_REPLACE), | ||
| matchesType(VirtualSlotReference.class).thenApply(ctx -> { | ||
| VirtualSlotReference virtualSlot = ctx.expr; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1.there is an attribute "realExpressions" in VirtualSlotReference, should we replace "realExpressions" too?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. realExpressions is derived from original Expressions, we have replaced original Expressions rightly, realExpressions is right auto |
||
| return virtualSlot.accept(new DefaultExpressionRewriter<Map<ExprId, ExprId>>() { | ||
| @Override | ||
| public Expression visitVirtualReference(VirtualSlotReference virtualSlot, | ||
| Map<ExprId, ExprId> replaceMap) { | ||
| Optional<GroupingScalarFunction> originExpression = virtualSlot.getOriginExpression(); | ||
| if (!originExpression.isPresent()) { | ||
| return virtualSlot; | ||
| } | ||
| GroupingScalarFunction groupingScalarFunction = originExpression.get(); | ||
| GroupingScalarFunction rewrittenFunction = | ||
| (GroupingScalarFunction) groupingScalarFunction.accept( | ||
| SLOT_REPLACER, replaceMap); | ||
| if (!rewrittenFunction.children().equals(groupingScalarFunction.children())) { | ||
| return virtualSlot.withOriginExpressionAndComputeLongValueMethod( | ||
| Optional.of(rewrittenFunction), | ||
| rewrittenFunction::computeVirtualSlotValue); | ||
| } | ||
| return virtualSlot; | ||
| } | ||
| }, replaceMap); | ||
| }).toRule(ExpressionRuleType.VIRTUAL_EXPR_ID_REWRITE_REPLACE) | ||
| ); | ||
| } | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe this will lead to agg source repeat be rewritten twice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not same instance, so doesn't repeat be rewritten twice.