提交 dedefffc authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Fix possible NPE in ordered window aggregates with filter

上级 3ed3da43
......@@ -21,6 +21,8 @@ Change Log
<h2>Next Version (unreleased)</h2>
<ul>
<li>PR #1660: Optimize window aggregates with AND UNBOUNDED FOLLOWING and no exclusions
</li>
<li>PR #1656: Optimize window aggregates with ORDER BY + UNBOUNDED PRECEDING + no exclusions
</li>
<li>Issue #1654: OOM in TestMemoryUsage, in big mode
......
......@@ -345,7 +345,11 @@ public abstract class DataAnalysisOperation extends Expression {
data = partition.getData();
}
if (forOrderBy || !isAggregate()) {
return getOrderedResult(session, groupData, partition, data);
Value result = getOrderedResult(session, groupData, partition, data);
if (result == null) {
return getAggregatedValue(session, null);
}
return result;
}
// Window aggregate without ORDER BY clause in window specification
Value result = partition.getResult();
......
......@@ -107,15 +107,18 @@ SELECT ARRAY_AGG(ID ORDER BY ID) OVER (PARTITION BY NAME), NAME FROM TEST;
> [4, 5, 6] c
> rows: 6
SELECT ARRAY_AGG(ID ORDER BY ID) FILTER (WHERE ID < 3 OR ID > 4) OVER (PARTITION BY NAME), NAME FROM TEST ORDER BY NAME;
> ARRAY_AGG(ID ORDER BY ID) FILTER (WHERE ((ID < 3) OR (ID > 4))) OVER (PARTITION BY NAME) NAME
> ---------------------------------------------------------------------------------------- ----
> [1, 2] a
> [1, 2] a
> null b
> [5, 6] c
> [5, 6] c
> [5, 6] c
SELECT
ARRAY_AGG(ID ORDER BY ID) FILTER (WHERE ID < 3 OR ID > 4) OVER (PARTITION BY NAME) A,
ARRAY_AGG(ID ORDER BY ID) FILTER (WHERE ID < 3 OR ID > 4) OVER (PARTITION BY NAME ORDER BY ID) AO,
ID, NAME FROM TEST ORDER BY ID;
> A AO ID NAME
> ------ ------ -- ----
> [1, 2] [1] 1 a
> [1, 2] [1, 2] 2 a
> null null 3 b
> [5, 6] null 4 c
> [5, 6] [5] 5 c
> [5, 6] [5, 6] 6 c
> rows (ordered): 6
SELECT ARRAY_AGG(SUM(ID)) OVER () FROM TEST;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论