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 b7c5a9b9366 branch-4.2: [fix](eager-agg) Prevent unsafe concat_ws 
aggregate pushdown through outer joins #68182 (#70048)
b7c5a9b9366 is described below

commit b7c5a9b93669d1961af240490dd1ad0b4a0ca233
Author: morrySnow <[email protected]>
AuthorDate: Wed Nov 4 08:23:46 2026 +0800

    branch-4.2: [fix](eager-agg) Prevent unsafe concat_ws aggregate pushdown 
through outer joins #68182 (#70048)
    
    picked from master #68182
    
    Co-authored-by: feiniaofeiafei <[email protected]>
---
 .../expressions/functions/scalar/ConcatWs.java     |  3 +-
 .../eageraggregation/EagerAggRewriterTest.java     | 37 ++++++++++++++++++++++
 2 files changed, 39 insertions(+), 1 deletion(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ConcatWs.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ConcatWs.java
index 1a0382e4e1f..f120d7232a9 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ConcatWs.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ConcatWs.java
@@ -19,6 +19,7 @@ package 
org.apache.doris.nereids.trees.expressions.functions.scalar;
 
 import org.apache.doris.catalog.FunctionSignature;
 import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.NullToNonNullFunction;
 import 
org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature;
 import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
 import org.apache.doris.nereids.types.ArrayType;
@@ -35,7 +36,7 @@ import java.util.List;
  * ScalarFunction 'concat_ws'. This class is generated by GenerateFunction.
  */
 public class ConcatWs extends ScalarFunction
-        implements ExplicitlyCastableSignature {
+        implements ExplicitlyCastableSignature, NullToNonNullFunction {
 
     public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
             FunctionSignature.ret(VarcharType.SYSTEM_DEFAULT)
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/eageraggregation/EagerAggRewriterTest.java
 
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/eageraggregation/EagerAggRewriterTest.java
index 486d5805d34..1cbb3f30621 100644
--- 
a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/eageraggregation/EagerAggRewriterTest.java
+++ 
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/eageraggregation/EagerAggRewriterTest.java
@@ -735,4 +735,41 @@ class EagerAggRewriterTest extends TestWithFeService 
implements MemoPatternMatch
         }
         return null;
     }
+
+    @Test
+    void testNotPushConcatWsToNullableSideOfOuterJoin() {
+        // concat_ws(',', NULL) returns an empty string, so unmatched rows 
contribute to count.
+        // Pushing the aggregate to the nullable side would lose these 
contributions.
+        connectContext.getSessionVariable().setEagerAggregationMode(1);
+        connectContext.getSessionVariable().setDisableJoinReorder(true);
+        try {
+            String sql = "select count(concat_ws(',', t1.name)), t2.id2"
+                    + " from t1 right join t2 on t1.id1 = t2.id2 group by 
t2.id2";
+            PlanChecker.from(connectContext)
+                    .analyze(sql)
+                    .rewrite()
+                    .nonMatch(logicalJoin(logicalAggregate(), any()))
+                    .printlnTree();
+
+            sql = "select count(concat_ws(',', t2.name)), t1.id1"
+                    + " from t1 left join t2 on t1.id1 = t2.id2 group by 
t1.id1";
+            PlanChecker.from(connectContext)
+                    .analyze(sql)
+                    .rewrite()
+                    .nonMatch(logicalJoin(any(), logicalAggregate()))
+                    .printlnTree();
+
+            // Inner joins do not introduce null-extended rows, so pushdown 
remains safe.
+            sql = "select count(concat_ws(',', t1.name)), t2.id2"
+                    + " from t1 join t2 on t1.id1 = t2.id2 group by t2.id2";
+            PlanChecker.from(connectContext)
+                    .analyze(sql)
+                    .rewrite()
+                    
.matches(logicalAggregate(logicalProject(logicalJoin(logicalAggregate(), 
any()))))
+                    .printlnTree();
+        } finally {
+            connectContext.getSessionVariable().setEagerAggregationMode(0);
+            connectContext.getSessionVariable().setDisableJoinReorder(false);
+        }
+    }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to