From f81d087bab7f4f9bdb166cf515ffead37fd815e5 Mon Sep 17 00:00:00 2001 From: zhangdong <493738387@qq.com> Date: Thu, 19 Sep 2024 22:47:50 +0800 Subject: [PATCH] [enhance](mtmv)Improve the speed of obtaining table snapshots (#40717) (#40995) pick: https://github.com/apache/doris/pull/40717 --- .../datasource/hive/HMSExternalTable.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/datasource/hive/HMSExternalTable.java b/fe/fe-core/src/main/java/org/apache/doris/datasource/hive/HMSExternalTable.java index 4b87f938da..5207095327 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/datasource/hive/HMSExternalTable.java +++ b/fe/fe-core/src/main/java/org/apache/doris/datasource/hive/HMSExternalTable.java @@ -761,26 +761,26 @@ public class HMSExternalTable extends ExternalTable implements MTMVRelatedTableI if (getPartitionType() == PartitionType.UNPARTITIONED) { return new MTMVMaxTimestampSnapshot(getName(), getLastDdlTime()); } - Long maxPartitionId = 0L; + HivePartition maxPartition = null; long maxVersionTime = 0L; long visibleVersionTime; HiveMetaStoreCache cache = Env.getCurrentEnv().getExtMetaCacheMgr() .getMetaStoreCache((HMSExternalCatalog) getCatalog()); HiveMetaStoreCache.HivePartitionValues hivePartitionValues = cache.getPartitionValues( getDbName(), getName(), getPartitionColumnTypes()); - BiMap idToName = hivePartitionValues.getPartitionNameToIdMap().inverse(); - if (MapUtils.isEmpty(idToName)) { - throw new AnalysisException("partitions is empty for : " + getName()); + List partitionList = cache.getAllPartitionsWithCache(getDbName(), getName(), + Lists.newArrayList(hivePartitionValues.getPartitionValuesMap().values())); + if (CollectionUtils.isEmpty(partitionList)) { + throw new AnalysisException("partitionList is empty, table name: " + getName()); } - for (Long partitionId : idToName.keySet()) { - visibleVersionTime = getHivePartitionByIdOrAnalysisException(partitionId, hivePartitionValues, - cache).getLastModifiedTime(); + for (HivePartition hivePartition : partitionList) { + visibleVersionTime = hivePartition.getLastModifiedTime(); if (visibleVersionTime > maxVersionTime) { maxVersionTime = visibleVersionTime; - maxPartitionId = partitionId; + maxPartition = hivePartition; } } - return new MTMVMaxTimestampSnapshot(idToName.get(maxPartitionId), maxVersionTime); + return new MTMVMaxTimestampSnapshot(maxPartition.getPartitionName(getPartitionColumns()), maxVersionTime); } private Long getPartitionIdByNameOrAnalysisException(String partitionName,