Skip to content

Commit ede2c54

Browse files
committed
getBlockId code clean
1 parent 32c2306 commit ede2c54

2 files changed

Lines changed: 30 additions & 38 deletions

File tree

core/src/main/java/org/apache/carbondata/core/scan/executor/impl/AbstractQueryExecutor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,11 +446,11 @@ private BlockExecutionInfo getBlockExecutionInfoForBlock(QueryModel queryModel,
446446
segmentProperties.getComplexDimensions(),
447447
blockExecutionInfo.getActualQueryMeasures().length,
448448
queryModel.getTable().getTableInfo().isTransactionalTable());
449-
boolean isStandardTable = CarbonUtil.isStandardCarbonTable(queryModel.getTable());
449+
boolean isFlatFolderTable = queryModel.getTable().isSupportFlatFolder();
450450
String blockId = CarbonUtil
451451
.getBlockId(queryModel.getAbsoluteTableIdentifier(), filePath, segment.getSegmentNo(),
452452
queryModel.getTable().getTableInfo().isTransactionalTable(),
453-
isStandardTable, queryModel.getTable().isHivePartitionTable());
453+
isFlatFolderTable, queryModel.getTable().isHivePartitionTable());
454454
blockExecutionInfo.setBlockId(CarbonTablePath.getShortBlockId(blockId));
455455
blockExecutionInfo.setDeleteDeltaFilePath(deleteDeltaFiles);
456456
blockExecutionInfo.setStartBlockletIndex(0);

core/src/main/java/org/apache/carbondata/core/util/CarbonUtil.java

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2759,49 +2759,41 @@ public static String getBlockId(AbsoluteTableIdentifier identifier, String fileP
27592759
* @return
27602760
*/
27612761
public static String getBlockId(AbsoluteTableIdentifier identifier, String filePath,
2762-
String segmentId, boolean isTransactionalTable, boolean isStandardTable,
2762+
String segmentId, boolean isTransactionalTable, boolean isFlatFolderTable,
27632763
boolean isPartitionTable) {
2764-
String blockId;
27652764
String blockName = filePath.substring(filePath.lastIndexOf("/") + 1);
27662765
String tablePath = identifier.getTablePath();
27672766

2768-
if (filePath.startsWith(tablePath)) {
2769-
if (!isTransactionalTable || isStandardTable) {
2770-
blockId = "Part0" + CarbonCommonConstants.FILE_SEPARATOR + "Segment_" + segmentId
2771-
+ CarbonCommonConstants.FILE_SEPARATOR + blockName;
2772-
} else {
2773-
// This is the case with partition table.
2774-
String partitionDir;
2775-
int partLength = filePath.length() - blockName.length() - 1;
2776-
if (tablePath.length() + 1 < partLength) {
2777-
partitionDir =
2778-
filePath.substring(tablePath.length() + 1, partLength);
2779-
} else {
2780-
partitionDir = "";
2781-
}
2782-
if (isPartitionTable) {
2783-
blockId =
2784-
partitionDir.replace(CarbonCommonConstants.FILE_SEPARATOR, "#")
2785-
+ CarbonCommonConstants.FILE_SEPARATOR + blockName;
2786-
} else {
2787-
// Replace / with # on partition director to support multi level partitioning. And access
2788-
// them all as a single entity.
2789-
if (partitionDir.isEmpty()) {
2790-
blockId = segmentId + CarbonCommonConstants.FILE_SEPARATOR + blockName;
2791-
} else {
2792-
blockId = partitionDir.replace(CarbonCommonConstants.FILE_SEPARATOR, "#")
2793-
+ CarbonCommonConstants.FILE_SEPARATOR + segmentId
2794-
+ CarbonCommonConstants.FILE_SEPARATOR + blockName;
2795-
}
2767+
if (!filePath.startsWith(tablePath)) {
2768+
return filePath.substring(0, filePath.length() - blockName.length()).replace("/", "#")
2769+
+ CarbonCommonConstants.FILE_SEPARATOR + segmentId
2770+
+ CarbonCommonConstants.FILE_SEPARATOR + blockName;
2771+
}
27962772

2797-
}
2798-
}
2799-
} else {
2800-
blockId = filePath.substring(0, filePath.length() - blockName.length()).replace("/", "#")
2801-
+ CarbonCommonConstants.FILE_SEPARATOR + "Segment_" + segmentId
2773+
if (!isTransactionalTable || !isPartitionTable) {
2774+
return "0" + CarbonCommonConstants.FILE_SEPARATOR + segmentId
2775+
+ CarbonCommonConstants.FILE_SEPARATOR + blockName;
2776+
}
2777+
2778+
String partitionDir = getPartitionDir(tablePath, filePath, blockName);
2779+
if (isFlatFolderTable) {
2780+
return partitionDir.replace(CarbonCommonConstants.FILE_SEPARATOR, "#")
2781+
+ CarbonCommonConstants.FILE_SEPARATOR + segmentId
28022782
+ CarbonCommonConstants.FILE_SEPARATOR + blockName;
28032783
}
2804-
return blockId;
2784+
2785+
return partitionDir.replace(CarbonCommonConstants.FILE_SEPARATOR, "#")
2786+
+ CarbonCommonConstants.FILE_SEPARATOR + blockName;
2787+
}
2788+
2789+
public static String getPartitionDir(String tablePath, String filePath, String blockName) {
2790+
String partitionDir = "";
2791+
int partLength = filePath.length() - blockName.length() - 1;
2792+
if (tablePath.length() + 1 < partLength) {
2793+
partitionDir =
2794+
filePath.substring(tablePath.length() + 1, partLength);
2795+
}
2796+
return partitionDir;
28052797
}
28062798

28072799
/**

0 commit comments

Comments
 (0)