private void removeRedundantSemijoinAndDpp(OptimizeTezProcContext procCtx)
      throws SemanticException {
    Map<SemanticRule, SemanticNodeProcessor> opRules = new LinkedHashMap<>();
    opRules.put(
        new RuleRegExp("R1", GroupByOperator.getOperatorName() + "%" +
            ReduceSinkOperator.getOperatorName() + "%" +
            GroupByOperator.getOperatorName() + "%" +
            ReduceSinkOperator.getOperatorName() + "%"),
        new SemiJoinRemovalProc(false, true));
    opRules.put(
        new RuleRegExp("R2",
            AppMasterEventOperator.getOperatorName() + "%"),
        new DynamicPruningRemovalRedundantProc());

    // Gather
    SemiJoinRemovalContext ctx =
        new SemiJoinRemovalContext(procCtx.parseContext);
    SemanticDispatcher disp = new DefaultRuleDispatcher(null, opRules, ctx);
    List<Node> topNodes = new ArrayList<Node>();
    topNodes.addAll(procCtx.parseContext.getTopOps().values());
    SemanticGraphWalker ogw = new PreOrderOnceWalker(disp);
    ogw.startWalking(topNodes, null);

    // Remove
    for (Map.Entry<Operator<?>, TableScanOperator> p : ctx.opsToRemove.entrySet()) {
      if (LOG.isDebugEnabled()) {
        LOG.debug("Removing redundant " + OperatorUtils.getOpNamePretty(p.getKey()) + " - " + OperatorUtils.getOpNamePretty(p.getValue()));
      }
      GenTezUtils.removeBranch(p.getKey());
      if (p.getKey() instanceof AppMasterEventOperator) {
        GenTezUtils.removeSemiJoinOperator(procCtx.parseContext, (AppMasterEventOperator) p.getKey(), p.getValue());
      } else if (p.getKey() instanceof ReduceSinkOperator) {
        GenTezUtils.removeSemiJoinOperator(procCtx.parseContext, (ReduceSinkOperator) p.getKey(), p.getValue());
      } else {
        throw new SemanticException("Unexpected error - type for branch could not be recognized");
      }
    }
  }
TezCompiler translates the operator plan into TezTasks.
ql/src/java/org/apache/hadoop/hive/ql/parse/TezCompiler.java