private long getMergeSize(List<FileStatus> fileStatuses, long avgSize) {
    FileSummary fileSummary = getFileSummary(fileStatuses);
    if (fileSummary.getTotalSize() <= 0) {
      return -1;
    }

    if (fileSummary.getNumFiles() <= 1) {
      return -1;
    }

    if (fileSummary.getTotalSize() / fileSummary.getNumFiles() < avgSize) {
      return fileSummary.getTotalSize();
    }
    return -1;
  }
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