提交 4b02e36f authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Add window stage flag to updateAggregate()

上级 4c2a4489
......@@ -276,8 +276,9 @@ public abstract class Query extends Prepared {
* Update all aggregate function values.
*
* @param s the session
* @param window true for window processing stage, false for group stage
*/
public abstract void updateAggregate(Session s);
public abstract void updateAggregate(Session s, boolean window);
/**
* Call the before triggers on all tables.
......
......@@ -369,7 +369,7 @@ public class Select extends Query {
if (isConditionMet()) {
rowNumber++;
groupData.nextSource();
updateAgg(columnCount);
updateAgg(columnCount, true);
if (sampleSize > 0 && rowNumber >= sampleSize) {
break;
}
......@@ -398,7 +398,7 @@ public class Select extends Query {
if (isConditionMet()) {
rowNumber++;
groupData.nextSource();
updateAgg(columnCount);
updateAgg(columnCount, false);
if (sampleSize > 0 && rowNumber >= sampleSize) {
break;
}
......@@ -413,11 +413,11 @@ public class Select extends Query {
}
}
private void updateAgg(int columnCount) {
private void updateAgg(int columnCount, boolean window) {
for (int i = 0; i < columnCount; i++) {
if (groupByExpression == null || !groupByExpression[i]) {
Expression expr = expressions.get(i);
expr.updateAggregate(session);
expr.updateAggregate(session, window);
}
}
}
......@@ -1482,15 +1482,15 @@ public class Select extends Query {
}
@Override
public void updateAggregate(Session s) {
public void updateAggregate(Session s, boolean window) {
for (Expression e : expressions) {
e.updateAggregate(s);
e.updateAggregate(s, window);
}
if (condition != null) {
condition.updateAggregate(s);
condition.updateAggregate(s, window);
}
if (having != null) {
having.updateAggregate(s);
having.updateAggregate(s, window);
}
}
......@@ -1686,7 +1686,7 @@ public class Select extends Query {
for (int i = 0; i < columnCount; i++) {
if (groupByExpression == null || !groupByExpression[i]) {
Expression expr = expressions.get(i);
expr.updateAggregate(getSession());
expr.updateAggregate(getSession(), false);
}
}
if (row != null) {
......
......@@ -449,9 +449,9 @@ public class SelectUnion extends Query {
}
@Override
public void updateAggregate(Session s) {
left.updateAggregate(s);
right.updateAggregate(s);
public void updateAggregate(Session s, boolean window) {
left.updateAggregate(s, window);
right.updateAggregate(s, window);
}
@Override
......
......@@ -83,8 +83,8 @@ public class Alias extends Expression {
}
@Override
public void updateAggregate(Session session) {
expr.updateAggregate(session);
public void updateAggregate(Session session, boolean window) {
expr.updateAggregate(session, window);
}
@Override
......
......@@ -436,9 +436,9 @@ public class BinaryOperation extends Expression {
}
@Override
public void updateAggregate(Session session) {
left.updateAggregate(session);
right.updateAggregate(session);
public void updateAggregate(Session session, boolean window) {
left.updateAggregate(session, window);
right.updateAggregate(session, window);
}
@Override
......
......@@ -495,11 +495,11 @@ public class CompareLike extends Condition {
}
@Override
public void updateAggregate(Session session) {
left.updateAggregate(session);
right.updateAggregate(session);
public void updateAggregate(Session session, boolean window) {
left.updateAggregate(session, window);
right.updateAggregate(session, window);
if (escape != null) {
escape.updateAggregate(session);
escape.updateAggregate(session, window);
}
}
......
......@@ -475,10 +475,10 @@ public class Comparison extends Condition {
}
@Override
public void updateAggregate(Session session) {
left.updateAggregate(session);
public void updateAggregate(Session session, boolean window) {
left.updateAggregate(session, window);
if (right != null) {
right.updateAggregate(session);
right.updateAggregate(session, window);
}
}
......
......@@ -268,9 +268,9 @@ public class ConditionAndOr extends Condition {
}
@Override
public void updateAggregate(Session session) {
left.updateAggregate(session);
right.updateAggregate(session);
public void updateAggregate(Session session, boolean window) {
left.updateAggregate(session, window);
right.updateAggregate(session, window);
}
@Override
......
......@@ -46,7 +46,7 @@ public class ConditionExists extends Condition {
}
@Override
public void updateAggregate(Session session) {
public void updateAggregate(Session session, boolean window) {
// TODO exists: is it allowed that the subquery contains aggregates?
// probably not
// select id from test group by id having exists (select * from test2
......
......@@ -163,10 +163,10 @@ public class ConditionIn extends Condition {
}
@Override
public void updateAggregate(Session session) {
left.updateAggregate(session);
public void updateAggregate(Session session, boolean window) {
left.updateAggregate(session, window);
for (Expression e : valueList) {
e.updateAggregate(session);
e.updateAggregate(session, window);
}
}
......
......@@ -125,8 +125,8 @@ public class ConditionInConstantSet extends Condition {
}
@Override
public void updateAggregate(Session session) {
left.updateAggregate(session);
public void updateAggregate(Session session, boolean window) {
left.updateAggregate(session, window);
}
@Override
......
......@@ -145,8 +145,8 @@ public class ConditionInParameter extends Condition {
}
@Override
public void updateAggregate(Session session) {
left.updateAggregate(session);
public void updateAggregate(Session session, boolean window) {
left.updateAggregate(session, window);
}
@Override
......
......@@ -146,9 +146,9 @@ public class ConditionInSelect extends Condition {
}
@Override
public void updateAggregate(Session session) {
left.updateAggregate(session);
query.updateAggregate(session);
public void updateAggregate(Session session, boolean window) {
left.updateAggregate(session, window);
query.updateAggregate(session, window);
}
@Override
......
......@@ -70,8 +70,8 @@ public class ConditionNot extends Condition {
}
@Override
public void updateAggregate(Session session) {
condition.updateAggregate(session);
public void updateAggregate(Session session, boolean window) {
condition.updateAggregate(session, window);
}
@Override
......
......@@ -105,8 +105,9 @@ public abstract class Expression {
* be used to make sure the internal state is only updated once.
*
* @param session the session
* @param window true for window processing stage, false for group stage
*/
public abstract void updateAggregate(Session session);
public abstract void updateAggregate(Session session, boolean window);
/**
* Check if this expression and all sub-expressions can fulfill a criteria.
......
......@@ -153,7 +153,7 @@ public class ExpressionColumn extends Expression {
}
@Override
public void updateAggregate(Session session) {
public void updateAggregate(Session session, boolean window) {
Value now = columnResolver.getValue(column);
Select select = columnResolver.getSelect();
if (select == null) {
......
......@@ -98,9 +98,9 @@ public class ExpressionList extends Expression {
}
@Override
public void updateAggregate(Session session) {
public void updateAggregate(Session session, boolean window) {
for (Expression e : list) {
e.updateAggregate(session);
e.updateAggregate(session, window);
}
}
......
......@@ -2633,10 +2633,10 @@ public class Function extends Expression implements FunctionCall {
}
@Override
public void updateAggregate(Session session) {
public void updateAggregate(Session session, boolean window) {
for (Expression e : args) {
if (e != null) {
e.updateAggregate(session);
e.updateAggregate(session, window);
}
}
}
......
......@@ -291,9 +291,9 @@ public class IntervalOperation extends Expression {
}
@Override
public void updateAggregate(Session session) {
left.updateAggregate(session);
right.updateAggregate(session);
public void updateAggregate(Session session, boolean window) {
left.updateAggregate(session, window);
right.updateAggregate(session, window);
}
@Override
......
......@@ -107,10 +107,10 @@ public class JavaFunction extends Expression implements FunctionCall {
}
@Override
public void updateAggregate(Session session) {
public void updateAggregate(Session session, boolean window) {
for (Expression e : args) {
if (e != null) {
e.updateAggregate(session);
e.updateAggregate(session, window);
}
}
}
......
......@@ -141,7 +141,7 @@ public class Parameter extends Expression implements ParameterInterface {
}
@Override
public void updateAggregate(Session session) {
public void updateAggregate(Session session, boolean window) {
// nothing to do
}
......
......@@ -73,7 +73,7 @@ public class Rownum extends Expression {
}
@Override
public void updateAggregate(Session session) {
public void updateAggregate(Session session, boolean window) {
// nothing to do
}
......
......@@ -72,7 +72,7 @@ public class SequenceValue extends Expression {
}
@Override
public void updateAggregate(Session session) {
public void updateAggregate(Session session, boolean window) {
// nothing to do
}
......
......@@ -94,8 +94,8 @@ public class Subquery extends Expression {
}
@Override
public void updateAggregate(Session session) {
query.updateAggregate(session);
public void updateAggregate(Session session, boolean window) {
query.updateAggregate(session, window);
}
private Expression getExpression() {
......
......@@ -82,8 +82,8 @@ public class UnaryOperation extends Expression {
}
@Override
public void updateAggregate(Session session) {
arg.updateAggregate(session);
public void updateAggregate(Session session, boolean window) {
arg.updateAggregate(session, window);
}
@Override
......
......@@ -143,7 +143,7 @@ public class ValueExpression extends Expression {
}
@Override
public void updateAggregate(Session session) {
public void updateAggregate(Session session, boolean window) {
// nothing to do
}
......
......@@ -101,7 +101,7 @@ public class Variable extends Expression {
}
@Override
public void updateAggregate(Session session) {
public void updateAggregate(Session session, boolean window) {
// nothing to do
}
......
......@@ -91,7 +91,7 @@ public class Wildcard extends Expression {
}
@Override
public void updateAggregate(Session session) {
public void updateAggregate(Session session, boolean window) {
DbException.throwInternalError(toString());
}
......
......@@ -289,12 +289,15 @@ public class Aggregate extends AbstractAggregate {
}
@Override
public void updateAggregate(Session session) {
public void updateAggregate(Session session, boolean window) {
if (window != (over != null)) {
return;
}
// TODO aggregates: check nested MIN(MAX(ID)) and so on
// if (on != null) {
// on.updateAggregate();
// }
SelectGroups groupData = select.getGroupDataIfCurrent(over != null);
SelectGroups groupData = select.getGroupDataIfCurrent(window);
if (groupData == null) {
// this is a different level (the enclosing query)
return;
......@@ -308,7 +311,7 @@ public class Aggregate extends AbstractAggregate {
lastGroupRowId = groupRowId;
if (over != null) {
over.updateAggregate(session);
over.updateAggregate(session, true);
}
if (filterCondition != null) {
if (!filterCondition.getBooleanValue(session)) {
......
......@@ -200,8 +200,11 @@ public class JavaAggregate extends AbstractAggregate {
}
@Override
public void updateAggregate(Session session) {
SelectGroups groupData = select.getGroupDataIfCurrent(over != null);
public void updateAggregate(Session session, boolean window) {
if (window != (over != null)) {
return;
}
SelectGroups groupData = select.getGroupDataIfCurrent(window);
if (groupData == null) {
// this is a different level (the enclosing query)
return;
......@@ -215,7 +218,7 @@ public class JavaAggregate extends AbstractAggregate {
lastGroupRowId = groupRowId;
if (over != null) {
over.updateAggregate(session);
over.updateAggregate(session, true);
}
if (filterCondition != null) {
if (!filterCondition.getBooleanValue(session)) {
......
......@@ -113,12 +113,13 @@ public final class Window {
*
* @param session
* the session
* @see Expression#updateAggregate(Session)
* @param window true for window processing stage, false for group stage
* @see Expression#updateAggregate(Session, boolean)
*/
public void updateAggregate(Session session) {
public void updateAggregate(Session session, boolean window) {
if (partitionBy != null) {
for (Expression expr : partitionBy) {
expr.updateAggregate(session);
expr.updateAggregate(session, window);
}
}
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论