You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ca...@apache.org on 2025/04/02 06:14:55 UTC

(iotdb) branch fix_project_order_in_TableDistributedPlanGenerator created (now 50cade1f3c1)

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

caogaofei pushed a change to branch fix_project_order_in_TableDistributedPlanGenerator
in repository https://gitbox.apache.org/repos/asf/iotdb.git


      at 50cade1f3c1 fix node ordering

This branch includes the following new commits:

     new 50cade1f3c1 fix node ordering

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(iotdb) 01/01: fix node ordering

Posted by ca...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

caogaofei pushed a commit to branch fix_project_order_in_TableDistributedPlanGenerator
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit 50cade1f3c14f4cde4cfc5bf591d1ab59293f567
Author: Beyyes <cg...@foxmail.com>
AuthorDate: Wed Apr 2 14:14:38 2025 +0800

    fix node ordering
---
 .../distribute/TableDistributedPlanGenerator.java  | 42 ++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/planner/distribute/TableDistributedPlanGenerator.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/planner/distribute/TableDistributedPlanGenerator.java
index c8087e365d3..85142057e4b 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/planner/distribute/TableDistributedPlanGenerator.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/planner/distribute/TableDistributedPlanGenerator.java
@@ -259,6 +259,47 @@ public class TableDistributedPlanGenerator
     return resultNodeList;
   }
 
+  // @Override
+  public List<PlanNode> visitProject2(ProjectNode node, PlanContext context) {
+    List<PlanNode> childrenNodes = node.getChild().accept(this, context);
+    OrderingScheme childOrdering = nodeOrderingMap.get(childrenNodes.get(0).getPlanNodeId());
+    boolean containAllSortItem = false;
+    if (childOrdering != null) {
+      // the column used for order by has been pruned, we can't copy this node to sub nodeTrees.
+      containAllSortItem =
+          ImmutableSet.copyOf(node.getOutputSymbols()).containsAll(childOrdering.getOrderBy());
+    }
+    if (childrenNodes.size() == 1) {
+      if (containAllSortItem) {
+        nodeOrderingMap.put(node.getPlanNodeId(), childOrdering);
+      }
+      node.setChild(childrenNodes.get(0));
+      return Collections.singletonList(node);
+    }
+
+    boolean containsDiff =
+        node.getAssignments().getMap().values().stream()
+            .anyMatch(PushPredicateIntoTableScan::containsDiffFunction);
+    if (containsDiff) {
+      if (containAllSortItem) {
+        nodeOrderingMap.put(node.getPlanNodeId(), childOrdering);
+      }
+      node.setChild(mergeChildrenViaCollectOrMergeSort(childOrdering, childrenNodes));
+      return Collections.singletonList(node);
+    }
+
+    List<PlanNode> resultNodeList = new ArrayList<>(childrenNodes.size());
+    for (PlanNode child : childrenNodes) {
+      ProjectNode subProjectNode =
+          new ProjectNode(queryId.genPlanNodeId(), child, node.getAssignments());
+      resultNodeList.add(subProjectNode);
+      if (containAllSortItem) {
+        nodeOrderingMap.put(subProjectNode.getPlanNodeId(), childOrdering);
+      }
+    }
+    return resultNodeList;
+  }
+
   @Override
   public List<PlanNode> visitTopK(TopKNode node, PlanContext context) {
     context.setExpectedOrderingScheme(node.getOrderingScheme());
@@ -417,6 +458,7 @@ public class TableDistributedPlanGenerator
   public List<PlanNode> visitFilter(FilterNode node, PlanContext context) {
     List<PlanNode> childrenNodes = node.getChild().accept(this, context);
     OrderingScheme childOrdering = nodeOrderingMap.get(childrenNodes.get(0).getPlanNodeId());
+    // TODO examine allSortItem
     if (childOrdering != null) {
       nodeOrderingMap.put(node.getPlanNodeId(), childOrdering);
     }