private boolean mergeFiles(HiveConf conf, boolean includeBaseDir, AcidDirectory dir,
                               Path outputDirPath, boolean isMm) throws IOException {
    Map<Integer, List<Reader>> bucketIdToBucketFiles = matchBucketIdToBucketFiles(conf, dir, includeBaseDir, isMm);
    OrcFileMerger fileMerger = new OrcFileMerger(conf);
    boolean isCompatible = bucketIdToBucketFiles.values().stream().allMatch(fileMerger::checkCompatibility);
    if (isCompatible) {
      for (Map.Entry<Integer, List<Reader>> e : bucketIdToBucketFiles.entrySet()) {
        Path path = isMm ? new Path(outputDirPath, String.format(AcidUtils.LEGACY_FILE_BUCKET_DIGITS,
                e.getKey()) + "_0") : new Path(outputDirPath, AcidUtils.BUCKET_PREFIX + String.format(AcidUtils.BUCKET_DIGITS,
                e.getKey()));
        fileMerger.mergeFiles(e.getValue(), path);
      }
      return true;
    } else {
      return false;
    }
  }
Merge files from base/delta directories. If the directories contains multiple buckets, the result will also
contain the same amount.
@param conf hive configuration
@param includeBaseDir if base directory should be scanned for orc files
@param dir the root directory of the table/partition
@param outputDirPath the result directory path
@param isMm merge orc files from insert only tables
@throws IOException error occurred during file operation
ql/src/java/org/apache/hadoop/hive/ql/txn/compactor/MergeCompactor.java