提交 421d27bb authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Remove Select.groupSelect and pass SelectGroups to table filters instead

上级 ae71212d
......@@ -118,11 +118,6 @@ public class Select extends Query {
*/
boolean[] groupByExpression;
/**
* Select with grouped data for aggregates.
*/
private Select groupSelect;
/**
* Grouped data for aggregates.
*/
......@@ -219,10 +214,6 @@ public class Select extends Query {
return group;
}
void setGroupSelect(Select groupSelect) {
this.groupSelect = groupSelect;
}
/**
* Get the group data if there is currently a group-by active.
*
......@@ -230,9 +221,6 @@ public class Select extends Query {
* @return the grouped data
*/
public SelectGroups getGroupDataIfCurrent(boolean window) {
if (groupSelect != null) {
return groupSelect.getGroupDataIfCurrent(window);
}
return groupData != null && (window || groupData.isCurrentGroup()) ? groupData : null;
}
......@@ -481,13 +469,26 @@ public class Select extends Query {
private void initGroupData(int columnCount) {
if (groupData == null) {
groupData = SelectGroups.getInstance(session, expressions, isGroupQuery, groupIndex);
setGroupData(SelectGroups.getInstance(session, expressions, isGroupQuery, groupIndex));
} else {
updateAgg(columnCount, DataAnalysisOperation.STAGE_RESET);
}
groupData.reset();
}
void setGroupData(final SelectGroups groupData) {
this.groupData = groupData;
topTableFilter.visit(new TableFilterVisitor() {
@Override
public void accept(TableFilter f) {
Select s = f.getSelect();
if (s != null) {
s.groupData = groupData;
}
}
});
}
private void gatherGroup(int columnCount, int stage) {
long rowNumber = 0;
setCurrentRowNumber(0);
......@@ -1346,15 +1347,6 @@ public class Select extends Query {
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]);
isPrepared = true;
}
......@@ -1910,7 +1902,8 @@ public class Select extends Query {
LazyResultGroupSorted(Expression[] expressions, int columnCount) {
super(expressions, columnCount);
if (groupData == null) {
groupData = SelectGroups.getInstance(getSession(), Select.this.expressions, isGroupQuery, groupIndex);
setGroupData(SelectGroups.getInstance(getSession(), Select.this.expressions, isGroupQuery,
groupIndex));
} else {
// TODO is this branch possible?
updateAgg(columnCount, DataAnalysisOperation.STAGE_RESET);
......
......@@ -603,6 +603,14 @@ FROM (SELECT 1 X), (VALUES (1, 2), (2, 1), (3, 3)) T(A, B);
> 1 3 3
> rows: 3
SELECT A, SUM(S) OVER (ORDER BY S) FROM
(SELECT A, SUM(B) FROM (VALUES (1, 2), (1, 3), (3, 5), (3, 10)) V(A, B) GROUP BY A) S(A, S);
> A SUM(S) OVER (ORDER BY S)
> - ------------------------
> 1 5
> 3 20
> 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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论