private static void findRoots(Operator<?> op, List<Operator<?>> ops) {
    List<Operator<?>> parents = op.getParentOperators();
    if (parents == null || parents.isEmpty()) {
      ops.add(op);
      return;
    }
    for (Operator<?> p : parents) {
      findRoots(p, ops);
    }
  }
getEncosingWork finds the BaseWork any given operator belongs to.
ql/src/java/org/apache/hadoop/hive/ql/parse/GenTezUtils.java