Skip to content

Commit

Permalink
branch-2.1: [fix](mtmv) Fixed an error in setting variables in nested…
Browse files Browse the repository at this point in the history
… materialize views #44960 (#45038)

Cherry-picked from #44960
  • Loading branch information
github-actions[bot] authored Dec 6, 2024
1 parent 682cec9 commit f038f28
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 4 deletions.
5 changes: 3 additions & 2 deletions fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,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) {
Expand Down
3 changes: 3 additions & 0 deletions regression-test/data/correctness_p0/test_mv_case.out
Original file line number Diff line number Diff line change
Expand Up @@ -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"}

69 changes: 67 additions & 2 deletions regression-test/suites/correctness_p0/test_mv_case.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand All @@ -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 """
}

0 comments on commit f038f28

Please sign in to comment.