Skip to content

Commit

Permalink
Add enable_active_materialized_view_schema_strict_check config to dec…
Browse files Browse the repository at this point in the history
…ide whether to check schema strictlly in activing mv

Signed-off-by: shuming.li <[email protected]>
  • Loading branch information
LiShuMing committed Sep 9, 2024
1 parent e3e6943 commit a6c55a7
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
36 changes: 35 additions & 1 deletion fe/fe-core/src/main/java/com/starrocks/alter/AlterJobMgr.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import com.starrocks.catalog.Table.TableType;
import com.starrocks.catalog.TableProperty;
import com.starrocks.catalog.View;
import com.starrocks.common.Config;
import com.starrocks.common.DdlException;
import com.starrocks.common.ErrorCode;
import com.starrocks.common.ErrorReport;
Expand Down Expand Up @@ -254,10 +255,13 @@ public static QueryStatement recreateMVQuery(MaterializedView materializedView,
throw new SemanticException(String.format("number of columns changed: %d != %d",
existedColumns.size(), newColumns.size()));
}

for (int i = 0; i < existedColumns.size(); i++) {
Column existed = existedColumns.get(i);
Column created = newColumns.get(i);
if (!existed.isSchemaCompatible(created)) {
if (!isSchemaCompatible(existed, created)) {
LOG.warn("Active materialized view {} failed, column schema changed: {} != {}",
materializedView.getName(), existed.toString(), created.toString());
String message = MaterializedViewExceptions.inactiveReasonForColumnNotCompatible(
existed.toString(), created.toString());
materializedView.setInactiveAndReason(message);
Expand All @@ -268,6 +272,36 @@ public static QueryStatement recreateMVQuery(MaterializedView materializedView,
return createStmt.getQueryStatement();
}

/**
* Check if the schema of existed and created column is compatible, if not, return false
* @param existed mv's existed column
* @param created new mv's created column
*/
private static boolean isSchemaCompatible(Column existed, Column created) {
if (Config.enable_active_materialized_view_schema_strict_check) {
return existed.isSchemaCompatible(created);
} else {
return isSchemaCompatibleInLoose(existed, created);
}
}

/**
* Check if the schema of existed and created column is compatible in loose mode
* @param t1 mv's existed column
* @param t2 new mv's created column
*/
private static boolean isSchemaCompatibleInLoose(Column t1, Column t2) {
// check whether the column name are the same
if (!t1.getName().equalsIgnoreCase(t2.getName())) {
return false;
}
// check whether the column primitive type are the same
if (!t1.getType().getPrimitiveType().equals(t2.getType().getPrimitiveType())) {
return false;
}
return true;
}

public void replayAlterMaterializedViewBaseTableInfos(AlterMaterializedViewBaseTableInfosLog log) {
long dbId = log.getDbId();
long mvId = log.getMvId();
Expand Down
3 changes: 3 additions & 0 deletions fe/fe-core/src/main/java/com/starrocks/common/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -2972,6 +2972,9 @@ public class Config extends ConfigBase {
@ConfField(mutable = true)
public static int default_mv_partition_refresh_number = 1;

@ConfField(mutable = true, comment = "Check the schema of materialized view's base table strictly or not")
public static boolean enable_active_materialized_view_schema_strict_check = true;

@ConfField(mutable = true,
comment = "The default behavior of whether REFRESH IMMEDIATE or not, " +
"which would refresh the materialized view after creating")
Expand Down

0 comments on commit a6c55a7

Please sign in to comment.