kaka11chen commented on code in PR #45251:
URL: https://github.com/apache/doris/pull/45251#discussion_r1881666585
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PruneFileScanPartition.java:
##########
@@ -91,13 +119,87 @@ private SelectedPartitions
pruneHivePartitions(HMSExternalTable hiveTbl,
.map(column -> scanOutput.get(column.getName().toLowerCase()))
.collect(Collectors.toList());
- Map<Long, PartitionItem> idToPartitionItem =
scan.getSelectedPartitions().selectedPartitions;
- List<Long> prunedPartitions = new ArrayList<>(PartitionPruner.prune(
- partitionSlots, filter.getPredicate(), idToPartitionItem, ctx,
PartitionTableType.HIVE));
+ HiveMetaStoreCache cache = Env.getCurrentEnv().getExtMetaCacheMgr()
+ .getMetaStoreCache((HMSExternalCatalog) hiveTbl.getCatalog());
+ int partitionNum = cache.getPartitionNum(hiveTbl.getDbName(),
hiveTbl.getName());
+ boolean isDirectlyByFilter = partitionNum >
Config.max_partition_num_for_single_hive_table_without_filter;
+ Expression partitionPredicate = null;
+ // use listPartitionsByFilter
+ if (isDirectlyByFilter) {
+ try {
+ partitionPredicate =
PartitionPruneExpressionExtractor.extract(filter.getPredicate(),
+ ImmutableSet.copyOf(partitionSlots), ctx);
+ List<String> partitionColumnNames =
partitionSlots.stream().map(e -> e.getName())
+ .collect(Collectors.toList());
+ partitionPredicate =
PredicateRewriteForPartitionPrune.rewrite(partitionPredicate, ctx);
+ partitionPredicate =
PredicateRewriteForPartitionFilter.rewrite(partitionPredicate, ctx);
+ if (BooleanLiteral.TRUE.equals(partitionPredicate)) {
+ HiveMetaStoreCache.HivePartitionValues hivePartitionValues
= cache.getPartitionValues(
+ hiveTbl.getDbName(), hiveTbl.getName(),
hiveTbl.getPartitionColumnTypes());
+ selectedPartitionItems =
hivePartitionValues.getIdToPartitionItem();
+ } else if (BooleanLiteral.FALSE.equals(partitionPredicate) ||
partitionPredicate.isNullLiteral()) {
+ // do nothing
+ } else {
+ selectedPartitionItems =
cache.getPartitionValuesByFilter(hiveTbl.getDbName(), hiveTbl.getName(),
+ partitionPredicate.toSql(), partitionColumnNames,
hiveTbl.getPartitionColumnTypes());
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("prune Partitions use
getPartitionValuesByFilter "
+ + "selected partitions num #{} for table:
{}.{}", selectedPartitionItems.size(),
+ hiveTbl.getDbName(), hiveTbl.getName());
+ }
+ }
+ } catch (Exception e) {
+ // for some complex case listPartitionsByFilter may not support
+ LOG.warn("get selected partition items by
listPartitionsByFilter failed, filter sql is "
+ + partitionPredicate.toSql() + ", use
getPartitionValues instead");
+ isDirectlyByFilter = false;
+ }
+ }
+ if (!isDirectlyByFilter) {
Review Comment:
Why not use original source codeļ¼
```
List<String> prunedPartitions = new
ArrayList<>(PartitionPruner.prune(
partitionSlots, filter.getPredicate(), nameToPartitionItem,
ctx, PartitionTableType.EXTERNAL));
```
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]