diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PushCountIntoUnionAll.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PushCountIntoUnionAll.java index d94acccc9bfaeb7..e40c5309b815308 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PushCountIntoUnionAll.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PushCountIntoUnionAll.java @@ -56,9 +56,9 @@ public Rule build() { private Plan doPush(LogicalAggregate agg) { LogicalUnion logicalUnion = agg.child(); List outputs = logicalUnion.getOutput(); - Map mmap = new HashMap<>(); + Map replaceMap = new HashMap<>(); for (int i = 0; i < outputs.size(); i++) { - mmap.put(outputs.get(i), i); + replaceMap.put(outputs.get(i), i); } int childSize = logicalUnion.children().size(); List upperGroupByExpressions = agg.getGroupByExpressions(); @@ -69,9 +69,9 @@ private Plan doPush(LogicalAggregate agg) { for (int i = 0; i < childSize; i++) { Plan child = logicalUnion.children().get(i); List childOutputs = child.getOutput(); - List groupByExpressions = replaceExpressionByUnionAll(upperGroupByExpressions, mmap, + List groupByExpressions = replaceExpressionByUnionAll(upperGroupByExpressions, replaceMap, childOutputs); - List outputExpressions = replaceExpressionByUnionAll(upperOutputExpressions, mmap, + List outputExpressions = replaceExpressionByUnionAll(upperOutputExpressions, replaceMap, childOutputs); LogicalAggregate logicalAggregate = new LogicalAggregate<>(groupByExpressions, outputExpressions, child); @@ -110,8 +110,8 @@ private Plan doPush(LogicalAggregate agg) { } private List replaceExpressionByUnionAll(List expressions, - Map mmap, List childOutputs) { - // 遍历expressions,如果出现了mmap中的slot,那么替换为childOutputs[mmap[slot]] + Map replaceMap, List childOutputs) { + // Traverse expressions. If a slot in replaceMap appears, replace it with childOutputs[replaceMap[slot]] return ExpressionUtils.rewriteDownShortCircuit(expressions, expr -> { if (expr instanceof Alias && ((Alias) expr).child() instanceof Count) { Count cnt = (Count) ((Alias) expr).child(); @@ -119,22 +119,22 @@ private List replaceExpressionByUnionAll(List expre return new Alias(new Count()); } else { Expression newCntChild = cnt.child(0).rewriteDownShortCircuit(e -> { - if (e instanceof SlotReference && mmap.containsKey(e)) { - return childOutputs.get(mmap.get(e)); + if (e instanceof SlotReference && replaceMap.containsKey(e)) { + return childOutputs.get(replaceMap.get(e)); } return e; }); return new Alias(new Count(newCntChild)); } - } else if (expr instanceof SlotReference && mmap.containsKey(expr)) { - return childOutputs.get(mmap.get(expr)); + } else if (expr instanceof SlotReference && replaceMap.containsKey(expr)) { + return childOutputs.get(replaceMap.get(expr)); } return expr; }); } private boolean hasUnsuportedAggFunc(LogicalAggregate aggregate) { - // 如果有不是count的aggfunc,或者有count distinct 都不支持这个规则 + // only support count, and support count(distinct) return ExpressionUtils.deapAnyMatch(aggregate.getOutputExpressions(), expr -> { if (expr instanceof AggregateFunction) { return !(expr instanceof Count) || ((Count) expr).isDistinct(); diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalAggregate.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalAggregate.java index 776e9556f64f089..fa4f891e7a20b37 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalAggregate.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalAggregate.java @@ -82,7 +82,6 @@ public class LogicalAggregate private final boolean ordinalIsResolved; private final boolean generated; private final boolean hasPushed; - public boolean done = false; /** * Desc: Constructor for LogicalAggregate.