This is an automated email from the ASF dual-hosted git repository. yiguolei pushed a commit to branch branch-2.1 in repository https://gitbox.apache.org/repos/asf/doris.git
commit 3b7261abe4e1d6da670d93a0bd1b007a6f32fa74 Author: Pxl <[email protected]> AuthorDate: Mon Feb 26 10:35:08 2024 +0800 [Mv] check delete from column exists on mv (#31321) --- .../nereids/trees/plans/commands/DeleteFromCommand.java | 12 ++++++++++++ .../mv_p0/test_mv_useless/where_invalid/where_invalid.out | 4 ++++ .../test_mv_useless/where_invalid/where_invalid.groovy | 14 ++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/DeleteFromCommand.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/DeleteFromCommand.java index ac2e4987715..0fbab6c72bb 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/DeleteFromCommand.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/DeleteFromCommand.java @@ -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) { diff --git a/regression-test/data/mv_p0/test_mv_useless/where_invalid/where_invalid.out b/regression-test/data/mv_p0/test_mv_useless/where_invalid/where_invalid.out new file mode 100644 index 00000000000..61cbb17e941 --- /dev/null +++ b/regression-test/data/mv_p0/test_mv_useless/where_invalid/where_invalid.out @@ -0,0 +1,4 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !test -- +2 1 + diff --git a/regression-test/suites/mv_p0/test_mv_useless/where_invalid/where_invalid.groovy b/regression-test/suites/mv_p0/test_mv_useless/where_invalid/where_invalid.groovy index f0d96a773f0..525f633f47d 100644 --- a/regression-test/suites/mv_p0/test_mv_useless/where_invalid/where_invalid.groovy +++ b/regression-test/suites/mv_p0/test_mv_useless/where_invalid/where_invalid.groovy @@ -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," --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
