This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-4.2
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-4.2 by this push:
new 9695ae9a349 branch-4.2: [fix](expr) fix deep match expr utils
duplicate walk #68362 (#70041)
9695ae9a349 is described below
commit 9695ae9a349261b67af2f3471c04cbfb345f5e3f
Author: morrySnow <[email protected]>
AuthorDate: Tue Nov 3 17:09:41 2026 +0800
branch-4.2: [fix](expr) fix deep match expr utils duplicate walk #68362
(#70041)
picked from master #68362
Co-authored-by: feiniaofeiafei <[email protected]>
---
.../nereids/rules/rewrite/MergeAggregate.java | 2 +-
.../rules/rewrite/PushCountIntoUnionAll.java | 2 +-
.../apache/doris/nereids/util/AggregateUtils.java | 4 +-
.../apache/doris/nereids/util/ExpressionUtils.java | 8 ++--
.../nereids/util/ExpressionUtilsTraversalTest.java | 52 ++++++++++++++++++++++
5 files changed, 60 insertions(+), 8 deletions(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/MergeAggregate.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/MergeAggregate.java
index ca3bc69649d..c89ce4570ac 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/MergeAggregate.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/MergeAggregate.java
@@ -218,7 +218,7 @@ public class MergeAggregate implements RewriteRuleFactory {
return false;
}
// project cannot have expressions like a+1
- if (ExpressionUtils.deapAnyMatch(project.getProjects(),
+ if (ExpressionUtils.deepAnyMatch(project.getProjects(),
expr -> !(expr instanceof SlotReference) && !(expr instanceof
Alias))) {
return false;
}
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 ddca8e479a3..b1fb62f5107 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
@@ -195,7 +195,7 @@ public class PushCountIntoUnionAll implements
RewriteRuleFactory {
private boolean hasUnsuportedAggFunc(LogicalAggregate aggregate) {
// only support count, not suport sum,min... and not support
count(distinct)
- return ExpressionUtils.deapAnyMatch(aggregate.getOutputExpressions(),
expr -> {
+ return ExpressionUtils.deepAnyMatch(aggregate.getOutputExpressions(),
expr -> {
if (expr instanceof AggregateFunction) {
if (!(expr instanceof Count)) {
return true;
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/util/AggregateUtils.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/util/AggregateUtils.java
index 6e5e0068408..646d3829a51 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/util/AggregateUtils.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/util/AggregateUtils.java
@@ -131,13 +131,13 @@ public class AggregateUtils {
}
public static boolean containsCountDistinctMultiExpr(LogicalAggregate<?
extends Plan> aggregate) {
- return ExpressionUtils.deapAnyMatch(aggregate.getOutputExpressions(),
expr ->
+ return ExpressionUtils.deepAnyMatch(aggregate.getOutputExpressions(),
expr ->
expr instanceof Count && ((Count) expr).isDistinct() &&
expr.arity() > 1);
}
/** e.g. Aggregation with avg(distinct a)(not support multiDistinct) or
count(distinct a,b) will return true*/
public static boolean
containsNotSupportMultiDistinctFunction(LogicalAggregate<? extends Plan>
aggregate) {
- return ExpressionUtils.deapAnyMatch(aggregate.getOutputExpressions(),
expr -> {
+ return ExpressionUtils.deepAnyMatch(aggregate.getOutputExpressions(),
expr -> {
if (expr instanceof AggregateFunction && ((AggregateFunction)
expr).isDistinct()) {
return !(expr instanceof SupportMultiDistinct)
|| expr instanceof Count && ((Count)
expr).isDistinct() && expr.arity() > 1;
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/util/ExpressionUtils.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/util/ExpressionUtils.java
index d61906cf221..e0848d59eef 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/util/ExpressionUtils.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/util/ExpressionUtils.java
@@ -1149,10 +1149,10 @@ public class ExpressionUtils {
}
/** deapAnyMatch */
- public static boolean deapAnyMatch(
+ public static boolean deepAnyMatch(
Collection<? extends Expression> expressions,
Predicate<TreeNode<Expression>> predicate) {
for (Expression expression : expressions) {
- if (expression.anyMatch(expr -> expr.anyMatch(predicate))) {
+ if (expression.anyMatch(predicate)) {
return true;
}
}
@@ -1160,10 +1160,10 @@ public class ExpressionUtils {
}
/** deapNoneMatch */
- public static boolean deapNoneMatch(
+ public static boolean deepNoneMatch(
Collection<? extends Expression> expressions,
Predicate<TreeNode<Expression>> predicate) {
for (Expression expression : expressions) {
- if (expression.anyMatch(expr -> expr.anyMatch(predicate))) {
+ if (expression.anyMatch(predicate)) {
return false;
}
}
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/nereids/util/ExpressionUtilsTraversalTest.java
b/fe/fe-core/src/test/java/org/apache/doris/nereids/util/ExpressionUtilsTraversalTest.java
new file mode 100644
index 00000000000..010a811061b
--- /dev/null
+++
b/fe/fe-core/src/test/java/org/apache/doris/nereids/util/ExpressionUtilsTraversalTest.java
@@ -0,0 +1,52 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.nereids.util;
+
+import org.apache.doris.nereids.trees.expressions.Add;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral;
+
+import com.google.common.collect.ImmutableList;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import java.util.concurrent.atomic.AtomicInteger;
+
+class ExpressionUtilsTraversalTest {
+ @Test
+ void visitsEachNodeOnceWhenNoNodeMatches() {
+ Expression expression = new Add(new IntegerLiteral(1),
+ new Add(new IntegerLiteral(2), new IntegerLiteral(3)));
+ AtomicInteger visits = new AtomicInteger();
+
Assertions.assertFalse(ExpressionUtils.deepAnyMatch(ImmutableList.of(expression),
node -> {
+ visits.incrementAndGet();
+ return false;
+ }));
+ Assertions.assertEquals(5, visits.get());
+ visits.set(0);
+
Assertions.assertTrue(ExpressionUtils.deepNoneMatch(ImmutableList.of(expression),
node -> {
+ visits.incrementAndGet();
+ return false;
+ }));
+ Assertions.assertEquals(5, visits.get());
+
Assertions.assertTrue(ExpressionUtils.deepAnyMatch(ImmutableList.of(expression),
+ node -> node.equals(new IntegerLiteral(3))));
+
Assertions.assertFalse(ExpressionUtils.deepNoneMatch(ImmutableList.of(expression),
+ node -> node.equals(new IntegerLiteral(3))));
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]