@SuppressWarnings("unchecked")
  private void walk(Node nd, int level, Stack<Node> stack)
      throws SemanticException {
    List<Operator<? extends OperatorDesc>> parents =
        ((Operator<? extends OperatorDesc>) nd).getParentOperators();

    if (level >= numLevels || CollectionUtils.isEmpty(parents)) {
      dispatch(stack.peek(), stack);
      return;
    }

    for (Node parent : parents) {
      stack.add(0, parent);
      walk(parent, level + 1, stack);
      stack.remove(0);
    }
  }
Enumerate numLevels of ancestors by putting them in the stack and dispatch
the current node.

@param nd current operator in the ancestor tree
@param level how many level of ancestors included in the stack
@param stack operator stack
@throws SemanticException
ql/src/java/org/apache/hadoop/hive/ql/lib/LevelOrderWalker.java