From 11a265b4c74f14d702c21cd0cc2ad1cb53a4dab5 Mon Sep 17 00:00:00 2001 From: "shuming.li" Date: Mon, 2 Dec 2024 11:45:53 +0800 Subject: [PATCH] Fix alter mv with excluded_refresh_tables bug Signed-off-by: shuming.li --- .../starrocks/alter/AlterMVJobExecutor.java | 2 +- .../analysis/RefreshMaterializedViewTest.java | 50 ++++++++++++++++++- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/fe/fe-core/src/main/java/com/starrocks/alter/AlterMVJobExecutor.java b/fe/fe-core/src/main/java/com/starrocks/alter/AlterMVJobExecutor.java index 75aa04ef5e2f0..66bd93dd84c60 100644 --- a/fe/fe-core/src/main/java/com/starrocks/alter/AlterMVJobExecutor.java +++ b/fe/fe-core/src/main/java/com/starrocks/alter/AlterMVJobExecutor.java @@ -250,7 +250,7 @@ public Void visitModifyTablePropertiesClause(ModifyTablePropertiesClause modifyT if (propClone.containsKey(PropertyAnalyzer.PROPERTIES_EXCLUDED_REFRESH_TABLES)) { curProp.put(PropertyAnalyzer.PROPERTIES_EXCLUDED_REFRESH_TABLES, propClone.get(PropertyAnalyzer.PROPERTIES_EXCLUDED_REFRESH_TABLES)); - materializedView.getTableProperty().setExcludedRefreshTables(excludedTriggerTables); + materializedView.getTableProperty().setExcludedRefreshTables(excludedRefreshBaseTables); isChanged = true; } if (propClone.containsKey(PropertyAnalyzer.PROPERTIES_UNIQUE_CONSTRAINT)) { diff --git a/fe/fe-core/src/test/java/com/starrocks/analysis/RefreshMaterializedViewTest.java b/fe/fe-core/src/test/java/com/starrocks/analysis/RefreshMaterializedViewTest.java index 175030b914fd7..937ee4d0456fd 100644 --- a/fe/fe-core/src/test/java/com/starrocks/analysis/RefreshMaterializedViewTest.java +++ b/fe/fe-core/src/test/java/com/starrocks/analysis/RefreshMaterializedViewTest.java @@ -107,7 +107,7 @@ public static void beforeClass() throws Exception { } @Test - public void testCreateMVProperties() throws Exception { + public void testCreateMVProperties1() throws Exception { starRocksAssert .withTable("CREATE TABLE t1 \n" + "(\n" + @@ -150,6 +150,54 @@ public void testCreateMVProperties() throws Exception { }); } + @Test + public void testCreateMVProperties2() throws Exception { + starRocksAssert + .withTable("CREATE TABLE t1 \n" + + "(\n" + + " k1 date,\n" + + " k2 int,\n" + + " v1 int\n" + + ")\n" + + "PARTITION BY date_trunc('day', k1)\n" + + "DISTRIBUTED BY HASH(k2) BUCKETS 3\n" + + "PROPERTIES('replication_num' = '1');") + .withTable("CREATE TABLE t2 \n" + + "(\n" + + " k1 date,\n" + + " k2 int,\n" + + " v1 int\n" + + ")\n" + + "PARTITION BY date_trunc('day', k1)\n" + + "DISTRIBUTED BY HASH(k2) BUCKETS 3\n" + + "PROPERTIES('replication_num' = '1');"); + withRefreshedMV("CREATE MATERIALIZED VIEW mv1 \n" + + "PARTITION BY date_trunc('day', k1)\n" + + "DISTRIBUTED BY RANDOM\n" + + "REFRESH ASYNC\n" + + "AS \n" + + "select k1 from (SELECT * FROM t1 UNION ALL SELECT * FROM t2) t group by k1\n", () -> { + Database db = GlobalStateMgr.getCurrentState().getLocalMetastore().getDb("test"); + MaterializedView mv = + (MaterializedView) GlobalStateMgr.getCurrentState().getLocalMetastore().getTable(db.getFullName(), "mv1"); + Assert.assertTrue(mv.shouldRefreshTable("t1")); + Assert.assertTrue(mv.shouldRefreshTable("t2")); + + String alterSql = "ALTER MATERIALIZED VIEW mv1 SET ('excluded_refresh_tables' = 't2')"; + AlterMaterializedViewStmt stmt = + (AlterMaterializedViewStmt) UtFrameUtils.parseStmtWithNewParser(alterSql, connectContext); + GlobalStateMgr.getCurrentState().getLocalMetastore().alterMaterializedView(stmt); + Assert.assertTrue(mv.shouldRefreshTable("t1")); + Assert.assertFalse(mv.shouldRefreshTable("t2")); + + // cleanup + starRocksAssert.dropTable("t1"); + starRocksAssert.dropTable("t2"); + starRocksAssert.dropMaterializedView("mv1"); + }); + } + + @Test public void testNormal() throws Exception { String refreshMvSql = "refresh materialized view test.mv_to_refresh";