Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1519,6 +1519,12 @@ public Void visitRefreshMaterializedViewStatement(RefreshMaterializedViewStateme
"refresh_mode=" + refreshMode.name() + ". Please refresh the whole materialized view instead.",
tableRef.getPos());
}
if (statement.isForceRefresh() && refreshMode.isIncrementalOrAuto()) {
throw new SemanticException("FORCE refresh is not supported for materialized views with " +
"refresh_mode=" + refreshMode.name() +
". Please drop and re-create the materialized view instead.",
tableRef.getPos());
}
PartitionInfo partitionInfo = mv.getPartitionInfo();
if (statement.getPartitionRangeDesc() != null) {
if (partitionInfo.isUnPartitioned()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.starrocks.clone.DynamicPartitionScheduler;
import com.starrocks.common.DdlException;
import com.starrocks.common.MaterializedViewExceptions;
import com.starrocks.common.util.PropertyAnalyzer;
import com.starrocks.connector.iceberg.MockIcebergMetadata;
import com.starrocks.qe.StmtExecutor;
import com.starrocks.schema.MTable;
Expand Down Expand Up @@ -362,6 +363,53 @@ public void testIncrementalRefreshModeRejectsPartitionRefresh() throws Exception
}
}

@Test
public void testIncrementalRefreshModeRejectsForceRefresh() throws Exception {
// Create a MV with PCT mode (no Iceberg required), then flip the persisted refresh_mode
// to "incremental" so the FORCE-rejection branch in the analyzer fires. This isolates the
// analyzer check from the IVM eligibility constraints of the CREATE path.
starRocksAssert.withMaterializedView("create materialized view test.mv_incremental_force_refresh\n" +
"distributed by hash(k2) buckets 3\n" +
"refresh manual\n" +
"properties (\n" +
"\"refresh_mode\" = \"pct\"\n" +
")\n" +
"as select k1, k2, v1 from test.tbl_with_mv;");
try {
MaterializedView mv = (MaterializedView) GlobalStateMgr.getCurrentState()
.getLocalMetastore().getTable("test", "mv_incremental_force_refresh");
mv.getTableProperty().setMvRefreshMode("incremental");
mv.getTableProperty().modifyTableProperties(PropertyAnalyzer.PROPERTIES_MV_REFRESH_MODE, "incremental");

String sql = "REFRESH MATERIALIZED VIEW test.mv_incremental_force_refresh FORCE;";
Exception e = Assertions.assertThrows(Exception.class,
() -> UtFrameUtils.parseStmtWithNewParser(sql, connectContext));
Assertions.assertTrue(e.getMessage().contains(
"FORCE refresh is not supported for materialized views with refresh_mode=INCREMENTAL."),
"expected FORCE rejection error, got: " + e.getMessage());
} finally {
starRocksAssert.dropMaterializedView("test.mv_incremental_force_refresh");
}
}

@Test
public void testPctRefreshModeAllowsForceRefresh() throws Exception {
starRocksAssert.withMaterializedView("create materialized view test.mv_pct_force_refresh\n" +
"distributed by hash(k2) buckets 3\n" +
"refresh manual\n" +
"properties (\n" +
"\"refresh_mode\" = \"pct\"\n" +
")\n" +
"as select k1, k2, v1 from test.tbl_with_mv;");
try {
String sql = "REFRESH MATERIALIZED VIEW test.mv_pct_force_refresh FORCE;";
// Should parse without error: FORCE is only blocked on INCREMENTAL/AUTO MVs.
UtFrameUtils.parseStmtWithNewParser(sql, connectContext);
} finally {
starRocksAssert.dropMaterializedView("test.mv_pct_force_refresh");
}
}

@Test
public void testRefreshExecution() throws Exception {
executeInsertSql(connectContext, "insert into tbl_with_mv values(\"2022-02-20\", 1, 10)");
Expand Down
Loading