private void setupWorkWithCustomHandler(MapWork mapWork, Path dirPath,
                                          MergeTaskProperties mergeProperties) throws IOException, ClassNotFoundException {
    Map<String, Operator<? extends OperatorDesc>> aliasToWork = mapWork.getAliasToWork();
    Map<Path, PartitionDesc> pathToPartitionInfo = mapWork.getPathToPartitionInfo();
    Operator<? extends OperatorDesc> op = aliasToWork.get(dirPath.toString());
    PartitionDesc partitionDesc = pathToPartitionInfo.get(dirPath);
    Path tmpDir = mergeProperties.getTmpLocation();
    if (op != null) {
      aliasToWork.remove(dirPath.toString());
      aliasToWork.put(tmpDir.toString(), op);
      mapWork.setAliasToWork(aliasToWork);
    }
    if (partitionDesc != null) {
      pathToPartitionInfo.remove(dirPath);
      pathToPartitionInfo.put(tmpDir, partitionDesc);
      mapWork.setPathToPartitionInfo(pathToPartitionInfo);
    }
    mapWork.setMergeSplitProperties(mergeProperties.getSplitProperties());
    mapWork.removePathToAlias(dirPath);
    mapWork.addPathToAlias(tmpDir, tmpDir.toString());
    mapWork.setUseInputPathsDirectly(true);
  }
Whether to merge files inside directory given the threshold of the average file size.

@param fileStatuses a list of FileStatus instances.
@param avgSize threshold of average file size.
@return -1 if not need to merge (either because of there is only 1 file or the
average size is larger than avgSize). Otherwise the size of the total size of files.
If return value is 0 that means there are multiple files each of which is an empty file.
This could be true when the table is bucketized and all buckets are empty.
ql/src/java/org/apache/hadoop/hive/ql/plan/ConditionalResolverMergeFiles.java