private Map<FileStatus, List<FileStatus>> getParentDirToFileMap(FileSystem inpFs, List<FileStatus> fileStatuses)
      throws IOException {
    Map<FileStatus, List<FileStatus>> manifestDirsToPaths = new HashMap<>();
    for (FileStatus fileStatus : fileStatuses) {
      if (!fileStatus.isDirectory()) {
        FileStatus parentDir = inpFs.getFileStatus(fileStatus.getPath().getParent());
        List<FileStatus> fileStatusList = Lists.newArrayList(fileStatus);
        manifestDirsToPaths.merge(parentDir, fileStatusList, (oldValue, newValue) -> {
          oldValue.addAll(newValue);
          return oldValue;
        });
      }
    }
    return manifestDirsToPaths;
  }
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