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

Fix possible NPE in ordered window aggregates with filter

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