|
30 | 30 | import com.starrocks.catalog.TableName; |
31 | 31 | import com.starrocks.catalog.Tablet; |
32 | 32 | 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)) |
33 | 39 | import com.starrocks.connector.iceberg.MockIcebergMetadata; |
34 | 40 | import com.starrocks.qe.StmtExecutor; |
35 | 41 | import com.starrocks.schema.MTable; |
@@ -314,6 +320,53 @@ public void testIncrementalRefreshModeRejectsPartitionRefresh() throws Exception |
314 | 320 | } |
315 | 321 | } |
316 | 322 |
|
| 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 | + |
317 | 370 | @Test |
318 | 371 | public void testRefreshExecution() throws Exception { |
319 | 372 | executeInsertSql(connectContext, "insert into tbl_with_mv values(\"2022-02-20\", 1, 10)"); |
|
0 commit comments