You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by mo...@apache.org on 2023/01/03 03:19:32 UTC

[doris] branch master updated: [fix](nereids) check failed that exchange node under agg must from PhysicalDistribute (#15473)

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

morrysnow pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 31548cfe2a [fix](nereids) check failed that exchange node under agg must from PhysicalDistribute (#15473)
31548cfe2a is described below

commit 31548cfe2a0d9855ea01ef4c2405bf337b391396
Author: minghong <en...@gmail.com>
AuthorDate: Tue Jan 3 11:19:25 2023 +0800

    [fix](nereids) check failed that exchange node under agg must from PhysicalDistribute (#15473)
    
    when nereids translates PhysicalHashAggreg node to original plan, if the input fragment root is exchange node, nereids assumes that this exchanged node is generated from PhyscialDistirbute node.
    But this assumption is not true. For example, sort node could be translated to exchange(merge phase)+sort(local phase).
---
 .../glue/translator/PhysicalPlanTranslator.java    | 12 ++++---
 .../data/nereids_syntax_p0/agg_with_sort.out       |  4 +++
 .../suites/nereids_syntax_p0/agg_with_sort.groovy  | 38 ++++++++++++++++++++++
 3 files changed, 50 insertions(+), 4 deletions(-)

diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslator.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslator.java
index aac80b95f4..dda2ee547d 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslator.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslator.java
@@ -227,10 +227,14 @@ public class PhysicalPlanTranslator extends DefaultPlanVisitor<PlanFragment, Pla
                 .collect(Collectors.toCollection(ArrayList::new));
 
         PlanFragment currentFragment;
-        if (inputPlanFragment.getPlanRoot() instanceof ExchangeNode) {
-            Preconditions.checkState(aggregate.child() instanceof PhysicalDistribute,
-                    "When the ExchangeNode is child of PhysicalHashAggregate, "
-                            + "it should be created by PhysicalDistribute, but meet " + aggregate.child());
+        if (inputPlanFragment.getPlanRoot() instanceof ExchangeNode
+                && aggregate.child() instanceof PhysicalDistribute) {
+            //the exchange node is generated in two cases:
+            //  1. some nodes (e.g. sort node) need to gather data from multiple instances, and hence their gather phase
+            //     need an exchange node. For this type of exchange, their data partition is un_partitioned, do not
+            //     create a new plan fragment.
+            //  2. PhysicalDistribute node is translated to exchange node. PhysicalDistribute node means we need to
+            //     shuffle data, and we have to create a new plan fragment.
             ExchangeNode exchangeNode = (ExchangeNode) inputPlanFragment.getPlanRoot();
             Optional<List<Expression>> partitionExpressions = aggregate.getPartitionExpressions();
             PhysicalDistribute physicalDistribute = (PhysicalDistribute) aggregate.child();
diff --git a/regression-test/data/nereids_syntax_p0/agg_with_sort.out b/regression-test/data/nereids_syntax_p0/agg_with_sort.out
new file mode 100644
index 0000000000..c92ff08e08
--- /dev/null
+++ b/regression-test/data/nereids_syntax_p0/agg_with_sort.out
@@ -0,0 +1,4 @@
+-- This file is automatically generated. You should know what you did if you want to edit this
+-- !select --
+0
+
diff --git a/regression-test/suites/nereids_syntax_p0/agg_with_sort.groovy b/regression-test/suites/nereids_syntax_p0/agg_with_sort.groovy
new file mode 100644
index 0000000000..623c3e2973
--- /dev/null
+++ b/regression-test/suites/nereids_syntax_p0/agg_with_sort.groovy
@@ -0,0 +1,38 @@
+// 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("agg_with_sort") {
+    sql "SET enable_nereids_planner=true"
+    sql "set enable_fallback_to_original_planner=false"
+    sql """
+        DROP TABLE IF EXISTS tbl
+       """
+
+    sql """CREATE TABLE IF NOT EXISTS tbl (a int not null, b int not null)
+        DISTRIBUTED BY HASH(a)
+        BUCKETS 1
+        PROPERTIES(
+            "replication_num"="1"
+        )
+        """
+    //make sure we can handle this sql pattern:
+    // agg -> exchange -> sort
+        
+    qt_select """
+        select count(1) from (select a from tbl order by a desc) t;
+    """
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org