[Feature](Materialized-View) forbiden rename column on materialized view (#17030)
forbiden rename column on materialized view
This commit is contained in:
@ -61,6 +61,7 @@ import org.apache.doris.analysis.DropFunctionStmt;
|
||||
import org.apache.doris.analysis.DropMaterializedViewStmt;
|
||||
import org.apache.doris.analysis.DropPartitionClause;
|
||||
import org.apache.doris.analysis.DropTableStmt;
|
||||
import org.apache.doris.analysis.Expr;
|
||||
import org.apache.doris.analysis.FunctionName;
|
||||
import org.apache.doris.analysis.InstallPluginStmt;
|
||||
import org.apache.doris.analysis.LinkDbStmt;
|
||||
@ -4052,9 +4053,26 @@ public class Env {
|
||||
if (entry.getValue().getColumnByName(newColName) != null) {
|
||||
throw new DdlException("Column name[" + newColName + "] is already used");
|
||||
}
|
||||
|
||||
// check if have materialized view on rename column
|
||||
for (Column column : entry.getValue().getSchema()) {
|
||||
Expr expr = column.getDefineExpr();
|
||||
if (expr == null) {
|
||||
continue;
|
||||
}
|
||||
List<SlotRef> slots = new ArrayList<>();
|
||||
expr.collect(SlotRef.class, slots);
|
||||
for (SlotRef slot : slots) {
|
||||
String name = MaterializedIndexMeta
|
||||
.normalizeName(CreateMaterializedViewStmt.mvColumnBreaker(slot.toSqlWithoutTbl()));
|
||||
if (!isReplay && name.equals(colName)) {
|
||||
throw new DdlException("Column[" + colName + "] have materialized view index");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 1. modify MaterializedIndexMeta
|
||||
// 1. modify old MaterializedIndexMeta
|
||||
boolean hasColumn = false;
|
||||
for (Map.Entry<Long, MaterializedIndexMeta> entry : indexIdToMeta.entrySet()) {
|
||||
Column column = entry.getValue().getColumnByName(colName);
|
||||
@ -4062,16 +4080,6 @@ public class Env {
|
||||
column.setName(newColName);
|
||||
hasColumn = true;
|
||||
}
|
||||
|
||||
// todo: need change complex expr name also
|
||||
Column mvColumn = entry.getValue().getColumnByName(CreateMaterializedViewStmt.mvColumnBuilder(colName));
|
||||
if (mvColumn != null) {
|
||||
mvColumn.setName(CreateMaterializedViewStmt.mvColumnBuilder(newColName));
|
||||
SlotRef slot = (SlotRef) mvColumn.getDefineExpr();
|
||||
slot.setCol(newColName);
|
||||
slot.setLabel('`' + newColName + '`');
|
||||
hasColumn = true;
|
||||
}
|
||||
}
|
||||
if (!hasColumn) {
|
||||
throw new DdlException("Column[" + colName + "] does not exists");
|
||||
@ -4084,12 +4092,6 @@ public class Env {
|
||||
if (column.getName().equalsIgnoreCase(colName)) {
|
||||
column.setName(newColName);
|
||||
}
|
||||
if (column.getName().equalsIgnoreCase(CreateMaterializedViewStmt.mvColumnBuilder(colName))) {
|
||||
column.setName(CreateMaterializedViewStmt.mvColumnBuilder(newColName));
|
||||
SlotRef slot = (SlotRef) column.getDefineExpr();
|
||||
slot.setCol(newColName);
|
||||
slot.setLabel('`' + newColName + '`');
|
||||
}
|
||||
}
|
||||
|
||||
// 3. modify index
|
||||
@ -4100,9 +4102,6 @@ public class Env {
|
||||
if (columns.get(i).equalsIgnoreCase(colName)) {
|
||||
columns.set(i, newColName);
|
||||
}
|
||||
if (columns.get(i).equalsIgnoreCase(CreateMaterializedViewStmt.mvColumnBuilder(colName))) {
|
||||
columns.set(i, CreateMaterializedViewStmt.mvColumnBuilder(newColName));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -4114,12 +4113,6 @@ public class Env {
|
||||
if (column.getName().equalsIgnoreCase(colName)) {
|
||||
column.setName(newColName);
|
||||
}
|
||||
if (column.getName().equalsIgnoreCase(CreateMaterializedViewStmt.mvColumnBuilder(colName))) {
|
||||
column.setName(CreateMaterializedViewStmt.mvColumnBuilder(newColName));
|
||||
SlotRef slot = (SlotRef) column.getDefineExpr();
|
||||
slot.setCol(newColName);
|
||||
slot.setLabel('`' + newColName + '`');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user