Skip to content

Commit

Permalink
[BugFix] Fix mv partition prune failed when partition column predicat…
Browse files Browse the repository at this point in the history
…e with function

Signed-off-by: kaijian.ding <[email protected]>
  • Loading branch information
kaijianding committed Aug 7, 2024
1 parent e73c9b1 commit bd0f1da
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.starrocks.analysis.Expr;
import com.starrocks.analysis.FunctionCallExpr;
import com.starrocks.analysis.LiteralExpr;
import com.starrocks.analysis.SlotRef;
import com.starrocks.catalog.Column;
import com.starrocks.catalog.ExpressionRangePartitionInfo;
import com.starrocks.catalog.ExpressionRangePartitionInfoV2;
Expand Down Expand Up @@ -408,6 +409,8 @@ private static boolean isNeedFurtherPrune(List<Long> candidatePartitions, Logica
return (FunctionSet.DATE_TRUNC.equalsIgnoreCase(functionName)
|| FunctionSet.TIME_SLICE.equalsIgnoreCase(functionName))
&& !exprPartitionInfo.getIdToRange(true).containsKey(candidatePartitions.get(0));
} else if (partitionExpr.size() == 1 && partitionExpr.get(0) instanceof SlotRef) {
return !exprPartitionInfo.getIdToRange(true).containsKey(candidatePartitions.get(0));
}
} else if (partitionInfo instanceof ExpressionRangePartitionInfoV2) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ public static void beforeClass() throws Exception {
" PARTITION p5 values less than (\"3000\"))" +
" distributed by hash(c1)" +
" properties (\"replication_num\"=\"1\");");

starRocksAssert.withTable("create table test_base_part3(c1 int, c2 bigint, c3 date, c4 bigint)" +
" partition by range(c3) (" +
" partition p1 values less than (\"20240603\")," +
" partition p2 values less than (\"20240604\")," +
" partition p3 values less than (\"20240605\")," +
" PARTITION p4 values less than (\"20240606\")," +
" PARTITION p5 values less than (\"20240607\"))" +
" distributed by hash(c1)" +
" properties (\"replication_num\"=\"1\");");
}

// MV's partition columns is the same with the base table, and mv has partition filter predicates.
Expand Down Expand Up @@ -493,6 +503,25 @@ public void testBucketPrune_SingleTable2() throws Exception {
starRocksAssert.dropMaterializedView("partial_mv_8");
}

@Test
public void testPartitionPrune_WithFunc() throws Exception {
starRocksAssert.withMaterializedView("CREATE MATERIALIZED VIEW `partial_mv_14`\n" +
"COMMENT \"MATERIALIZED_VIEW\"\n" +
"PARTITION BY (`c3`)\n" +
"REFRESH MANUAL\n" +
"AS SELECT `c3`, sum(`c4`) AS `total`\n" +
"FROM `test_mv`.`test_base_part3`\n" +
"GROUP BY `c3`;");
refreshMaterializedView(MATERIALIZED_DB_NAME, "partial_mv_14");

sql("select c3, sum(c4) from test_base_part3 where date_format(c3,'%Y%m%d')='20240602' group by c3")
.contains("TABLE: partial_mv_14\n" +
" PREAGGREGATION: ON\n" +
" PREDICATES: '%Y%m%d') = '20240602', date_format(col$: c3\n" +
" partitions=1/5");
starRocksAssert.dropMaterializedView("partial_mv_14");
}

@Test
public void testPartitionWithNull() throws Exception {
{
Expand Down

0 comments on commit bd0f1da

Please sign in to comment.