liuhe0702 commented on a change in pull request #4104: URL: https://github.com/apache/carbondata/pull/4104#discussion_r597462970
########## File path: integration/spark/src/main/scala/org/apache/carbondata/spark/rdd/CarbonTableCompactor.scala ########## @@ -296,26 +299,46 @@ class CarbonTableCompactor( if (finalMergeStatus) { val mergedLoadNumber = CarbonDataMergerUtil.getLoadNumberFromLoadName(mergedLoadName) - var segmentFilesForIUDCompact = new util.ArrayList[Segment]() var segmentFileName: String = null + + val isMergeIndexEnabled = CarbonProperties.getInstance().getProperty( + CarbonCommonConstants.CARBON_MERGE_INDEX_IN_SEGMENT, + CarbonCommonConstants.CARBON_MERGE_INDEX_IN_SEGMENT_DEFAULT).toBoolean + + if (compactionType != CompactionType.IUD_DELETE_DELTA && isMergeIndexEnabled) { + MergeIndexUtil.mergeIndexFilesOnCompaction(compactionCallableModel) + } + if (carbonTable.isHivePartitionTable) { - val readPath = - CarbonTablePath.getSegmentFilesLocation(carbonLoadModel.getTablePath) + - CarbonCommonConstants.FILE_SEPARATOR + carbonLoadModel.getFactTimeStamp + ".tmp" - // Merge all partition files into a single file. - segmentFileName = - mergedLoadNumber + "_" + carbonLoadModel.getFactTimeStamp - val segmentFile = SegmentFileStore - .mergeSegmentFiles(readPath, - segmentFileName, - CarbonTablePath.getSegmentFilesLocation(carbonLoadModel.getTablePath)) - if (segmentFile != null) { - SegmentFileStore - .moveFromTempFolder(segmentFile, - carbonLoadModel.getFactTimeStamp + ".tmp", - carbonLoadModel.getTablePath) + if (isMergeIndexEnabled) { + val segmentTmpFileName = carbonLoadModel.getFactTimeStamp + CarbonTablePath.SEGMENT_EXT + segmentFileName = mergedLoadNumber + "_" + segmentTmpFileName + val segmentTmpFile = FileFactory.getCarbonFile( + CarbonTablePath.getSegmentFilePath(carbonTable.getTablePath, segmentTmpFileName)) + if (!segmentTmpFile.renameForce( + CarbonTablePath.getSegmentFilePath(carbonTable.getTablePath, segmentFileName))) { + throw new Exception(s"Rename segment file from ${segmentTmpFileName} " + + s"to ${segmentFileName} failed.") + } + } else { + val readPath = + CarbonTablePath.getSegmentFilesLocation(carbonLoadModel.getTablePath) + + CarbonCommonConstants.FILE_SEPARATOR + carbonLoadModel.getFactTimeStamp + ".tmp" + // Merge all partition files into a single file. + segmentFileName = + mergedLoadNumber + "_" + carbonLoadModel.getFactTimeStamp Review comment: done -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org