提交 001cd637 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Fix window definition lookup in some queries

上级 f2c645a3
......@@ -1335,7 +1335,7 @@ public class Parser {
}
private Prepared parseHelp() {
Select select = new Select(session);
Select select = new Select(session, null);
select.setWildcard();
Table table = database.getSchema("INFORMATION_SCHEMA").resolveTableOrView(session, "HELP");
Function function = Function.getFunction(database, "UPPER");
......@@ -1535,7 +1535,7 @@ public class Parser {
TableFilter sourceTableFilter = readSimpleTableFilter(0, null);
command.setSourceTableFilter(sourceTableFilter);
Select preparedQuery = new Select(session);
Select preparedQuery = new Select(session, null);
preparedQuery.setWildcard();
TableFilter filter = new TableFilter(session, sourceTableFilter.getTable(),
sourceTableFilter.getTableAlias(), rightsChecked, preparedQuery, 0, null);
......@@ -2689,7 +2689,7 @@ public class Parser {
} else if (readIf(TABLE)) {
int start = lastParseIndex;
Table table = readTableOrView();
Select command = new Select(session);
Select command = new Select(session, currentSelect);
TableFilter filter = new TableFilter(session, table, null, rightsChecked,
command, orderInFrom++, null);
command.addTableFilter(filter, true);
......@@ -2703,7 +2703,7 @@ public class Parser {
} else {
throw getSyntaxError();
}
Select command = new Select(session);
Select command = new Select(session, currentSelect);
int start = lastParseIndex;
Select oldSelect = currentSelect;
Prepared oldPrepared = currentPrepared;
......@@ -5867,7 +5867,7 @@ public class Parser {
}
private Select parseValues() {
Select command = new Select(session);
Select command = new Select(session, currentSelect);
currentSelect = command;
TableFilter filter = parseValuesTable(0);
command.setWildcard();
......
......@@ -419,7 +419,7 @@ public class MergeUsing extends Prepared {
}
// setup the targetMatchQuery - for detecting if the target row exists
targetMatchQuery = new Select(session);
targetMatchQuery = new Select(session, null);
ArrayList<Expression> expressions = new ArrayList<>(1);
expressions.add(new ExpressionColumn(session.getDatabase(), targetTable.getSchema().getName(),
targetTableFilter.getTableAlias(), "_ROWID_"));
......
......@@ -78,6 +78,11 @@ public class Select extends Query {
private final ArrayList<TableFilter> filters = Utils.newSmallArrayList();
private final ArrayList<TableFilter> topFilters = Utils.newSmallArrayList();
/**
* Parent select for selects in table filters.
*/
private Select parentSelect;
/**
* WHERE condition.
*/
......@@ -146,8 +151,9 @@ public class Select extends Query {
private HashMap<String, Window> windows;
public Select(Session session) {
public Select(Session session, Select parentSelect) {
super(session);
this.parentSelect = parentSelect;
}
@Override
......@@ -1956,4 +1962,14 @@ public class Select extends Query {
return row;
}
}
/**
* Returns parent select, or null.
*
* @return parent select, or null
*/
public Select getParentSelect() {
return parentSelect;
}
}
......@@ -8,6 +8,7 @@ package org.h2.expression.analysis;
import java.util.ArrayList;
import org.h2.api.ErrorCode;
import org.h2.command.dml.Select;
import org.h2.command.dml.SelectOrderBy;
import org.h2.engine.Session;
import org.h2.expression.Expression;
......@@ -104,9 +105,13 @@ public final class Window {
private void resolveWindows(ColumnResolver resolver) {
if (parent != null) {
Window p = resolver.getSelect().getWindow(parent);
if (p == null) {
throw DbException.get(ErrorCode.WINDOW_NOT_FOUND_1, parent);
Select select = resolver.getSelect();
Window p;
while ((p = select.getWindow(parent)) == null) {
select = select.getParentSelect();
if (select == null) {
throw DbException.get(ErrorCode.WINDOW_NOT_FOUND_1, parent);
}
}
p.resolveWindows(resolver);
if (partitionBy == null) {
......
......@@ -611,6 +611,13 @@ SELECT A, SUM(S) OVER (ORDER BY S) FROM
> 3 20
> rows: 2
SELECT A, SUM(A) OVER W SUM FROM (VALUES 1, 2) T(A) WINDOW W AS (ORDER BY A);
> A SUM
> - ---
> 1 1
> 2 3
> rows: 2
SELECT A, B, C FROM (SELECT A, B, C FROM (VALUES (1, 2, 3)) V(A, B, C));
> A B C
> - - -
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论