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

Fix Select.getGroupDataIfCurrent() for some queries

上级 11f00203
...@@ -44,6 +44,7 @@ import org.h2.table.IndexColumn; ...@@ -44,6 +44,7 @@ import org.h2.table.IndexColumn;
import org.h2.table.JoinBatch; import org.h2.table.JoinBatch;
import org.h2.table.Table; import org.h2.table.Table;
import org.h2.table.TableFilter; import org.h2.table.TableFilter;
import org.h2.table.TableFilter.TableFilterVisitor;
import org.h2.table.TableType; import org.h2.table.TableType;
import org.h2.table.TableView; import org.h2.table.TableView;
import org.h2.util.ColumnNamer; import org.h2.util.ColumnNamer;
...@@ -117,6 +118,11 @@ public class Select extends Query { ...@@ -117,6 +118,11 @@ public class Select extends Query {
*/ */
boolean[] groupByExpression; boolean[] groupByExpression;
/**
* Select with grouped data for aggregates.
*/
private Select groupSelect;
/** /**
* Grouped data for aggregates. * Grouped data for aggregates.
*/ */
...@@ -213,6 +219,10 @@ public class Select extends Query { ...@@ -213,6 +219,10 @@ public class Select extends Query {
return group; return group;
} }
void setGroupSelect(Select groupSelect) {
this.groupSelect = groupSelect;
}
/** /**
* Get the group data if there is currently a group-by active. * Get the group data if there is currently a group-by active.
* *
...@@ -220,6 +230,9 @@ public class Select extends Query { ...@@ -220,6 +230,9 @@ public class Select extends Query {
* @return the grouped data * @return the grouped data
*/ */
public SelectGroups getGroupDataIfCurrent(boolean window) { public SelectGroups getGroupDataIfCurrent(boolean window) {
if (groupSelect != null) {
return groupSelect.getGroupDataIfCurrent(window);
}
return groupData != null && (window || groupData.isCurrentGroup()) ? groupData : null; return groupData != null && (window || groupData.isCurrentGroup()) ? groupData : null;
} }
...@@ -1333,6 +1346,15 @@ public class Select extends Query { ...@@ -1333,6 +1346,15 @@ public class Select extends Query {
isGroupSortedQuery = true; isGroupSortedQuery = true;
} }
} }
topTableFilter.visit(new TableFilterVisitor() {
@Override
public void accept(TableFilter f) {
Select s = f.getSelect();
if (s != null && s != Select.this) {
s.setGroupSelect(Select.this);
}
}
});
expressionArray = expressions.toArray(new Expression[0]); expressionArray = expressions.toArray(new Expression[0]);
isPrepared = true; isPrepared = true;
} }
......
...@@ -584,3 +584,21 @@ SELECT COUNT(*) C FROM TEST QUALIFY C < 1; ...@@ -584,3 +584,21 @@ SELECT COUNT(*) C FROM TEST QUALIFY C < 1;
DROP TABLE TEST; DROP TABLE TEST;
> ok > ok
SELECT A, ROW_NUMBER() OVER (ORDER BY B) R
FROM (VALUES (1, 2), (2, 1), (3, 3)) T(A, B);
> A R
> - -
> 1 2
> 2 1
> 3 3
> rows: 3
SELECT X, A, ROW_NUMBER() OVER (ORDER BY B) R
FROM (SELECT 1 X), (VALUES (1, 2), (2, 1), (3, 3)) T(A, B);
> X A R
> - - -
> 1 1 2
> 1 2 1
> 1 3 3
> rows: 3
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论