Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CARBONDATA-4046] Handled multiple partition columns for partition cache #4002

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,10 @@ object PartitionCacheManager extends Cache[PartitionCacheKey,
segmentFilePath.getAbsolutePath), segmentFileModifiedTime))
}
}.toMap
val invalidSegmentMap = validInvalidSegments.getInvalidSegments.asScala
.map(seg => (seg.getSegmentNo, seg)).toMap
// remove all invalid segment entries from cache
val finalCache = cacheablePartitionSpecs --
validInvalidSegments.getInvalidSegments.asScala.map(_.getSegmentNo)
val finalCache = cacheablePartitionSpecs -- invalidSegmentMap.keySet
val cacheObject = CacheablePartitionSpec(finalCache)
if (finalCache.nonEmpty) {
// remove the existing cache as new cache values may be added.
Expand All @@ -92,6 +93,8 @@ object PartitionCacheManager extends Cache[PartitionCacheKey,
cacheObject,
cacheObject.getMemorySize,
identifier.expirationTime)
} else if (invalidSegmentMap != null && invalidSegmentMap.nonEmpty) {
CACHE.remove(identifier.tableId)
}
finalCache.values.flatMap(_._1).toList.asJava
}
Expand All @@ -112,14 +115,18 @@ object PartitionCacheManager extends Cache[PartitionCacheKey,

private def readPartition(identifier: PartitionCacheKey, segmentFilePath: String) = {
val segmentFile = SegmentFileStore.readSegmentFile(segmentFilePath)
val partitionPath = new mutable.StringBuilder()
var partitionSpec: Map[String, String] = Map()
segmentFile.getLocationMap.values().asScala
.flatMap(_.getPartitions.asScala).toSet.map { uniquePartition: String =>
.flatMap(_.getPartitions.asScala).toSet.foreach { uniquePartition: String =>
partitionPath.append(CarbonCommonConstants.FILE_SEPARATOR).append(uniquePartition)
val partitionSplit = uniquePartition.split("=")
val storageFormat = CatalogStorageFormat(
Some(new URI(identifier.tablePath + "/" + uniquePartition)),
None, None, None, compressed = false, Map())
CatalogTablePartition(Map(partitionSplit(0) -> partitionSplit(1)), storageFormat)
}.toSeq
partitionSpec = partitionSpec. +(partitionSplit(0) -> partitionSplit(1))
}
Seq(CatalogTablePartition(partitionSpec,
CatalogStorageFormat(
Some(new URI(identifier.tablePath + partitionPath)),
None, None, None, compressed = false, Map())))
}

override def put(key: PartitionCacheKey,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,21 @@ class StandardPartitionTableLoadingTestCase extends QueryTest with BeforeAndAfte
CarbonProperties.getInstance().addProperty("carbon.read.partition.hive.direct", "true")
}

test("test partition cache on multiple columns") {
CarbonProperties.getInstance().addProperty("carbon.read.partition.hive.direct", "false")
sql("drop table if exists partition_cache")
sql("create table partition_cache(a string) partitioned by(b int, c String) stored as carbondata")
sql("insert into partition_cache select 'k',1,'nihal'")
checkAnswer(sql("select count(*) from partition_cache where b = 1"), Seq(Row(1)))
sql("select * from partition_cache where b = 1").collect()
val carbonTable = CarbonMetadata.getInstance().getCarbonTable("default", "partition_cache")
val partitionSpecs: util.List[CatalogTablePartition] = PartitionCacheManager.getIfPresent(
PartitionCacheKey(carbonTable.getTableId, carbonTable.getTablePath, 1L))
assert(partitionSpecs.size == 1)
assert(partitionSpecs.get(0).spec.size == 2)
CarbonProperties.getInstance().addProperty("carbon.read.partition.hive.direct", "true")
}

test("test partition caching after load") {
CarbonProperties.getInstance().addProperty("carbon.read.partition.hive.direct", "false")
sql("drop table if exists partition_cache")
Expand Down