public static Operator<?> findSourceOperatorInSameBranch(Operator<?> op) {
    while (op != null && !(op instanceof TableScanOperator || op instanceof ReduceSinkOperator
            || op instanceof CommonJoinOperator)) {
      // If op has parents it is guaranteed to be 1.
      List<Operator<?>> parents = op.getParentOperators();
      Preconditions.checkState(parents.size() <= 1);
      op = parents.size() == 1 ? parents.get(0) : null;
    }
    return op;
  }
Traverses the operator chain upwards to find input source operator in that branch

@param op the starting operator
@return the first matching operator or null if none found
ql/src/java/org/apache/hadoop/hive/ql/exec/OperatorUtils.java