Skip to content

Commit

Permalink
[BugFix] fix npe of remove partition predicte (backport #50762) (#50768)
Browse files Browse the repository at this point in the history
Co-authored-by: Murphy <[email protected]>
  • Loading branch information
mergify[bot] and murphyatwork authored Sep 5, 2024
1 parent 8d5ebb0 commit 10a5f0e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1623,9 +1623,9 @@ public Void visitPhysicalNoCTE(PhysicalNoCTEOperator node, ExpressionContext con
// avoid use partition cols filter rows twice
@VisibleForTesting
public ScalarOperator removePartitionPredicate(ScalarOperator predicate, Operator operator,
OptimizerContext optimizerContext) {
OptimizerContext optimizerContext) {
boolean isTableTypeSupported = operator instanceof LogicalIcebergScanOperator ||
isOlapScanListPartitionTable(operator);
isOlapScanListPartitionTable(operator);
if (isTableTypeSupported && !optimizerContext.isObtainedFromInternalStatistics()) {
LogicalScanOperator scanOperator = operator.cast();
List<String> partitionColNames = scanOperator.getTable().getPartitionColumnNames();
Expand All @@ -1634,8 +1634,8 @@ public ScalarOperator removePartitionPredicate(ScalarOperator predicate, Operato
List<ScalarOperator> conjuncts = Utils.extractConjuncts(predicate);
List<ScalarOperator> newPredicates = Lists.newArrayList();
for (ScalarOperator scalarOperator : conjuncts) {
boolean isPartitionCol = isPartitionCol(scalarOperator.getChild(0), partitionColNames);
if (isPartitionCol && ListPartitionPruner.canPruneWithConjunct(scalarOperator)) {
if (ListPartitionPruner.canPruneWithConjunct(scalarOperator) &&
isPartitionCol(scalarOperator.getChild(0), partitionColNames)) {
// drop this predicate
} else {
newPredicates.add(scalarOperator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ public static void beforeClass() throws Exception {
starRocksAssert.ddl("ALTER TABLE t_gen_col ADD PARTITION p2_202402 VALUES IN (('2', '2024-02-01'))");
starRocksAssert.ddl("ALTER TABLE t_gen_col ADD PARTITION p2_202403 VALUES IN (('2', '2024-03-01'))");

starRocksAssert.withTable("CREATE TABLE t_bool_partition (" +
" c1 datetime NOT NULL, " +
" c2 boolean" +
" ) " +
" PARTITION BY (c1, c2) " +
" PROPERTIES('replication_num'='1')");

// year(c1)
starRocksAssert.withTable("CREATE TABLE t_gen_col_1 (" +
" c1 datetime NOT NULL," +
Expand Down Expand Up @@ -232,6 +239,10 @@ public void testGeneratedColumnPrune_RemovePredicate() throws Exception {
testRemovePredicate("select * from t_gen_col where c2 in (1, 2,3)", "true");
testRemovePredicate("select * from t_gen_col where c2 = cast('123' as int)", "true");

// bool partition column
testRemovePredicate("select * from t_bool_partition where c2=true", "2: c2");
testRemovePredicate("select * from t_bool_partition where c2=false", "true");

// can not be removed
testRemovePredicate("select * from t_gen_col where c1 = random() and c2 > 100",
"cast(1: c1 as double) = random(1)");
Expand Down

0 comments on commit 10a5f0e

Please sign in to comment.