vikramahuja1001 commented on a change in pull request #3917: URL: https://github.com/apache/carbondata/pull/3917#discussion_r503370601
########## File path: core/src/main/java/org/apache/carbondata/core/metadata/SegmentFileStore.java ########## @@ -1106,23 +1107,55 @@ public static void cleanSegments(CarbonTable table, List<PartitionSpec> partitio */ public static void deleteSegment(String tablePath, Segment segment, List<PartitionSpec> partitionSpecs, - SegmentUpdateStatusManager updateStatusManager) throws Exception { + SegmentUpdateStatusManager updateStatusManager, String tableName, String DatabaseName, + SegmentStatus segmentStatus, Boolean isPartitionTable) + throws Exception { SegmentFileStore fileStore = new SegmentFileStore(tablePath, segment.getSegmentFileName()); - List<String> indexOrMergeFiles = fileStore.readIndexFiles(SegmentStatus.SUCCESS, true, - FileFactory.getConfiguration()); + List<String> indexOrMergeFiles = fileStore.readIndexFiles(SegmentStatus.SUCCESS, + true, FileFactory.getConfiguration()); Map<String, List<String>> indexFilesMap = fileStore.getIndexFilesMap(); for (Map.Entry<String, List<String>> entry : indexFilesMap.entrySet()) { + // If the file to be deleted is a carbondata file, copy that file to the trash folder. + if (segmentStatus == SegmentStatus.INSERT_IN_PROGRESS) { + if (!isPartitionTable) { + TrashUtil.copyDataToTrashFolder(tablePath, entry.getKey(), CarbonCommonConstants + .LOAD_FOLDER + segment.getSegmentNo()); + } else { + TrashUtil.copyDataToTrashFolder(tablePath, entry.getKey(), CarbonCommonConstants + .LOAD_FOLDER + segment.getSegmentNo() + CarbonCommonConstants.FILE_SEPARATOR + + entry.getKey().substring(tablePath.length() + 1, entry.getKey().length())); + } + } FileFactory.deleteFile(entry.getKey()); for (String file : entry.getValue()) { String[] deltaFilePaths = updateStatusManager.getDeleteDeltaFilePath(file, segment.getSegmentNo()); for (String deltaFilePath : deltaFilePaths) { + // If the file to be deleted is a carbondata file, copy that file to the trash folder. + if (segmentStatus == SegmentStatus + .INSERT_IN_PROGRESS) { + TrashUtil.copyDataToTrashFolder(tablePath, deltaFilePath, deltaFilePath + .substring(tablePath.length() + 1, deltaFilePath.length())); + } FileFactory.deleteFile(deltaFilePath); } + // If the file to be deleted is a carbondata file, copy that file to the trash folder. + if (file.endsWith(CarbonCommonConstants.FACT_FILE_EXT) && segmentStatus == + SegmentStatus.INSERT_IN_PROGRESS) { Review comment: the indexfile map will contain both the index files as well as the .carbondata file. `file` is entry.getValue and entry is indexfileMap which also has the carbondata file in it. So, we can have places where this condition will be true ---------------------------------------------------------------- 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