Skip to content

Commit 59e0965

Browse files
author
liutang123
committed
add ut
1 parent 633d20f commit 59e0965

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

fe/fe-core/src/test/java/org/apache/doris/nereids/rules/exploration/mv/MaterializedViewUtilsTest.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,19 @@ protected void runBeforeAll() throws Exception {
234234
+ " \"replication_num\" = \"1\"\n"
235235
+ ");\n"
236236
);
237+
createTable("CREATE TABLE `test3` (\n"
238+
+ " `id` VARCHAR(36) NOT NULL COMMENT 'id',\n"
239+
+ " `created_time` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT ''\n"
240+
+ ") ENGINE=OLAP\n"
241+
+ "DUPLICATE KEY(`id`)\n"
242+
+ "COMMENT ''\n"
243+
+ "PARTITION BY RANGE(`created_time`)\n"
244+
+ "(PARTITION P_2024071713 VALUES [('2024-07-17 13:00:00'), ('2024-07-17 14:00:00')),\n"
245+
+ "PARTITION P_2024071714 VALUES [('2024-07-17 14:00:00'), ('2024-07-17 15:00:00')))\n"
246+
+ "DISTRIBUTED BY HASH(`id`) BUCKETS AUTO\n"
247+
+ "PROPERTIES (\n"
248+
+ "\"replication_allocation\" = \"tag.location.default: 1\"\n"
249+
+ ");\n");
237250
// Should not make scan to empty relation when the table used by materialized view has no data
238251
connectContext.getSessionVariable().setDisableNereidsRules("OLAP_SCAN_PARTITION_PRUNE,PRUNE_EMPTY_PARTITION");
239252
}
@@ -809,6 +822,42 @@ public void containTableQueryOperatorWithoutOperatorTest() {
809822
});
810823
}
811824

825+
@Test
826+
public void getRelatedTableInfoWhenMultiPartitionExprs() {
827+
PlanChecker.from(connectContext)
828+
.checkExplain("select id, date_trunc(created_time, 'minute') as created_time_minute,"
829+
+ " min(created_time) as start_time,"
830+
+ " if(count(id) > 0, 1, 0) as status\n"
831+
+ " from test3 \n"
832+
+ " group by id, date_trunc(created_time, 'minute')",
833+
nereidsPlanner -> {
834+
Plan rewrittenPlan = nereidsPlanner.getRewrittenPlan();
835+
RelatedTableInfo relatedTableInfo =
836+
MaterializedViewUtils.getRelatedTableInfo("created_time_minute",
837+
"day", rewrittenPlan, nereidsPlanner.getCascadesContext());
838+
checkRelatedTableInfo(relatedTableInfo,
839+
"test3",
840+
"created_time",
841+
true);
842+
});
843+
PlanChecker.from(connectContext)
844+
.checkExplain("select id, date_trunc(created_time, 'hour') as created_time_hour,"
845+
+ " min(created_time) as start_time\n"
846+
+ " from test3 \n"
847+
+ " group by id, date_trunc(created_time, 'minute'),"
848+
+ " date_trunc(created_time, 'hour');",
849+
nereidsPlanner -> {
850+
Plan rewrittenPlan = nereidsPlanner.getRewrittenPlan();
851+
RelatedTableInfo relatedTableInfo =
852+
MaterializedViewUtils.getRelatedTableInfo("created_time_hour",
853+
"day", rewrittenPlan, nereidsPlanner.getCascadesContext());
854+
checkRelatedTableInfo(relatedTableInfo,
855+
"test3",
856+
"created_time",
857+
true);
858+
});
859+
}
860+
812861
private void checkRelatedTableInfo(RelatedTableInfo relatedTableInfo,
813862
String expectTableName,
814863
String expectColumnName,

0 commit comments

Comments
 (0)