Skip to content

Commit

Permalink
Fix alter mv with excluded_refresh_tables bug
Browse files Browse the repository at this point in the history
Signed-off-by: shuming.li <[email protected]>
  • Loading branch information
LiShuMing committed Dec 2, 2024
1 parent 4e448af commit 11a265b
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" +
Expand Down Expand Up @@ -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";
Expand Down

0 comments on commit 11a265b

Please sign in to comment.