This is an automated email from the ASF dual-hosted git repository. liulijia pushed a commit to branch branch-2.1 in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.1 by this push: new 07ea5111413 [opt](optimizer) Remove unused code to unify code (#38918) 07ea5111413 is described below commit 07ea51114132ee729158040e99027effd0686167 Author: Lijia Liu <liutang...@yeah.net> AuthorDate: Tue Aug 6 19:09:25 2024 +0800 [opt](optimizer) Remove unused code to unify code (#38918) ## Proposed changes Now, Agg's child predicates will not spread to agg. For example: select a, sum(b) from ( select a,b from t where a = 1 and b = 2 ) t group by a `a = 1` in scan can be propagated to `a` of agg. But `b = 2` in scan can not be propagated to `sum(b)` of agg. Issue Number: #38905 <!--Describe your changes.--> Co-authored-by: liutang123 <liuli...@gmail.com> --- .../nereids/rules/rewrite/PullUpPredicates.java | 18 +-------- .../nereids/rules/rewrite/InferPredicatesTest.java | 44 ++++++++++++++++++++++ 2 files changed, 45 insertions(+), 17 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PullUpPredicates.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PullUpPredicates.java index dec288a6f52..7f7314d483c 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PullUpPredicates.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PullUpPredicates.java @@ -35,11 +35,9 @@ import org.apache.doris.nereids.util.ExpressionUtils; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet.Builder; import com.google.common.collect.Lists; -import com.google.common.collect.Maps; import com.google.common.collect.Sets; import java.util.IdentityHashMap; -import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; @@ -107,21 +105,7 @@ public class PullUpPredicates extends PlanVisitor<ImmutableSet<Expression>, Void return cacheOrElse(aggregate, () -> { ImmutableSet<Expression> childPredicates = aggregate.child().accept(this, context); // TODO - List<NamedExpression> outputExpressions = aggregate.getOutputExpressions(); - - Map<Expression, Slot> expressionSlotMap - = Maps.newLinkedHashMapWithExpectedSize(outputExpressions.size()); - for (NamedExpression output : outputExpressions) { - if (hasAgg(output)) { - expressionSlotMap.putIfAbsent( - output instanceof Alias ? output.child(0) : output, output.toSlot() - ); - } - } - Expression expression = ExpressionUtils.replace( - ExpressionUtils.and(Lists.newArrayList(childPredicates)), - expressionSlotMap - ); + Expression expression = ExpressionUtils.and(Lists.newArrayList(childPredicates)); Set<Expression> predicates = Sets.newLinkedHashSet(ExpressionUtils.extractConjunction(expression)); return getAvailableExpressions(predicates, aggregate); }); diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/InferPredicatesTest.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/InferPredicatesTest.java index c272e4d340b..0f4bf27c149 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/InferPredicatesTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/InferPredicatesTest.java @@ -73,6 +73,12 @@ class InferPredicatesTest extends TestWithFeService implements MemoPatternMatchS + "distributed by hash(k2) buckets 1\n" + "properties('replication_num' = '1');"); + createTables("CREATE TABLE `test`.`test_tt` (\n" + + "`key` varchar(*) NOT NULL,\n" + + " `value` varchar(*) NULL\n" + + ") ENGINE=OLAP\n" + + "DISTRIBUTED BY HASH(`key`) BUCKETS 1\n" + + "PROPERTIES ('replication_allocation' = 'tag.location.default: 1');"); connectContext.setDatabase("test"); connectContext.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION"); } @@ -645,4 +651,42 @@ class InferPredicatesTest extends TestWithFeService implements MemoPatternMatchS )) ); } + + @Test + void testAggMultiAliasWithSameChild() { + String sql = "SELECT t.*\n" + + "FROM (\n" + + " SELECT `key`, a , b \n" + + " FROM (\n" + + " SELECT `key`,\n" + + " any_value(value) AS a,\n" + + " any_value(CAST(value AS double)) AS b\n" + + " FROM (\n" + + " SELECT `key`, CAST(value AS double) AS value\n" + + " FROM test_tt\n" + + " WHERE `key` = '1'\n" + + " ) agg\n" + + " GROUP BY `key`\n" + + " ) proj\n" + + ") t\n" + + "LEFT JOIN\n" + + "( SELECT id, name FROM student) t2\n" + + "ON t.`key`=t2.`name`"; + PlanChecker.from(connectContext).analyze(sql).rewrite().printlnTree(); + PlanChecker.from(connectContext) + .analyze(sql) + .rewrite() + .matches( + logicalJoin( + any(), + logicalProject( + logicalFilter( + logicalOlapScan() + ).when(filter -> filter.getConjuncts().size() == 1 + && filter.getPredicate().toSql().contains("name = '1'")) + ) + ).when(join -> join.getJoinType() == JoinType.LEFT_OUTER_JOIN) + ); + + } } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org