private static void iterateParents(Operator<?> operator, Function<Operator<?>> function, Set<Operator<?>> visited) {
    if (!visited.add(operator)) {
      return;
    }
    function.apply(operator);
    if (operator.getNumParent() > 0) {
      for (Operator<?> parent : operator.getParentOperators()) {
        iterateParents(parent, function, visited);
      }
    }
  }
Starting at the input operator, finds the last operator in the stream that
is an instance of the input class.

@param op the starting operator
@param clazz the class that the operator that we are looking for instantiates
@return null if no such operator exists or multiple branches are found in
the stream, the last operator otherwise
ql/src/java/org/apache/hadoop/hive/ql/exec/OperatorUtils.java