|
63 | 63 | import com.starrocks.sql.analyzer.MaterializedViewAnalyzer; |
64 | 64 | import com.starrocks.sql.analyzer.SemanticException; |
65 | 65 | import com.starrocks.sql.analyzer.SetStmtAnalyzer; |
66 | | -import com.starrocks.sql.analyzer.mv.IVMAnalyzer; |
67 | 66 | import com.starrocks.sql.ast.AddColumnsClause; |
68 | 67 | import com.starrocks.sql.ast.AddMVColumnClause; |
69 | 68 | import com.starrocks.sql.ast.AlterMaterializedViewStatusClause; |
@@ -244,49 +243,29 @@ private void alterMVRefreshMode(Map<String, String> properties, |
244 | 243 | List<Runnable> appliers, |
245 | 244 | ConnectContext context) { |
246 | 245 | String mvRefreshMode = PropertyAnalyzer.analyzeRefreshMode(properties); |
247 | | - // cannot alter original pct based mv to incremental or auto, only support original ivm/pct based mv |
248 | | - MaterializedView.RefreshMode currentRefreshMode = |
| 246 | + MaterializedView.RefreshMode targetMode = |
249 | 247 | MaterializedView.RefreshMode.valueOf(mvRefreshMode.toUpperCase(Locale.ROOT)); |
250 | | - if (currentRefreshMode.isIncrementalOrAuto()) { |
251 | | - ParseNode mvDefinedQueryParseNode = materializedView.getDefineQueryParseNode(); |
252 | | - if ((mvDefinedQueryParseNode instanceof QueryStatement queryStatement)) { |
253 | | - IVMAnalyzer ivmAnalyzer = new IVMAnalyzer(context, null, queryStatement); |
254 | | - |
255 | | - Optional<IVMAnalyzer.IVMAnalyzeResult> result; |
256 | | - try { |
257 | | - result = ivmAnalyzer.rewrite( |
258 | | - MaterializedView.RefreshMode.valueOf(mvRefreshMode.toUpperCase(Locale.ROOT))); |
259 | | - } catch (SemanticException e) { |
260 | | - throw new SemanticException("Cannot alter materialized view refresh mode to %s: %s", |
261 | | - mvRefreshMode, e.getMessage()); |
262 | | - } |
263 | | - if (result.isEmpty()) { |
264 | | - throw new SemanticException("Cannot alter materialized view refresh mode to %s," + |
265 | | - " because the materialized view is not eligible for %s refresh mode", |
266 | | - mvRefreshMode, mvRefreshMode); |
267 | | - } |
268 | | - // if materialized's original refresh mode is not auto or ivm, throw exception |
269 | | - if (!materializedView.getCurrentRefreshMode().isIncrementalOrAuto()) { |
270 | | - throw new SemanticException("Cannot alter materialized view refresh mode to %s," + |
271 | | - " only support alter original incremental/auto based materialized view", |
272 | | - mvRefreshMode); |
273 | | - } |
274 | | - currentRefreshMode = result.get().currentRefreshMode(); |
275 | | - } else { |
276 | | - throw new SemanticException("Cannot alter materialized view refresh mode to %s", mvRefreshMode); |
277 | | - } |
| 248 | + MaterializedView.RefreshMode originalMode = materializedView.getCurrentRefreshMode(); |
| 249 | + |
| 250 | + // Cross-mode ALTER is not supported. The recovery path for changing refresh_mode is |
| 251 | + // drop-and-recreate. Same-mode ALTER is allowed and behaves as a no-op (modulo the |
| 252 | + // applier below, which keeps the persisted property and the in-memory mode in sync). |
| 253 | + if (originalMode != targetMode) { |
| 254 | + throw new SemanticException( |
| 255 | + "Altering refresh_mode from %s to %s is not supported. " + |
| 256 | + "Please drop and re-create the materialized view if a mode change is required.", |
| 257 | + originalMode, targetMode); |
278 | 258 | } |
279 | 259 |
|
280 | | - MaterializedView.RefreshMode finalCurrentRefreshMode = currentRefreshMode; |
281 | 260 | // Trigger applier when either the persisted property or the in-memory current mode |
282 | 261 | // would change. Comparing only the persisted string would miss cases where the two |
283 | 262 | // are out of sync (e.g. mode promoted internally without rewriting the property). |
284 | 263 | if (!tableProperty.getMvRefreshMode().equals(mvRefreshMode) |
285 | | - || materializedView.getCurrentRefreshMode() != finalCurrentRefreshMode) { |
| 264 | + || materializedView.getCurrentRefreshMode() != targetMode) { |
286 | 265 | appliers.add(() -> { |
287 | 266 | tableProperty.modifyTableProperties(PropertyAnalyzer.PROPERTIES_MV_REFRESH_MODE, mvRefreshMode); |
288 | 267 | tableProperty.setMvRefreshMode(mvRefreshMode); |
289 | | - materializedView.setCurrentRefreshMode(finalCurrentRefreshMode); |
| 268 | + materializedView.setCurrentRefreshMode(targetMode); |
290 | 269 | }); |
291 | 270 | } |
292 | 271 | } |
|
0 commit comments