From a9f218133778bc8c9ddf0e38164d80ec9b975d55 Mon Sep 17 00:00:00 2001 From: 924060929 <924060929@qq.com> Date: Fri, 22 Mar 2024 17:24:14 +0800 Subject: [PATCH] save --- .../rules/analysis/BindExpression.java | 37 ++++--------------- 1 file changed, 7 insertions(+), 30 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindExpression.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindExpression.java index 04ba599aa60d5b5..c2c7f5815d92884 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindExpression.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindExpression.java @@ -19,7 +19,6 @@ import org.apache.doris.catalog.Env; import org.apache.doris.catalog.FunctionRegistry; -import org.apache.doris.common.Pair; import org.apache.doris.nereids.CascadesContext; import org.apache.doris.nereids.NereidsPlanner; import org.apache.doris.nereids.StatementContext; @@ -386,41 +385,19 @@ private LogicalHaving bindHavingAggregate( } Scope groupBySlotsScope = toScope(cascadesContext, groupBySlots.build()); - Supplier> separateAggOutputScopes = Suppliers.memoize(() -> { - ImmutableList.Builder groupByOutputs = ImmutableList.builderWithExpectedSize( - aggregate.getOutputExpressions().size()); - ImmutableList.Builder aggFunOutputs = ImmutableList.builderWithExpectedSize( - aggregate.getOutputExpressions().size()); - for (NamedExpression outputExpression : aggregate.getOutputExpressions()) { - if (outputExpression.anyMatch(AggregateFunction.class::isInstance)) { - aggFunOutputs.add(outputExpression.toSlot()); - } else { - groupByOutputs.add(outputExpression.toSlot()); - } - } - Scope nonAggFunSlotsScope = toScope(cascadesContext, groupByOutputs.build()); - Scope aggFuncSlotsScope = toScope(cascadesContext, aggFunOutputs.build()); - return Pair.of(nonAggFunSlotsScope, aggFuncSlotsScope); - }); - return (analyzer, unboundSlot) -> { List boundInGroupBy = analyzer.bindSlotByScope(unboundSlot, groupBySlotsScope); - if (boundInGroupBy.size() == 1) { - return boundInGroupBy; - } - - Pair separateAggOutputScope = separateAggOutputScopes.get(); - List boundInNonAggFuncs = analyzer.bindSlotByScope(unboundSlot, separateAggOutputScope.first); - if (boundInNonAggFuncs.size() == 1) { - return boundInNonAggFuncs; + if (!boundInGroupBy.isEmpty()) { + return ImmutableList.of(boundInGroupBy.get(0)); } - List boundInAggFuncs = analyzer.bindSlotByScope(unboundSlot, separateAggOutputScope.second); - if (boundInAggFuncs.size() == 1) { - return boundInAggFuncs; + List boundInAggOutput = analyzer.bindSlotByScope(unboundSlot, aggOutputScope); + if (!boundInAggOutput.isEmpty()) { + return ImmutableList.of(boundInAggOutput.get(0)); } - return bindByAggChild.get().bindSlot(analyzer, unboundSlot); + List expressions = bindByAggChild.get().bindSlot(analyzer, unboundSlot); + return expressions.isEmpty() ? expressions : ImmutableList.of(expressions.get(0)); }; });