[fix](Nereids) should not replace slot by Alias when do NormalizeSlot (#24928)

when we do NormalizeToSlot, we pushed complex expression and only remain
slot of it. When we do this, we collect alias and their child and
compute its child in bottom project, remain the result slot in current
node. for example

Window(max(...), c1 as a1)

after normalization, we get

Window(max(...), a1)
+-- Project(..., c1 as a1)

But, in some cases, we remove some SlotReference by mistake, for example

Window(max(...), c1, c1 as a1)

after normalization, we get

Window(max(...), a1)
+-- Project(..., c1 as a1)

we lost the SlotReference c1. This PR fix this problem. After this Pr,
we get

Window(max(...), c1, a1)
+-- Project(..., c1, c1 as a1)
This commit is contained in:
morrySnow
2023-09-28 14:51:08 +08:00
committed by GitHub
parent 377554ee1c
commit b50c1448df
32 changed files with 570 additions and 510 deletions

View File

@ -21,6 +21,7 @@ import org.apache.doris.nereids.trees.expressions.Alias;
import org.apache.doris.nereids.trees.expressions.Expression;
import org.apache.doris.nereids.trees.expressions.NamedExpression;
import org.apache.doris.nereids.trees.expressions.Slot;
import org.apache.doris.nereids.trees.expressions.SlotReference;
import org.apache.doris.nereids.trees.expressions.WindowExpression;
import org.apache.doris.nereids.trees.expressions.visitor.DefaultExpressionRewriter;
@ -69,8 +70,14 @@ public interface NormalizeToSlot {
if (normalizeToSlotMap.containsKey(expression)) {
continue;
}
NormalizeToSlotTriplet normalizeToSlotTriplet =
NormalizeToSlotTriplet.toTriplet(expression, existsAliasMap.get(expression));
Alias alias = null;
// consider projects: c1, c1 as a1. we should push down both of them,
// so we could not replace c1 with c1 as a1.
// use null as alias for SlotReference to avoid replace it by another alias of it.
if (!(expression instanceof SlotReference)) {
alias = existsAliasMap.get(expression);
}
NormalizeToSlotTriplet normalizeToSlotTriplet = NormalizeToSlotTriplet.toTriplet(expression, alias);
normalizeToSlotMap.put(expression, normalizeToSlotTriplet);
}
return new NormalizeToSlotContext(normalizeToSlotMap);