@SuppressWarnings("unchecked")
  private static <T> Set<T> findOperatorsUpstream(Operator<?> start, Class<T> clazz, Set<T> found) {
    if (clazz.isInstance(start)) {
      found.add((T) start);
    }
    if (start.getParentOperators() != null) {
      for (Operator<?> parent : start.getParentOperators()) {
        findOperatorsUpstream(parent, clazz, found);
      }
    }
    return found;
  }
Return the ancestor of the specified operator at the provided path or null if the path is invalid.

The method is equivalent to following code:
<pre>{@code
    op.getParentOperators().get(path[0])
    .getParentOperators().get(path[1])
    ...
    .getParentOperators().get(path[n])
}</pre>
with additional checks about the validity of the provided path and the type of the ancestor.

@param op the operator for which we
@param clazz the class of the ancestor operator
@param path the path leading to the desired ancestor
@param <T> the type of the ancestor
@return the ancestor of the specified operator at the provided path or null if the path is invalid.
ql/src/java/org/apache/hadoop/hive/ql/exec/OperatorUtils.java