diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateMaterializedViewStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateMaterializedViewStmt.java index bbab202051..de9caed75f 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateMaterializedViewStmt.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateMaterializedViewStmt.java @@ -165,6 +165,11 @@ public class CreateMaterializedViewStmt extends DdlStmt { analyzeSelectClause(analyzer); analyzeFromClause(); if (selectStmt.getWhereClause() != null) { + if (!isReplay && selectStmt.getWhereClause().hasAggregateSlot()) { + throw new AnalysisException( + "The where clause contained aggregate column is not supported, expr:" + + selectStmt.getWhereClause().toSql()); + } whereClauseItem = new MVColumnItem(selectStmt.getWhereClause()); } if (selectStmt.getHavingPred() != null) { diff --git a/regression-test/suites/mv_p0/test_mv_useless/agg_invalid.groovy b/regression-test/suites/mv_p0/test_mv_useless/agg_invalid/agg_invalid.groovy similarity index 85% rename from regression-test/suites/mv_p0/test_mv_useless/agg_invalid.groovy rename to regression-test/suites/mv_p0/test_mv_useless/agg_invalid/agg_invalid.groovy index f4702769ca..bdf7a567be 100644 --- a/regression-test/suites/mv_p0/test_mv_useless/agg_invalid.groovy +++ b/regression-test/suites/mv_p0/test_mv_useless/agg_invalid/agg_invalid.groovy @@ -16,11 +16,6 @@ // under the License. suite ("agg_invalid") { - def testTable = "test_agg_mv_useless_table" - def getJobState = { tableName -> - def jobStateResult = sql """ SHOW ALTER TABLE MATERIALIZED VIEW WHERE TableName='${testTable}' ORDER BY CreateTime DESC LIMIT 1; """ - return jobStateResult[0][8] - } sql """drop table if exists t1;""" sql """ @@ -42,7 +37,7 @@ suite ("agg_invalid") { exception null } - test { + test { sql "CREATE MATERIALIZED VIEW mv_4 AS SELECT p1, SUM(abs(v1)) FROM t1 GROUP BY p1;" exception "errCode = 2," } 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 new file mode 100644 index 0000000000..f0d96a773f --- /dev/null +++ b/regression-test/suites/mv_p0/test_mv_useless/where_invalid/where_invalid.groovy @@ -0,0 +1,49 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +suite ("where_invalid") { + sql """drop table if exists a_table;""" + + sql """ + create table a_table( + k1 int null, + k2 int not null, + k3 bigint null, + k4 bigint sum null, + k5 bitmap bitmap_union null, + k6 hll hll_union null + ) + aggregate key (k1,k2,k3) + distributed BY hash(k1) buckets 3 + properties("replication_num" = "1"); + """ + + test { + sql "create materialized view where_1 as select k1,k4 from a_table where k4 =1;" + exception "errCode = 2," + } + + test { + sql "create materialized view where_2 as select k1,sum(k4) from a_table where k4 =1 group by k1;" + exception "errCode = 2," + } + + test { + sql "create materialized view where_2 as select k1,sum(k4) from a_table where k1+k4 =1 group by k1;" + exception "errCode = 2," + } +}