This is an automated email from the ASF dual-hosted git repository.

morningman pushed a commit to branch branch-1.2-lts
in repository https://gitbox.apache.org/repos/asf/doris.git

commit ad61c84a606d2de6e048e0a6ecf035ab9394e803
Author: mch_ucchi <[email protected]>
AuthorDate: Mon Mar 27 17:50:52 2023 +0800

    [fix](planner) fix conjunct planned on exchange node (#18042)
    
    sql like:
    select k5, k6, SUM(k3) AS k3
    from (
        select
            k5,
            date_format(k6, '%Y-%m-%d') as k6,
            count(distinct k3) as k3
        from t
        group by k5, k6
    ) AS temp where 1=1
    group by k5, k6;
    
    will throw exception since conjuncts planned on exchange node, because 
exchange node cannot handle conjuncts, now we skip exchange node when planning 
conjuncts, which fixes the bug.
    notice: the bug occurs iff the conjunct is always true like 1=1 above.
---
 .../java/org/apache/doris/planner/PlanNode.java    |  4 ++
 .../suites/correctness_p0/test_distinct_agg.groovy | 58 ++++++++++++++++++++++
 2 files changed, 62 insertions(+)

diff --git a/fe/fe-core/src/main/java/org/apache/doris/planner/PlanNode.java 
b/fe/fe-core/src/main/java/org/apache/doris/planner/PlanNode.java
index 4543576a0d..8064686719 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/planner/PlanNode.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/planner/PlanNode.java
@@ -714,6 +714,10 @@ public abstract class PlanNode extends TreeNode<PlanNode> 
implements PlanStats {
      * Assign remaining unassigned conjuncts.
      */
     protected void assignConjuncts(Analyzer analyzer) {
+        // we cannot plan conjuncts on exchange node, so we just skip the node.
+        if (this instanceof ExchangeNode) {
+            return;
+        }
         List<Expr> unassigned = analyzer.getUnassignedConjuncts(this);
         for (Expr unassignedConjunct : unassigned) {
             addConjunct(unassignedConjunct);
diff --git a/regression-test/suites/correctness_p0/test_distinct_agg.groovy 
b/regression-test/suites/correctness_p0/test_distinct_agg.groovy
new file mode 100644
index 0000000000..8c80c9f184
--- /dev/null
+++ b/regression-test/suites/correctness_p0/test_distinct_agg.groovy
@@ -0,0 +1,58 @@
+// 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.
+
+suite("test_distinct_agg") {
+    sql 'drop table if exists t'
+
+    sql '''
+        CREATE TABLE `t` (
+            `k1` bigint(20) NULL,
+            `k2` varchar(20) NULL,
+            `k3` varchar(20) NULL,
+            `k4` varchar(20) NULL,
+            `k5` varchar(20) NULL,
+            `k6` datetime NULL
+        ) ENGINE=OLAP
+        UNIQUE KEY(`k1`, `k2`)
+        DISTRIBUTED BY HASH(`k1`, `k2`) BUCKETS 3
+        PROPERTIES (
+            "replication_allocation" = "tag.location.default: 1"
+        );
+    '''
+
+    sql '''
+        INSERT INTO `t` (`k1`, `k2`, `k3`, `k4`, `k5`, `k6`) VALUES
+            (1, '1234', 'A0', 'C0', '1', '2023-01-10 23:00:00');
+    '''
+
+    test {
+        sql '''
+            select k5, k6, SUM(k3) AS k3 
+            from ( 
+                select
+                    k5,
+                    date_format(k6, '%Y-%m-%d') as k6,
+                    count(distinct k3) as k3 
+                from t 
+                where 1=1 
+                group by k5, k6
+            ) AS temp where 1=1
+            group by k5, k6;
+        '''
+        result([['1', '2023-01-10', 1L]])
+    }
+}
\ No newline at end of file


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

Reply via email to