[fix](nereids) select with specified partition name is not work as expected (#20269)

This PR is to fix the select specific partition issue, certain codes related to this feature were accidentally deleted.
This commit is contained in:
AKIRA
2023-06-05 13:48:54 +09:00
committed by GitHub
parent d03bb4ba7b
commit cd0379df4e
3 changed files with 42 additions and 4 deletions

View File

@ -28,6 +28,10 @@ import org.apache.doris.nereids.trees.plans.logical.LogicalFilter;
import org.apache.doris.nereids.trees.plans.logical.LogicalOlapScan;
import org.apache.doris.nereids.util.Utils;
import com.google.common.collect.ImmutableList;
import org.apache.commons.collections.CollectionUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -61,10 +65,13 @@ public class PruneOlapScanPartition extends OneRewriteRuleFactory {
.map(column -> scanOutput.get(column.getName().toLowerCase()))
.collect(Collectors.toList());
List<Long> prunedPartitions = PartitionPruner.prune(
partitionSlots, filter.getPredicate(), partitionInfo, ctx.cascadesContext);
LogicalOlapScan rewrittenScan = scan.withSelectedPartitionIds(prunedPartitions);
List<Long> prunedPartitions = new ArrayList<>(PartitionPruner.prune(
partitionSlots, filter.getPredicate(), partitionInfo, ctx.cascadesContext));
List<Long> manuallySpecifiedPartitions = scan.getManuallySpecifiedPartitions();
if (!CollectionUtils.isEmpty(manuallySpecifiedPartitions)) {
prunedPartitions.retainAll(manuallySpecifiedPartitions);
}
LogicalOlapScan rewrittenScan = scan.withSelectedPartitionIds(ImmutableList.copyOf(prunedPartitions));
return new LogicalFilter<>(filter.getConjuncts(), rewrittenScan);
}).toRule(RuleType.OLAP_SCAN_PARTITION_PRUNE);
}

View File

@ -21,3 +21,6 @@
-- !sql --
16 1234 t
-- !sql --
1 aaa aaa

View File

@ -60,4 +60,32 @@ suite("query_on_specific_partition") {
qt_sql """select * from t_p temporary partitions(tp1);"""
qt_sql """select * from t_p temporary partition tp1;"""
sql """
CREATE TABLE IF NOT EXISTS test_iot (
`test_int` int NOT NULL,
`test_varchar` varchar(150) NULL,
`test_text` text NULL
) ENGINE=OLAP
UNIQUE KEY(`test_int`)
PARTITION BY LIST (`test_int`)
(
PARTITION p1 VALUES IN ("1","2","3"),
PARTITION p2 VALUES IN ("4","5","6")
)
DISTRIBUTED BY HASH(`test_int`) BUCKETS 3
PROPERTIES (
"replication_allocation" = "tag.location.default: 1",
"in_memory" = "false",
"storage_format" = "V2"
)
"""
sql """
INSERT INTO test_iot VALUES(1,'aaa','aaa'),(4,'ccc','ccc');
"""
qt_sql """
SELECT * FROM test_iot PARTITION p1;
"""
}