[Mv] check delete from column exists on mv (#31321)
This commit is contained in:
@ -26,6 +26,7 @@ import org.apache.doris.catalog.Column;
|
||||
import org.apache.doris.catalog.Database;
|
||||
import org.apache.doris.catalog.Env;
|
||||
import org.apache.doris.catalog.KeysType;
|
||||
import org.apache.doris.catalog.MaterializedIndexMeta;
|
||||
import org.apache.doris.catalog.OlapTable;
|
||||
import org.apache.doris.common.Config;
|
||||
import org.apache.doris.common.ErrorCode;
|
||||
@ -240,6 +241,17 @@ public class DeleteFromCommand extends Command implements ForwardWithSync {
|
||||
+ "] is an unique table without merge-on-write.");
|
||||
}
|
||||
}
|
||||
|
||||
for (String indexName : table.getIndexNameToId().keySet()) {
|
||||
MaterializedIndexMeta meta = table.getIndexMetaByIndexId(table.getIndexIdByName(indexName));
|
||||
Set<String> columns = meta.getSchema().stream()
|
||||
.map(col -> org.apache.doris.analysis.CreateMaterializedViewStmt.mvColumnBreaker(col.getName()))
|
||||
.collect(Collectors.toSet());
|
||||
if (!columns.contains(column.getName())) {
|
||||
throw new AnalysisException("Column[" + column.getName() + "] not exist in index " + indexName
|
||||
+ ". maybe you need drop the corresponding materialized-view.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void checkSubQuery(Plan plan) {
|
||||
|
||||
@ -0,0 +1,4 @@
|
||||
-- This file is automatically generated. You should know what you did if you want to edit this
|
||||
-- !test --
|
||||
2 1
|
||||
|
||||
@ -32,6 +32,20 @@ suite ("where_invalid") {
|
||||
properties("replication_num" = "1");
|
||||
"""
|
||||
|
||||
sql "insert into a_table select 1,1,1,1,to_bitmap(1),hll_hash(1);"
|
||||
|
||||
createMV("create materialized view ma1 as select k1,bitmap_union(k5) from a_table group by k1;")
|
||||
|
||||
sql "insert into a_table select 2,2,2,2,to_bitmap(2),hll_hash(2);"
|
||||
|
||||
test {
|
||||
sql "delete from a_table where k2=1;"
|
||||
exception "errCode = 2,"
|
||||
}
|
||||
sql "delete from a_table where k1=1;"
|
||||
|
||||
qt_test "select k1,bitmap_count(bitmap_union(k5)) from a_table group by k1;"
|
||||
|
||||
test {
|
||||
sql "create materialized view where_1 as select k1,k4 from a_table where k4 =1;"
|
||||
exception "errCode = 2,"
|
||||
|
||||
Reference in New Issue
Block a user