Skip to content

Commit 964a00c

Browse files
Youngwbmergify[bot]
authored andcommitted
[Enhancement] Reject FORCE refresh on INCREMENTAL/AUTO materialized views (#72336)
Signed-off-by: Youngwb <yangwenbo_mailbox@163.com> Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com> (cherry picked from commit 75a5d6e) # Conflicts: # fe/fe-core/src/test/java/com/starrocks/analysis/RefreshMaterializedViewTest.java
1 parent d9f4c90 commit 964a00c

2 files changed

Lines changed: 59 additions & 0 deletions

File tree

fe/fe-core/src/main/java/com/starrocks/sql/analyzer/MaterializedViewAnalyzer.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1803,6 +1803,12 @@ public Void visitRefreshMaterializedViewStatement(RefreshMaterializedViewStateme
18031803
"refresh_mode=" + refreshMode.name() + ". Please refresh the whole materialized view instead.",
18041804
tableRef.getPos());
18051805
}
1806+
if (statement.isForceRefresh() && refreshMode.isIncrementalOrAuto()) {
1807+
throw new SemanticException("FORCE refresh is not supported for materialized views with " +
1808+
"refresh_mode=" + refreshMode.name() +
1809+
". Please drop and re-create the materialized view instead.",
1810+
tableRef.getPos());
1811+
}
18061812
PartitionInfo partitionInfo = mv.getPartitionInfo();
18071813
if (statement.getPartitionRangeDesc() != null) {
18081814
if (partitionInfo.isUnPartitioned()) {

fe/fe-core/src/test/java/com/starrocks/analysis/RefreshMaterializedViewTest.java

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@
3030
import com.starrocks.catalog.TableName;
3131
import com.starrocks.catalog.Tablet;
3232
import com.starrocks.clone.DynamicPartitionScheduler;
33+
<<<<<<< HEAD
34+
=======
35+
import com.starrocks.common.DdlException;
36+
import com.starrocks.common.MaterializedViewExceptions;
37+
import com.starrocks.common.util.PropertyAnalyzer;
38+
>>>>>>> 75a5d6e2c1 ([Enhancement] Reject FORCE refresh on INCREMENTAL/AUTO materialized views (#72336))
3339
import com.starrocks.connector.iceberg.MockIcebergMetadata;
3440
import com.starrocks.qe.StmtExecutor;
3541
import com.starrocks.schema.MTable;
@@ -314,6 +320,53 @@ public void testIncrementalRefreshModeRejectsPartitionRefresh() throws Exception
314320
}
315321
}
316322

323+
@Test
324+
public void testIncrementalRefreshModeRejectsForceRefresh() throws Exception {
325+
// Create a MV with PCT mode (no Iceberg required), then flip the persisted refresh_mode
326+
// to "incremental" so the FORCE-rejection branch in the analyzer fires. This isolates the
327+
// analyzer check from the IVM eligibility constraints of the CREATE path.
328+
starRocksAssert.withMaterializedView("create materialized view test.mv_incremental_force_refresh\n" +
329+
"distributed by hash(k2) buckets 3\n" +
330+
"refresh manual\n" +
331+
"properties (\n" +
332+
"\"refresh_mode\" = \"pct\"\n" +
333+
")\n" +
334+
"as select k1, k2, v1 from test.tbl_with_mv;");
335+
try {
336+
MaterializedView mv = (MaterializedView) GlobalStateMgr.getCurrentState()
337+
.getLocalMetastore().getTable("test", "mv_incremental_force_refresh");
338+
mv.getTableProperty().setMvRefreshMode("incremental");
339+
mv.getTableProperty().modifyTableProperties(PropertyAnalyzer.PROPERTIES_MV_REFRESH_MODE, "incremental");
340+
341+
String sql = "REFRESH MATERIALIZED VIEW test.mv_incremental_force_refresh FORCE;";
342+
Exception e = Assertions.assertThrows(Exception.class,
343+
() -> UtFrameUtils.parseStmtWithNewParser(sql, connectContext));
344+
Assertions.assertTrue(e.getMessage().contains(
345+
"FORCE refresh is not supported for materialized views with refresh_mode=INCREMENTAL."),
346+
"expected FORCE rejection error, got: " + e.getMessage());
347+
} finally {
348+
starRocksAssert.dropMaterializedView("test.mv_incremental_force_refresh");
349+
}
350+
}
351+
352+
@Test
353+
public void testPctRefreshModeAllowsForceRefresh() throws Exception {
354+
starRocksAssert.withMaterializedView("create materialized view test.mv_pct_force_refresh\n" +
355+
"distributed by hash(k2) buckets 3\n" +
356+
"refresh manual\n" +
357+
"properties (\n" +
358+
"\"refresh_mode\" = \"pct\"\n" +
359+
")\n" +
360+
"as select k1, k2, v1 from test.tbl_with_mv;");
361+
try {
362+
String sql = "REFRESH MATERIALIZED VIEW test.mv_pct_force_refresh FORCE;";
363+
// Should parse without error: FORCE is only blocked on INCREMENTAL/AUTO MVs.
364+
UtFrameUtils.parseStmtWithNewParser(sql, connectContext);
365+
} finally {
366+
starRocksAssert.dropMaterializedView("test.mv_pct_force_refresh");
367+
}
368+
}
369+
317370
@Test
318371
public void testRefreshExecution() throws Exception {
319372
executeInsertSql(connectContext, "insert into tbl_with_mv values(\"2022-02-20\", 1, 10)");

0 commit comments

Comments
 (0)