提交 6a604a0e authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Fix NPE in window functions with unknown columns

上级 fb889f29
......@@ -113,6 +113,7 @@ public abstract class AbstractAggregate extends Expression {
@Override
public Expression optimize(Session session) {
if (over != null) {
over.optimize(session);
ArrayList<SelectOrderBy> orderBy = over.getOrderBy();
if (orderBy != null) {
overOrderBySort = createOrder(session, orderBy, getNumExpressions());
......
......@@ -81,6 +81,25 @@ public final class Window {
}
}
/**
* Try to optimize the window conditions.
*
* @param session
* the session
*/
public void optimize(Session session) {
if (partitionBy != null) {
for (int i = 0; i < partitionBy.size(); i++) {
partitionBy.set(i, partitionBy.get(i).optimize(session));
}
}
if (orderBy != null) {
for (SelectOrderBy o : orderBy) {
o.expression = o.expression.optimize(session);
}
}
}
/**
* Tell the expression columns whether the table filter can return values
* now. This is used when optimizing the query.
......
......@@ -3,6 +3,12 @@
-- Initial Developer: H2 Group
--
SELECT FIRST_VALUE(1) OVER (PARTITION BY ID);
> exception COLUMN_NOT_FOUND_1
SELECT FIRST_VALUE(1) OVER (ORDER BY ID);
> exception COLUMN_NOT_FOUND_1
CREATE TABLE TEST (ID INT PRIMARY KEY, CATEGORY INT, VALUE INT);
> ok
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论