diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java index 80ac94b688..b69466ab51 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java @@ -1343,6 +1343,16 @@ public class SelectStmt extends QueryStmt { } } + // can't contain analytic exprs + ArrayList aggExprsForChecking = Lists.newArrayList(); + TreeNode.collect(resultExprs, Expr.isAggregatePredicate(), aggExprsForChecking); + ArrayList analyticExprs = Lists.newArrayList(); + TreeNode.collect(aggExprsForChecking, AnalyticExpr.class, analyticExprs); + if (!analyticExprs.isEmpty()) { + throw new AnalysisException( + "AGGREGATE clause must not contain analytic expressions"); + } + // Collect the aggregate expressions from the SELECT, HAVING and ORDER BY clauses // of this statement. ArrayList aggExprs = Lists.newArrayList(); diff --git a/regression-test/suites/query_p0/sql_functions/window_functions/test_window_fn.groovy b/regression-test/suites/query_p0/sql_functions/window_functions/test_window_fn.groovy index 1cbab91a44..22a9e798f0 100644 --- a/regression-test/suites/query_p0/sql_functions/window_functions/test_window_fn.groovy +++ b/regression-test/suites/query_p0/sql_functions/window_functions/test_window_fn.groovy @@ -365,6 +365,29 @@ suite("test_window_fn") { """ sql "DROP TABLE IF EXISTS example_window_tb;" + + sql """ + CREATE TABLE IF NOT EXISTS test_window_in_agg + ( + `c1` int , + `c2` int , + `c3` int + ) + ENGINE=OLAP + DUPLICATE KEY(`c1`) + COMMENT "" + DISTRIBUTED BY HASH(`c1`) BUCKETS 1 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1", + "in_memory" = "false", + "storage_format" = "V2" + ); + """ + test { + sql """SELECT SUM(MAX(c1) OVER (PARTITION BY c2, c3)) FROM test_window_in_agg;""" + exception "errCode = 2, detailMessage = AGGREGATE clause must not contain analytic expressions" + } + sql "DROP TABLE IF EXISTS test_window_in_agg;" }