Skip to content

Commit ef57e03

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

6 files changed

Lines changed: 75 additions & 113 deletions

File tree

core/src/main/java/org/apache/carbondata/core/indexstore/blockletindex/BlockIndex.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
import org.apache.carbondata.core.scan.filter.resolver.FilterResolverIntf;
6464
import org.apache.carbondata.core.util.BlockletIndexUtil;
6565
import org.apache.carbondata.core.util.ByteUtil;
66-
import org.apache.carbondata.core.util.CarbonUtil;
6766
import org.apache.carbondata.core.util.DataFileFooterConverter;
6867
import org.apache.carbondata.core.util.path.CarbonTablePath;
6968

@@ -797,8 +796,8 @@ private boolean addBlockBasedOnMinMaxValue(FilterExecutor filterExecutor, byte[]
797796
// replaced with '#', to support multi level partitioning. For example, BlockId will be
798797
// look like `part1=1#part2=2/xxxxxxxxx`. During query also, blockId should be
799798
// replaced by '#' in place of '/', to match and prune data on SI table.
800-
uniqueBlockPath = CarbonUtil
801-
.getBlockId(carbonTable.getAbsoluteTableIdentifier(), filePath, "", true, false, true);
799+
uniqueBlockPath = CarbonTablePath
800+
.getBlockId(carbonTable.getAbsoluteTableIdentifier(), filePath, "", true);
802801
} else {
803802
uniqueBlockPath = filePath.substring(filePath.lastIndexOf("/Part") + 1);
804803
}

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -446,11 +446,9 @@ private BlockExecutionInfo getBlockExecutionInfoForBlock(QueryModel queryModel,
446446
segmentProperties.getComplexDimensions(),
447447
blockExecutionInfo.getActualQueryMeasures().length,
448448
queryModel.getTable().getTableInfo().isTransactionalTable());
449-
boolean isStandardTable = CarbonUtil.isStandardCarbonTable(queryModel.getTable());
450-
String blockId = CarbonUtil
449+
String blockId = CarbonTablePath
451450
.getBlockId(queryModel.getAbsoluteTableIdentifier(), filePath, segment.getSegmentNo(),
452-
queryModel.getTable().getTableInfo().isTransactionalTable(),
453-
isStandardTable, queryModel.getTable().isHivePartitionTable());
451+
queryModel.getTable().isHivePartitionTable());
454452
blockExecutionInfo.setBlockId(CarbonTablePath.getShortBlockId(blockId));
455453
blockExecutionInfo.setDeleteDeltaFilePath(deleteDeltaFiles);
456454
blockExecutionInfo.setStartBlockletIndex(0);

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

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -2737,72 +2737,6 @@ private static long getMaxOfBlockAndFileSize(long blockSize, long fileSize) {
27372737
return maxSize;
27382738
}
27392739

2740-
/**
2741-
* Generate the blockId as per the block path
2742-
*
2743-
* @param identifier
2744-
* @param filePath
2745-
* @param segmentId
2746-
* @param isTransactionalTable
2747-
* @param isStandardTable
2748-
* @return
2749-
*/
2750-
public static String getBlockId(AbsoluteTableIdentifier identifier, String filePath,
2751-
String segmentId, boolean isTransactionalTable, boolean isStandardTable) {
2752-
return getBlockId(identifier, filePath, segmentId, isTransactionalTable, isStandardTable,
2753-
false);
2754-
}
2755-
2756-
/**
2757-
* Generate the blockId as per the block path
2758-
*
2759-
* @return
2760-
*/
2761-
public static String getBlockId(AbsoluteTableIdentifier identifier, String filePath,
2762-
String segmentId, boolean isTransactionalTable, boolean isStandardTable,
2763-
boolean isPartitionTable) {
2764-
String blockId;
2765-
String blockName = filePath.substring(filePath.lastIndexOf("/") + 1);
2766-
String tablePath = identifier.getTablePath();
2767-
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-
}
2796-
2797-
}
2798-
}
2799-
} else {
2800-
blockId = filePath.substring(0, filePath.length() - blockName.length()).replace("/", "#")
2801-
+ CarbonCommonConstants.FILE_SEPARATOR + "Segment_" + segmentId
2802-
+ CarbonCommonConstants.FILE_SEPARATOR + blockName;
2803-
}
2804-
return blockId;
2805-
}
28062740

28072741
/**
28082742
* sets the local dictionary columns to wrapper schema, if the table property

core/src/main/java/org/apache/carbondata/core/util/path/CarbonTablePath.java

Lines changed: 64 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.apache.carbondata.core.datastore.filesystem.CarbonFileFilter;
2626
import org.apache.carbondata.core.datastore.impl.FileFactory;
2727
import org.apache.carbondata.core.locks.LockUsage;
28+
import org.apache.carbondata.core.metadata.AbsoluteTableIdentifier;
2829
import org.apache.carbondata.core.metadata.ColumnarFormatVersion;
2930

3031
import static org.apache.carbondata.core.constants.CarbonCommonConstants.DASH;
@@ -635,42 +636,76 @@ public static String getCarbonMergeIndexExtension() {
635636
return MERGE_INDEX_FILE_EXT;
636637
}
637638

639+
/**
640+
* Generate the blockId as per the block path
641+
*
642+
* @param identifier
643+
* @param filePath
644+
* @param segmentId
645+
* @param isPartitionTable
646+
* @return blockid, which is the identify of a block
647+
*/
648+
public static String getBlockId(AbsoluteTableIdentifier identifier, String filePath,
649+
String segmentId, boolean isPartitionTable) {
650+
String blockName = filePath.substring(filePath.lastIndexOf(
651+
CarbonCommonConstants.FILE_SEPARATOR) + 1);
652+
String tablePath = identifier.getTablePath();
653+
654+
String partitionDir = "";
655+
// 1. For block of Added Segments, The BlockId consistsof
656+
// <partitionPath><segmentId><blockName>
657+
if (!filePath.startsWith(tablePath)) {
658+
partitionDir = getPartitionDir(tablePath, filePath, blockName);
659+
return partitionDir.replace(CarbonCommonConstants.FILE_SEPARATOR, "#")
660+
+ CarbonCommonConstants.FILE_SEPARATOR + segmentId
661+
+ CarbonCommonConstants.FILE_SEPARATOR + blockName;
662+
}
663+
664+
// 2. For block of partitiontable, The BlockId consistsof
665+
// <partitionPath><blockName>
666+
if (isPartitionTable) {
667+
partitionDir = getPartitionDir(tablePath, filePath, blockName);
668+
return partitionDir.replace(CarbonCommonConstants.FILE_SEPARATOR, "#")
669+
+ CarbonCommonConstants.FILE_SEPARATOR + blockName;
670+
}
671+
672+
// 3. For nonpartitiontable, The BlockId consistsof
673+
// <segmentId><blockName>
674+
return segmentId + CarbonCommonConstants.FILE_SEPARATOR + blockName;
675+
}
676+
677+
/**
678+
* get the partition path in the block path
679+
*
680+
* @param tablePath
681+
* @param filePath
682+
* @param blockName
683+
* @return blockid, which is the identify of a block
684+
*/
685+
public static String getPartitionDir(String tablePath, String filePath, String blockName) {
686+
// The filepath is consist with <tablePath><partitionPath><blockName>
687+
// The partitionPath is the string truncated between tablePath and blockName
688+
if (!filePath.startsWith(tablePath)) {
689+
return filePath.substring(0, filePath.length() - blockName.length());
690+
}
691+
return filePath.substring(tablePath.length() + 1, filePath.length() - blockName.length() - 1);
692+
}
693+
694+
638695
/**
639696
* This method will remove strings in path and return short block id
640697
*
641698
* @param blockId
642699
* @return shortBlockId
643700
*/
644701
public static String getShortBlockId(String blockId) {
645-
String blockIdWithCompressorName =
646-
blockId.replace(PARTITION_PREFIX + "0" + CarbonCommonConstants.FILE_SEPARATOR, "")
647-
.replace(SEGMENT_PREFIX, "").replace(BATCH_PREFIX, CarbonCommonConstants.UNDERSCORE)
648-
.replace(DATA_PART_PREFIX, "").replace(CARBON_DATA_EXT, "");
649-
// to remove compressor name
650-
if (!blockId.equalsIgnoreCase(blockIdWithCompressorName)) {
651-
int index = blockIdWithCompressorName.lastIndexOf(POINT);
652-
int fileSeperatorIndex = blockIdWithCompressorName.lastIndexOf(File.separator);
653-
if (index != -1) {
654-
String modifiedBlockId;
655-
if (index > fileSeperatorIndex) {
656-
// Default case when path ends with compressor name.
657-
// Example: 0/0-0_0-0-0-1600789595862.snappy
658-
modifiedBlockId =
659-
blockIdWithCompressorName.replace(blockIdWithCompressorName.substring(index), "");
660-
} else {
661-
// in case of CACHE_LEVEL = BLOCKLET, blockId path contains both block id and blocklet id
662-
// so check for next file seperator and remove compressor name.
663-
// Example: 0/0-0_0-0-0-1600789595862.snappy/0
664-
modifiedBlockId = blockIdWithCompressorName
665-
.replace(blockIdWithCompressorName.substring(index, fileSeperatorIndex), "");
666-
}
667-
return modifiedBlockId;
668-
} else {
669-
return blockIdWithCompressorName;
670-
}
671-
} else {
672-
return blockIdWithCompressorName;
673-
}
702+
String fileName = blockId.substring(0, blockId.lastIndexOf(CARBON_DATA_EXT))
703+
.substring(blockId.lastIndexOf(CarbonCommonConstants.FILE_SEPARATOR) + 1);
704+
String compressorName = fileName.substring(fileName.lastIndexOf(POINT));
705+
return blockId.replace(BATCH_PREFIX, CarbonCommonConstants.UNDERSCORE)
706+
.replace(DATA_PART_PREFIX, "")
707+
.replace(CARBON_DATA_EXT, "")
708+
.replace(compressorName, "");
674709
}
675710

676711
/**

integration/spark/src/test/scala/org/apache/carbondata/spark/testsuite/iud/DeleteCarbonTableTestCase.scala

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -288,21 +288,17 @@ class DeleteCarbonTableTestCase extends QueryTest with BeforeAndAfterAll {
288288

289289
val carbonDataFilename = new File(carbonTable.getTablePath + "/Fact/Part0/Segment_0/")
290290
.listFiles().filter(fn => fn.getName.endsWith(".carbondata"))
291-
val blockId = CarbonUtil.getBlockId(carbonTable.getAbsoluteTableIdentifier,
291+
val blockId = CarbonTablePath.getBlockId(carbonTable.getAbsoluteTableIdentifier,
292292
carbonDataFilename(0).getAbsolutePath,
293-
"0",
294-
carbonTable.isTransactionalTable,
295-
CarbonUtil.isStandardCarbonTable(carbonTable))
293+
"0", false)
296294

297-
assert(blockId.startsWith("Part0/Segment_0/part-0-0_batchno0-0-0-"))
295+
assert(blockId.startsWith("0/part-0-0_batchno0-0-0-"))
298296
val carbonDataFilename_part = new File(carbonTable_part.getTablePath + "/c3=aa").listFiles()
299297
.filter(fn => fn.getName.endsWith(".carbondata"))
300-
val blockId_part = CarbonUtil.getBlockId(carbonTable.getAbsoluteTableIdentifier,
298+
val blockId_part = CarbonTablePath.getBlockId(carbonTable.getAbsoluteTableIdentifier,
301299
carbonDataFilename_part(0).getAbsolutePath,
302-
"0",
303-
carbonTable.isTransactionalTable,
304-
CarbonUtil.isStandardCarbonTable(carbonTable))
305-
assert(blockId_part.startsWith("Part0/Segment_0/part-0-100100000100001_batchno0-0-0-"))
300+
"0", false)
301+
assert(blockId_part.startsWith("0/part-0-100100000100001_batchno0-0-0-"))
306302
val tableBlockPath = CarbonUpdateUtil
307303
.getTableBlockPath(listOfTupleId(0),
308304
carbonTable.getTablePath,

integration/spark/src/test/scala/org/apache/carbondata/spark/testsuite/iud/UpdateCarbonTableTestCase.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,7 @@ class UpdateCarbonTableTestCase extends QueryTest with BeforeAndAfterAll {
10241024
}
10251025

10261026
test("check data after update with row.filter pushdown as false") {
1027-
sql("""drop table if exists iud.dest33_flat""")
1027+
sql("""drop table if exists iud.dest33_part""")
10281028
sql(
10291029
"""create table iud.dest33_part (c1 int,c2 string, c3 short) STORED AS carbondata"""
10301030
.stripMargin)

0 commit comments

Comments
 (0)