Skip to content

Commit

Permalink
[Fix](Planner) fix window function in aggregation (apache#22603)
Browse files Browse the repository at this point in the history
Problem:
When window function in aggregation function, executor would report an error like: Required field 'node_type' was not present!

Example:
SELECT SUM(MAX(c1) OVER (PARTITION BY c2, c3)) FROM test_window_in_agg;

Reason:
When analyze aggregate, analytic expr (window function carrior when analyze) transfered to slot and loss message. So when
serialize to thrift package, TExpr can not determine node_type of analytic expr.

Solved:
We do not support aggregate(window function) yet. So we report an error when analyze.
  • Loading branch information
LiBinfeng-01 authored Aug 4, 2023
1 parent b122f9b commit 265cded
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
10 changes: 10 additions & 0 deletions fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java
Original file line number Diff line number Diff line change
Expand Up @@ -1343,6 +1343,16 @@ private void analyzeAggregation(Analyzer analyzer) throws AnalysisException {
}
}

// can't contain analytic exprs
ArrayList<Expr> aggExprsForChecking = Lists.newArrayList();
TreeNode.collect(resultExprs, Expr.isAggregatePredicate(), aggExprsForChecking);
ArrayList<Expr> 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<FunctionCallExpr> aggExprs = Lists.newArrayList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;"
}


0 comments on commit 265cded

Please sign in to comment.