[refactor](planner) filter empty partitions in a unified location (#27190)
This commit is contained in:
@ -965,6 +965,18 @@ public class OlapTable extends Table {
|
||||
return partition;
|
||||
}
|
||||
|
||||
// select the non-empty partition ids belonging to this table.
|
||||
//
|
||||
// ATTN: partitions not belonging to this table will be filtered.
|
||||
public List<Long> selectNonEmptyPartitionIds(Collection<Long> partitionIds) {
|
||||
return partitionIds.stream()
|
||||
.map(this::getPartition)
|
||||
.filter(p -> p != null)
|
||||
.filter(Partition::hasData)
|
||||
.map(Partition::getId)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public int getPartitionNum() {
|
||||
return idToPartition.size();
|
||||
}
|
||||
|
||||
@ -22,8 +22,6 @@ import org.apache.doris.nereids.rules.Rule;
|
||||
import org.apache.doris.nereids.rules.RuleType;
|
||||
import org.apache.doris.nereids.trees.plans.logical.LogicalOlapScan;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Used to prune empty partition.
|
||||
*/
|
||||
@ -34,9 +32,7 @@ public class PruneEmptyPartition extends OneRewriteRuleFactory {
|
||||
return logicalOlapScan().thenApply(ctx -> {
|
||||
LogicalOlapScan scan = ctx.root;
|
||||
OlapTable table = scan.getTable();
|
||||
return scan.withSelectedPartitionIds(scan.getSelectedPartitionIds().stream()
|
||||
.filter(partitionId -> table.getPartition(partitionId).hasData())
|
||||
.collect(Collectors.toList()));
|
||||
return scan.withSelectedPartitionIds(table.selectNonEmptyPartitionIds(scan.getSelectedPartitionIds()));
|
||||
}).toRule(RuleType.PRUNE_EMPTY_PARTITION);
|
||||
}
|
||||
}
|
||||
|
||||
@ -873,22 +873,9 @@ public class OlapScanNode extends ScanNode {
|
||||
if (partitionInfo.getType() == PartitionType.RANGE || partitionInfo.getType() == PartitionType.LIST) {
|
||||
selectedPartitionIds = partitionPrune(partitionInfo, partitionNames);
|
||||
} else {
|
||||
selectedPartitionIds = null;
|
||||
}
|
||||
|
||||
if (selectedPartitionIds == null) {
|
||||
selectedPartitionIds = Lists.newArrayList();
|
||||
for (Partition partition : olapTable.getPartitions()) {
|
||||
if (!partition.hasData()) {
|
||||
continue;
|
||||
}
|
||||
selectedPartitionIds.add(partition.getId());
|
||||
}
|
||||
} else {
|
||||
selectedPartitionIds = selectedPartitionIds.stream()
|
||||
.filter(id -> olapTable.getPartition(id).hasData())
|
||||
.collect(Collectors.toList());
|
||||
selectedPartitionIds = olapTable.getPartitionIds();
|
||||
}
|
||||
selectedPartitionIds = olapTable.selectNonEmptyPartitionIds(selectedPartitionIds);
|
||||
selectedPartitionNum = selectedPartitionIds.size();
|
||||
|
||||
for (long id : selectedPartitionIds) {
|
||||
|
||||
Reference in New Issue
Block a user