From eb2387c62e3efcd70d7edb0d6e58d458fb13b50f Mon Sep 17 00:00:00 2001 From: morrySnow <101034200+morrySnow@users.noreply.github.com> Date: Tue, 2 Jul 2024 19:36:59 +0800 Subject: [PATCH] [fix](Nereids) normalize aggregate should not push down lambda's param (#37109) pick from master #37109 ArrayItemSlot should not be inputSlot --- .../doris/nereids/trees/expressions/Expression.java | 4 +++- .../normalize_aggregate_test.out | 3 +++ .../normalize_aggregate_test.groovy | 13 +++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Expression.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Expression.java index f6c7cbdb66a85a1..d7f400955c022c8 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Expression.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Expression.java @@ -23,6 +23,7 @@ import org.apache.doris.nereids.analyzer.UnboundVariable; import org.apache.doris.nereids.exceptions.AnalysisException; import org.apache.doris.nereids.trees.AbstractTreeNode; +import org.apache.doris.nereids.trees.expressions.ArrayItemReference.ArrayItemSlot; import org.apache.doris.nereids.trees.expressions.functions.ExpressionTrait; import org.apache.doris.nereids.trees.expressions.functions.Nondeterministic; import org.apache.doris.nereids.trees.expressions.functions.agg.AggregateFunction; @@ -67,7 +68,8 @@ public abstract class Expression extends AbstractTreeNode implements private final boolean inferred; private final boolean hasUnbound; private final boolean compareWidthAndDepth; - private final Supplier> inputSlots = Suppliers.memoize(() -> collect(Slot.class::isInstance)); + private final Supplier> inputSlots = Suppliers.memoize( + () -> collect(e -> e instanceof Slot && !(e instanceof ArrayItemSlot))); protected Expression(Expression... children) { super(children); diff --git a/regression-test/data/nereids_rules_p0/normalize_aggregate/normalize_aggregate_test.out b/regression-test/data/nereids_rules_p0/normalize_aggregate/normalize_aggregate_test.out index 50c132b2f72ebed..76173253ac0e173 100644 --- a/regression-test/data/nereids_rules_p0/normalize_aggregate/normalize_aggregate_test.out +++ b/regression-test/data/nereids_rules_p0/normalize_aggregate/normalize_aggregate_test.out @@ -1,3 +1,6 @@ -- This file is automatically generated. You should know what you did if you want to edit this -- !test_upper_project_projections_rewrite2 -- +-- !test_lambda -- +1 + diff --git a/regression-test/suites/nereids_rules_p0/normalize_aggregate/normalize_aggregate_test.groovy b/regression-test/suites/nereids_rules_p0/normalize_aggregate/normalize_aggregate_test.groovy index f3c732c0671fbeb..6f2c67414d3c537 100644 --- a/regression-test/suites/nereids_rules_p0/normalize_aggregate/normalize_aggregate_test.groovy +++ b/regression-test/suites/nereids_rules_p0/normalize_aggregate/normalize_aggregate_test.groovy @@ -15,12 +15,25 @@ // specific language governing permissions and limitations // under the License. suite("normalize_aggregate") { + sql "SET enable_nereids_planner=true" sql "SET enable_fallback_to_original_planner=false" + + qt_test_upper_project_projections_rewrite """ + SELECT DISTINCT + + ( ( + + 46 ) ) * 89 AS col0, COUNT( * ) + + - 72 + - - 87 - AVG ( ALL - 56 ) * COUNT( * ) + - CASE + 49 WHEN 6 * + 76 + - + + CAST( NULL AS SIGNED ) THEN NULL WHEN - COUNT( DISTINCT + + CAST( NULL AS SIGNED ) ) + 23 THEN NULL ELSE - + 43 * 32 - + 97 + - ( + 65 ) * + + + CASE - 77 WHEN 5 THEN - 56 * + 26 ELSE NULL END / + COUNT( * ) + 20 + + 78 END * COALESCE ( COUNT( * ), - 60 - 90, + 42 * 27 - 98 * ( - 83 + 47 / 7 ), + - ( NULLIF ( 61, 83 + 88 ) ) ) * 94; + """ +>>>>>>> cce5d5b6a2 ([fix](Nereids) normalize aggregate should not push down lambda's param (#37109)) sql "drop table if exists normalize_aggregate_tab" sql """CREATE TABLE normalize_aggregate_tab(col0 INTEGER, col1 INTEGER, col2 INTEGER) distributed by hash(col0) buckets 10 properties('replication_num' = '1'); """ qt_test_upper_project_projections_rewrite2 """ SELECT - + AVG ( DISTINCT - col0 ) * - col0 FROM normalize_aggregate_tab WHERE + - col0 IS NULL GROUP BY col0 HAVING NULL IS NULL;""" + + qt_test_lambda """ + select count(array_filter(i -> (i > 0.99), array(1, 2, 3))) + """ } \ No newline at end of file