diff --git a/ql/src/java/org/apache/hadoop/hive/ql/lib/DefaultGraphWalker.java b/ql/src/java/org/apache/hadoop/hive/ql/lib/DefaultGraphWalker.java index e45b5a9..88b609c 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/lib/DefaultGraphWalker.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/lib/DefaultGraphWalker.java @@ -18,16 +18,15 @@ package org.apache.hadoop.hive.ql.lib; -import java.util.ArrayList; +import java.util.ArrayDeque; import java.util.Collection; import java.util.HashMap; import java.util.IdentityHashMap; -import java.util.LinkedList; -import java.util.List; import java.util.Queue; import java.util.Set; import java.util.Stack; +import org.apache.commons.collections.CollectionUtils; import org.apache.hadoop.hive.ql.parse.SemanticException; /** @@ -53,7 +52,7 @@ * toWalk stores the starting nodes for the graph that needs to be * traversed */ - protected final List toWalk = new ArrayList(); + protected final Queue toWalk = new ArrayDeque<>(); protected final IdentityHashMap retMap = new IdentityHashMap(); protected final Dispatcher dispatcher; @@ -66,7 +65,7 @@ public DefaultGraphWalker(Dispatcher disp) { dispatcher = disp; opStack = new Stack(); - opQueue = new LinkedList(); + opQueue = new ArrayDeque<>(); } /** @@ -93,11 +92,13 @@ public void dispatch(Node nd, Stack ndStack) throws SemanticException { * Returns dispatch result */ public T dispatchAndReturn(Node nd, Stack ndStack) throws SemanticException { + final Collection nodeChildren = nd.getChildren(); Object[] nodeOutputs = null; - if (nd.getChildren() != null) { - nodeOutputs = new Object[nd.getChildren().size()]; + + if (CollectionUtils.isNotEmpty(nodeChildren)) { + nodeOutputs = new Object[nodeChildren.size()]; int i = 0; - for (Node child : nd.getChildren()) { + for (Node child : nodeChildren) { nodeOutputs[i++] = retMap.get(child); } } @@ -115,8 +116,8 @@ public void dispatch(Node nd, Stack ndStack) throws SemanticException { public void startWalking(Collection startNodes, HashMap nodeOutput) throws SemanticException { toWalk.addAll(startNodes); - while (toWalk.size() > 0) { - Node nd = toWalk.remove(0); + while (!toWalk.isEmpty()) { + final Node nd = toWalk.poll(); walk(nd); // Some walkers extending DefaultGraphWalker e.g. ForwardWalker // do not use opQueue and rely uniquely in the toWalk structure,