public static boolean isMergeRequired(List<Task<MoveWork>> mvTasks, HiveConf hconf,
      FileSinkOperator fsOp, Task<?> currTask, boolean isInsertTable) {
    // Has the user enabled merging of files for map-only jobs or for all jobs
    if (mvTasks == null  || mvTasks.isEmpty()) {
      return false;
    }

    // no need of merging if the move is to a local file system
    // We are looking based on the original FSOP, so use the original path as is.
    MoveTask mvTask = (MoveTask) GenMapRedUtils.findMoveTaskForFsopOutput(mvTasks, fsOp.getConf().getFinalDirName(),
        fsOp.getConf().isMmTable(), fsOp.getConf().isDirectInsert(), fsOp.getConf().getMoveTaskId(), fsOp.getConf().getAcidOperation());

    // TODO: wtf?!! why is this in this method? This has nothing to do with anything.
    if (isInsertTable && hconf.getBoolVar(ConfVars.HIVE_STATS_AUTOGATHER)
        && !fsOp.getConf().isMaterialization()) {
      // mark the MapredWork and FileSinkOperator for gathering stats
      fsOp.getConf().setGatherStats(true);
      fsOp.getConf().setStatsReliable(hconf.getBoolVar(ConfVars.HIVE_STATS_RELIABLE));
      if (mvTask != null && !mvTask.hasFollowingStatsTask()) {
        GenMapRedUtils.addStatsTask(fsOp, mvTask, currTask, hconf);
      }
    }

    if (mvTask == null || mvTask.isLocal() || !fsOp.getConf().canBeMerged()) {
      return false;
    }

    if (currTask.getWork() instanceof TezWork) {
      // tez blurs the boundary between map and reduce, thus it has it's own config
      return hconf.getBoolVar(ConfVars.HIVE_MERGE_TEZ_FILES);
    }
    return isMergeRequiredForMr(hconf, fsOp, currTask);
  }
Returns true iff the fsOp requires a merge
ql/src/java/org/apache/hadoop/hive/ql/optimizer/GenMapRedUtils.java