private void removeSemiJoinEdgesForUnion(OptimizeTezProcContext procCtx) throws SemanticException{
    // Get all the TS ops.
    List<Operator<?>> topOps = new ArrayList<>();
    topOps.addAll(procCtx.parseContext.getTopOps().values());
    Set<Operator<?>> unionOps = new HashSet<>();

    Map<ReduceSinkOperator, TableScanOperator> sjToRemove = new HashMap<>();
    for (Operator<?> parent : topOps) {
      Deque<Operator<?>> deque = new LinkedList<>();
      deque.add(parent);
      while (!deque.isEmpty()) {
        Operator<?> op = deque.pollLast();
        if (op instanceof UnionOperator && !unionOps.contains(op)) {
          unionOps.add(op);
          removeSemiJoinEdges(op, procCtx, sjToRemove);
        }
        deque.addAll(op.getChildOperators());
      }
    }
    // remove sj
    if (sjToRemove.size() > 0) {
      for (Map.Entry<ReduceSinkOperator, TableScanOperator> entry : sjToRemove.entrySet()) {
        if (LOG.isDebugEnabled()) {
          LOG.debug("Semijoin optimization with Union operator. Removing semijoin "
                        + OperatorUtils.getOpNamePretty(entry.getKey()) + " - "
                        + OperatorUtils.getOpNamePretty(sjToRemove.get(entry.getKey())));
        }
        GenTezUtils.removeBranch(entry.getKey());
        GenTezUtils.removeSemiJoinOperator(procCtx.parseContext, entry.getKey(), entry.getValue());
      }
    }
  }
TezCompiler translates the operator plan into TezTasks.
ql/src/java/org/apache/hadoop/hive/ql/parse/TezCompiler.java