Skip to content

Commit 10a5f0e

Browse files
[BugFix] fix npe of remove partition predicte (backport #50762) (#50768)
Co-authored-by: Murphy <[email protected]>
1 parent 8d5ebb0 commit 10a5f0e

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

fe/fe-core/src/main/java/com/starrocks/sql/optimizer/statistics/StatisticsCalculator.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1623,9 +1623,9 @@ public Void visitPhysicalNoCTE(PhysicalNoCTEOperator node, ExpressionContext con
16231623
// avoid use partition cols filter rows twice
16241624
@VisibleForTesting
16251625
public ScalarOperator removePartitionPredicate(ScalarOperator predicate, Operator operator,
1626-
OptimizerContext optimizerContext) {
1626+
OptimizerContext optimizerContext) {
16271627
boolean isTableTypeSupported = operator instanceof LogicalIcebergScanOperator ||
1628-
isOlapScanListPartitionTable(operator);
1628+
isOlapScanListPartitionTable(operator);
16291629
if (isTableTypeSupported && !optimizerContext.isObtainedFromInternalStatistics()) {
16301630
LogicalScanOperator scanOperator = operator.cast();
16311631
List<String> partitionColNames = scanOperator.getTable().getPartitionColumnNames();
@@ -1634,8 +1634,8 @@ public ScalarOperator removePartitionPredicate(ScalarOperator predicate, Operato
16341634
List<ScalarOperator> conjuncts = Utils.extractConjuncts(predicate);
16351635
List<ScalarOperator> newPredicates = Lists.newArrayList();
16361636
for (ScalarOperator scalarOperator : conjuncts) {
1637-
boolean isPartitionCol = isPartitionCol(scalarOperator.getChild(0), partitionColNames);
1638-
if (isPartitionCol && ListPartitionPruner.canPruneWithConjunct(scalarOperator)) {
1637+
if (ListPartitionPruner.canPruneWithConjunct(scalarOperator) &&
1638+
isPartitionCol(scalarOperator.getChild(0), partitionColNames)) {
16391639
// drop this predicate
16401640
} else {
16411641
newPredicates.add(scalarOperator);

fe/fe-core/src/test/java/com/starrocks/sql/plan/PartitionPruneTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ public static void beforeClass() throws Exception {
7878
starRocksAssert.ddl("ALTER TABLE t_gen_col ADD PARTITION p2_202402 VALUES IN (('2', '2024-02-01'))");
7979
starRocksAssert.ddl("ALTER TABLE t_gen_col ADD PARTITION p2_202403 VALUES IN (('2', '2024-03-01'))");
8080

81+
starRocksAssert.withTable("CREATE TABLE t_bool_partition (" +
82+
" c1 datetime NOT NULL, " +
83+
" c2 boolean" +
84+
" ) " +
85+
" PARTITION BY (c1, c2) " +
86+
" PROPERTIES('replication_num'='1')");
87+
8188
// year(c1)
8289
starRocksAssert.withTable("CREATE TABLE t_gen_col_1 (" +
8390
" c1 datetime NOT NULL," +
@@ -232,6 +239,10 @@ public void testGeneratedColumnPrune_RemovePredicate() throws Exception {
232239
testRemovePredicate("select * from t_gen_col where c2 in (1, 2,3)", "true");
233240
testRemovePredicate("select * from t_gen_col where c2 = cast('123' as int)", "true");
234241

242+
// bool partition column
243+
testRemovePredicate("select * from t_bool_partition where c2=true", "2: c2");
244+
testRemovePredicate("select * from t_bool_partition where c2=false", "true");
245+
235246
// can not be removed
236247
testRemovePredicate("select * from t_gen_col where c1 = random() and c2 > 100",
237248
"cast(1: c1 as double) = random(1)");

0 commit comments

Comments
 (0)