diff --git a/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVCache.java b/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVCache.java index 2895ad73e14297..d3d7f1ad6ebbf5 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVCache.java +++ b/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVCache.java @@ -88,13 +88,14 @@ public StructInfo getStructInfo() { } public static MTMVCache from(MTMV mtmv, ConnectContext connectContext, boolean needCost) { - LogicalPlan unboundMvPlan = new NereidsParser().parseSingle(mtmv.getQuerySql()); StatementContext mvSqlStatementContext = new StatementContext(connectContext, new OriginStatement(mtmv.getQuerySql(), 0)); - NereidsPlanner planner = new NereidsPlanner(mvSqlStatementContext); if (mvSqlStatementContext.getConnectContext().getStatementContext() == null) { mvSqlStatementContext.getConnectContext().setStatementContext(mvSqlStatementContext); } + LogicalPlan unboundMvPlan = new NereidsParser().parseSingle(mtmv.getQuerySql()); + NereidsPlanner planner = new NereidsPlanner(mvSqlStatementContext); + // Can not convert to table sink, because use the same column from different table when self join // the out slot is wrong if (needCost) { diff --git a/regression-test/data/correctness_p0/test_mv_case/test_mv_case.out b/regression-test/data/correctness_p0/test_mv_case/test_mv_case.out index e87ee694dc1adb..bab672bd6abd07 100644 --- a/regression-test/data/correctness_p0/test_mv_case/test_mv_case.out +++ b/regression-test/data/correctness_p0/test_mv_case/test_mv_case.out @@ -5,3 +5,6 @@ cib2205045_1_1s 2023-06-10T03:56:33 {"DB1":168939,"DNT":"2023-06-10 03:56:33"} cib2205045_1_1s 2023-06-10T03:57:33 {"DB1":168939,"DNT":"2023-06-10 03:57:33"} cib2205045_1_1s 2023-06-10T03:58:33 {"DB1":168939,"DNT":"2023-06-10 03:58:33"} +-- !select_mv -- +123 {3:"5", 6:"8"} + diff --git a/regression-test/suites/correctness_p0/test_mv_case/test_mv_case.groovy b/regression-test/suites/correctness_p0/test_mv_case/test_mv_case.groovy index 0a87c8d2704d1c..0940f817a8de27 100644 --- a/regression-test/suites/correctness_p0/test_mv_case/test_mv_case.groovy +++ b/regression-test/suites/correctness_p0/test_mv_case/test_mv_case.groovy @@ -20,7 +20,7 @@ suite("test_mv_case") { sql """CREATE TABLE `test_table_aaa2` ( `ordernum` varchar(65533) NOT NULL , `dnt` datetime NOT NULL , - `data` json NULL + `data` json NULL ) ENGINE=OLAP DUPLICATE KEY(`ordernum`, `dnt`) COMMENT 'OLAP' @@ -55,7 +55,7 @@ suite("test_mv_case") { createMV ("""create materialized view test_mv_view_t_mv as select `day`, count(game_code) from test_mv_view_t group by day;""") - sql """create view test_mv_view_t_view + sql """create view test_mv_view_t_view as select `day` from test_mv_view_t @@ -69,4 +69,69 @@ suite("test_mv_case") { sql("""SELECT * from test_mv_view_t_view where day='2024-04-15';""") notContains("mv_day") } + + sql """ drop table if exists tb1 """ + sql """ CREATE TABLE tb1 ( + `id` bigint NOT NULL COMMENT '', + `map_infos` map < int, + varchar(65533) > NULL COMMENT '' + ) ENGINE = OLAP UNIQUE KEY(`id`) COMMENT 'test' DISTRIBUTED BY HASH(`id`) BUCKETS 2 PROPERTIES ( + "replication_allocation" = "tag.location.default: 1", + "min_load_replica_num" = "-1", + "is_being_synced" = "false", + "storage_medium" = "hdd", + "storage_format" = "V2", + "inverted_index_storage_format" = "V1", + "enable_unique_key_merge_on_write" = "true", + "light_schema_change" = "true", + "disable_auto_compaction" = "false", + "enable_single_replica_compaction" = "false", + "group_commit_interval_ms" = "10000", + "group_commit_data_bytes" = "134217728", + "enable_mow_light_delete" = "false" + ) + """ + sql """insert into tb1 select id,map_agg(a, b) from(select 123 id,3 a,'5' b union all select 123 id, 6 a, '8' b) aa group by id""" + createMV ("""CREATE MATERIALIZED VIEW mv1 BUILD IMMEDIATE REFRESH COMPLETE ON SCHEDULE EVERY 10 MINUTE DUPLICATE KEY(info_id) DISTRIBUTED BY HASH(`info_id`) BUCKETS 2 PROPERTIES ( + "replication_allocation" = "tag.location.default: 1", + "min_load_replica_num" = "-1", + "is_being_synced" = "false", + "colocate_with" = "dwd_info_group", + "storage_medium" = "hdd", + "storage_format" = "V2", + "inverted_index_storage_format" = "V1", + "light_schema_change" = "true", + "disable_auto_compaction" = "false", + "enable_single_replica_compaction" = "false", + "group_commit_interval_ms" = "10000", + "group_commit_data_bytes" = "134217728", + "enable_nondeterministic_function" = "true" + ) AS + select + /*+ SET_VAR(enable_force_spill = true) */ + cast(a.id as bigint) info_id, + map_infos + from + tb1 a;""") + createMV ("""CREATE MATERIALIZED VIEW mv2 BUILD IMMEDIATE REFRESH COMPLETE ON SCHEDULE EVERY 10 MINUTE DUPLICATE KEY(info_id) DISTRIBUTED BY HASH(`info_id`) BUCKETS 2 PROPERTIES ( + "replication_allocation" = "tag.location.default: 1", + "min_load_replica_num" = "-1", + "is_being_synced" = "false", + "colocate_with" = "dwd_info_group", + "storage_medium" = "hdd", + "storage_format" = "V2", + "inverted_index_storage_format" = "V1", + "light_schema_change" = "true", + "disable_auto_compaction" = "false", + "enable_single_replica_compaction" = "false", + "group_commit_interval_ms" = "10000", + "group_commit_data_bytes" = "134217728", + "enable_nondeterministic_function" = "true" + ) AS + select + info_id, + map_infos + from + mv1 a;""") + qt_select_mv """ select * from mv2 """ }