This is an automated email from the ASF dual-hosted git repository.
huajianlan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new eb75ea88d61 [fix](Nereids) fix bind having aggregate failed again
(#32687)
eb75ea88d61 is described below
commit eb75ea88d619369952b436122c4c498fe0b5e6d8
Author: 924060929 <[email protected]>
AuthorDate: Fri Mar 22 20:39:40 2024 +0800
[fix](Nereids) fix bind having aggregate failed again (#32687)
follow up #32490
add more tests and fix some cases because some sqls are valid to mysql, but
failed in doris
---
.../nereids/rules/analysis/BindExpression.java | 37 ++++------------------
.../data/nereids_syntax_p0/bind_priority.out | 9 ++++++
.../suites/nereids_syntax_p0/bind_priority.groovy | 21 ++++++++++++
3 files changed, 37 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 04ba599aa60..c2c7f5815d9 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 @@ package org.apache.doris.nereids.rules.analysis;
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 @@ public class BindExpression implements
AnalysisRuleFactory {
}
Scope groupBySlotsScope = toScope(cascadesContext,
groupBySlots.build());
- Supplier<Pair<Scope, Scope>> separateAggOutputScopes =
Suppliers.memoize(() -> {
- ImmutableList.Builder<Slot> groupByOutputs =
ImmutableList.builderWithExpectedSize(
- aggregate.getOutputExpressions().size());
- ImmutableList.Builder<Slot> 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<Slot> boundInGroupBy =
analyzer.bindSlotByScope(unboundSlot, groupBySlotsScope);
- if (boundInGroupBy.size() == 1) {
- return boundInGroupBy;
- }
-
- Pair<Scope, Scope> separateAggOutputScope =
separateAggOutputScopes.get();
- List<Slot> boundInNonAggFuncs =
analyzer.bindSlotByScope(unboundSlot, separateAggOutputScope.first);
- if (boundInNonAggFuncs.size() == 1) {
- return boundInNonAggFuncs;
+ if (!boundInGroupBy.isEmpty()) {
+ return ImmutableList.of(boundInGroupBy.get(0));
}
- List<Slot> boundInAggFuncs =
analyzer.bindSlotByScope(unboundSlot, separateAggOutputScope.second);
- if (boundInAggFuncs.size() == 1) {
- return boundInAggFuncs;
+ List<Slot> boundInAggOutput =
analyzer.bindSlotByScope(unboundSlot, aggOutputScope);
+ if (!boundInAggOutput.isEmpty()) {
+ return ImmutableList.of(boundInAggOutput.get(0));
}
- return bindByAggChild.get().bindSlot(analyzer, unboundSlot);
+ List<? extends Expression> expressions =
bindByAggChild.get().bindSlot(analyzer, unboundSlot);
+ return expressions.isEmpty() ? expressions :
ImmutableList.of(expressions.get(0));
};
});
diff --git a/regression-test/data/nereids_syntax_p0/bind_priority.out
b/regression-test/data/nereids_syntax_p0/bind_priority.out
index eb4002d960a..53432880c24 100644
--- a/regression-test/data/nereids_syntax_p0/bind_priority.out
+++ b/regression-test/data/nereids_syntax_p0/bind_priority.out
@@ -76,3 +76,12 @@ all 2
-- !having_bind_group_by --
7 3
+-- !having_bind_group_by --
+4 5 3
+
+-- !having_bind_group_by --
+1 2
+
+-- !having_bind_group_by --
+2 1
+
diff --git a/regression-test/suites/nereids_syntax_p0/bind_priority.groovy
b/regression-test/suites/nereids_syntax_p0/bind_priority.groovy
index 4e1740061b6..84bab14eba0 100644
--- a/regression-test/suites/nereids_syntax_p0/bind_priority.groovy
+++ b/regression-test/suites/nereids_syntax_p0/bind_priority.groovy
@@ -287,5 +287,26 @@ suite("bind_priority") {
GROUP by pk + 6
HAVING pk = 3
"""
+
+ order_qt_having_bind_group_by """
+ select pk + 1 as pk, pk + 2 as pk, count(*)
+ from test_bind_having_slots3
+ group by pk + 1, pk + 2
+ having pk = 4;
+ """
+
+ order_qt_having_bind_group_by """
+ select count(*) pk, pk + 1 as pk
+ from test_bind_having_slots3
+ group by pk + 1, pk + 2
+ having pk = 1;
+ """
+
+ order_qt_having_bind_group_by """
+ select pk + 1 as pk, count(*) pk
+ from test_bind_having_slots3
+ group by pk + 1, pk + 2
+ having pk = 2;
+ """
}()
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]