private static boolean isMergeRequiredForMr(HiveConf hconf,
      FileSinkOperator fsOp, Task<?> currTask) {
    if (fsOp.getConf().isLinkedFileSink()) {
      // If the user has HIVE_MERGE_MAPRED_FILES set to false, the idea was the
      // number of reducers are few, so the number of files anyway are small.
      // However, with this optimization, we are increasing the number of files
      // possibly by a big margin. So, merge aggressively.
      return (hconf.getBoolVar(ConfVars.HIVE_MERGE_MAPFILES) ||
          hconf.getBoolVar(ConfVars.HIVE_MERGE_MAPRED_FILES));
    }
    // There are separate configuration parameters to control whether to
    // merge for a map-only job
    // or for a map-reduce job
    if (currTask.getWork() instanceof MapredWork) {
      ReduceWork reduceWork = ((MapredWork) currTask.getWork()).getReduceWork();
      boolean mergeMapOnly =
        hconf.getBoolVar(ConfVars.HIVE_MERGE_MAPFILES) && reduceWork == null;
      boolean mergeMapRed =
        hconf.getBoolVar(ConfVars.HIVE_MERGE_MAPRED_FILES) &&
        reduceWork != null;
      if (mergeMapOnly || mergeMapRed) {
        return true;
      }
    }
    return false;
  }
Returns true iff the fsOp requires a merge
ql/src/java/org/apache/hadoop/hive/ql/optimizer/GenMapRedUtils.java