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 <[email protected]> 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); }
