diff --git ql/src/java/org/apache/hadoop/hive/ql/lib/DefaultGraphWalker.java ql/src/java/org/apache/hadoop/hive/ql/lib/DefaultGraphWalker.java index d452f50..0870f93 100644 --- ql/src/java/org/apache/hadoop/hive/ql/lib/DefaultGraphWalker.java +++ ql/src/java/org/apache/hadoop/hive/ql/lib/DefaultGraphWalker.java @@ -144,32 +144,33 @@ public void startWalking(Collection startNodes, * @throws SemanticException */ protected void walk(Node nd) throws SemanticException { + // This is a stack with the number of children + // that we have visited for each node + Stack posStack = new Stack(); + // Push the node in the stack opStack.push(nd); + posStack.push(0); // While there are still nodes to dispatch... while (!opStack.empty()) { Node node = opStack.peek(); + int pos = posStack.pop(); if (node.getChildren() == null || - getDispatchedList().containsAll(node.getChildren())) { + pos >= node.getChildren().size()) { // Dispatch current node - if (!getDispatchedList().contains(node)) { - dispatch(node, opStack); - opQueue.add(node); - } + dispatch(node, opStack); + opQueue.add(node); opStack.pop(); continue; } // Add a single child and restart the loop - for (Node childNode : node.getChildren()) { - if (!getDispatchedList().contains(childNode)) { - opStack.push(childNode); - break; - } - } + Node childNode = node.getChildren().get(pos); + opStack.push(childNode); + posStack.push(++pos); + posStack.push(0); } // end while } - }