gortiz commented on code in PR #14296:
URL: https://github.com/apache/pinot/pull/14296#discussion_r1818762986


##########
pinot-query-planner/src/main/java/org/apache/pinot/query/planner/logical/ParentToChildrenCalculator.java:
##########
@@ -0,0 +1,56 @@
+/**
+ * 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.
+ */
+package org.apache.pinot.query.planner.logical;
+
+import java.util.Collections;
+import java.util.IdentityHashMap;
+import java.util.Set;
+import org.apache.pinot.query.planner.plannode.MailboxSendNode;
+import org.apache.pinot.query.planner.plannode.PlanNodeVisitor;
+
+
+/**
+ * Utility class to calculate the parent to children mapping for a given plan 
tree.
+ */
+public class ParentToChildrenCalculator {
+  private ParentToChildrenCalculator() {
+  }
+
+  /**
+   * Returns an identity map indexed by the parent node, with the value being 
a set of its <strong>direct</strong> child
+   * nodes.
+   */
+  public static IdentityHashMap<MailboxSendNode, Set<MailboxSendNode>> 
calculate(MailboxSendNode root) {
+    Visitor visitor = new Visitor();
+    root.getInputs().forEach(node -> node.visit(visitor, root));
+
+    return visitor._parentToChild;
+  }
+
+  private static class Visitor extends PlanNodeVisitor.DepthFirstVisitor<Void, 
MailboxSendNode> {
+    private IdentityHashMap<MailboxSendNode, Set<MailboxSendNode>> 
_parentToChild = new IdentityHashMap<>();
+
+    @Override
+    public Void visitMailboxSend(MailboxSendNode node, MailboxSendNode parent) 
{
+      _parentToChild.computeIfAbsent(parent, k -> 
Collections.newSetFromMap(new IdentityHashMap<>())).add(node);
+      visitChildren(node, node); // children will be called with the current 
node as the parent

Review Comment:
   You are right. That is going to be used in the prunning process explained in 
another comment. I guess I didn't need to include this code in the first PR. My 
original plan was to include the prunning process in ths PR but I removed that 
before creating the PR. I can add it if you feel it would be useful.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to