提交 5a5f919f authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Add AbstractAggregate as a base class

上级 aee4cfaa
...@@ -170,6 +170,7 @@ import org.h2.expression.UnaryOperation; ...@@ -170,6 +170,7 @@ import org.h2.expression.UnaryOperation;
import org.h2.expression.ValueExpression; import org.h2.expression.ValueExpression;
import org.h2.expression.Variable; import org.h2.expression.Variable;
import org.h2.expression.Wildcard; import org.h2.expression.Wildcard;
import org.h2.expression.aggregate.AbstractAggregate;
import org.h2.expression.aggregate.Aggregate; import org.h2.expression.aggregate.Aggregate;
import org.h2.expression.aggregate.Aggregate.AggregateType; import org.h2.expression.aggregate.Aggregate.AggregateType;
import org.h2.expression.aggregate.JavaAggregate; import org.h2.expression.aggregate.JavaAggregate;
...@@ -2967,27 +2968,11 @@ public class Parser { ...@@ -2967,27 +2968,11 @@ public class Parser {
} }
read(CLOSE_PAREN); read(CLOSE_PAREN);
if (r != null) { if (r != null) {
r.setFilterCondition(readFilterCondition()); readFilterAndOver(r);
Window over = readOver();
if (over != null) {
r.setOverCondition(over);
currentSelect.setWindowQuery();
} else {
currentSelect.setGroupQuery();
}
} }
return r; return r;
} }
private Window readOver() {
if (readIf("OVER")) {
read(OPEN_PAREN);
read(CLOSE_PAREN);
return new Window();
}
return null;
}
private void setModeAggOrder(Aggregate r, Expression expr) { private void setModeAggOrder(Aggregate r, Expression expr) {
ArrayList<SelectOrderBy> orderList = new ArrayList<>(1); ArrayList<SelectOrderBy> orderList = new ArrayList<>(1);
SelectOrderBy order = new SelectOrderBy(); SelectOrderBy order = new SelectOrderBy();
...@@ -3040,28 +3025,28 @@ public class Parser { ...@@ -3040,28 +3025,28 @@ public class Parser {
do { do {
params.add(readExpression()); params.add(readExpression());
} while (readIfMore(true)); } while (readIfMore(true));
Expression filterCondition = readFilterCondition();
Expression[] list = params.toArray(new Expression[0]); Expression[] list = params.toArray(new Expression[0]);
JavaAggregate agg = new JavaAggregate(aggregate, list, currentSelect, distinct, filterCondition); JavaAggregate agg = new JavaAggregate(aggregate, list, currentSelect, distinct);
Window over = readOver(); readFilterAndOver(agg);
if (over != null) {
agg.setOverCondition(over);
currentSelect.setWindowQuery();
} else {
currentSelect.setGroupQuery();
}
return agg; return agg;
} }
private Expression readFilterCondition() { private void readFilterAndOver(AbstractAggregate aggregate) {
if (readIf("FILTER")) { if (readIf("FILTER")) {
read(OPEN_PAREN); read(OPEN_PAREN);
read(WHERE); read(WHERE);
Expression filterCondition = readExpression(); Expression filterCondition = readExpression();
read(CLOSE_PAREN); read(CLOSE_PAREN);
return filterCondition; aggregate.setFilterCondition(filterCondition);
}
if (readIf("OVER")) {
read(OPEN_PAREN);
read(CLOSE_PAREN);
aggregate.setOverCondition(new Window());
currentSelect.setWindowQuery();
} else {
currentSelect.setGroupQuery();
} }
return null;
} }
private AggregateType getAggregateType(String name) { private AggregateType getAggregateType(String name) {
......
/*
* Copyright 2004-2018 H2 Group. Multiple-Licensed under the MPL 2.0,
* and the EPL 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.expression.aggregate;
import org.h2.expression.Expression;
/**
* A base class for aggregates.
*/
public abstract class AbstractAggregate extends Expression {
protected Expression filterCondition;
protected Window over;
/**
* Sets the FILTER condition.
*
* @param filterCondition
* FILTER condition
*/
public void setFilterCondition(Expression filterCondition) {
this.filterCondition = filterCondition;
}
/**
* Sets the OVER condition.
*
* @param over
* OVER condition
*/
public void setOverCondition(Window over) {
this.over = over;
}
}
...@@ -42,7 +42,7 @@ import org.h2.value.ValueString; ...@@ -42,7 +42,7 @@ import org.h2.value.ValueString;
/** /**
* Implements the integrated aggregate functions, such as COUNT, MAX, SUM. * Implements the integrated aggregate functions, such as COUNT, MAX, SUM.
*/ */
public class Aggregate extends Expression { public class Aggregate extends AbstractAggregate {
public enum AggregateType { public enum AggregateType {
/** /**
...@@ -166,10 +166,6 @@ public class Aggregate extends Expression { ...@@ -166,10 +166,6 @@ public class Aggregate extends Expression {
private int displaySize; private int displaySize;
private int lastGroupRowId; private int lastGroupRowId;
private Expression filterCondition;
private Window over;
/** /**
* Create a new aggregate object. * Create a new aggregate object.
* *
...@@ -257,24 +253,6 @@ public class Aggregate extends Expression { ...@@ -257,24 +253,6 @@ public class Aggregate extends Expression {
this.groupConcatSeparator = separator; this.groupConcatSeparator = separator;
} }
/**
* Sets the FILTER condition.
*
* @param filterCondition condition
*/
public void setFilterCondition(Expression filterCondition) {
this.filterCondition = filterCondition;
}
/**
* Sets the OVER condition.
*
* @param over OVER condition
*/
public void setOverCondition(Window over) {
this.over = over;
}
private SortOrder initOrder(Session session) { private SortOrder initOrder(Session session) {
int size = orderByList.size(); int size = orderByList.size();
int[] index = new int[size]; int[] index = new int[size];
......
...@@ -28,35 +28,22 @@ import org.h2.value.ValueNull; ...@@ -28,35 +28,22 @@ import org.h2.value.ValueNull;
/** /**
* This class wraps a user-defined aggregate. * This class wraps a user-defined aggregate.
*/ */
public class JavaAggregate extends Expression { public class JavaAggregate extends AbstractAggregate {
private final UserAggregate userAggregate; private final UserAggregate userAggregate;
private final Select select; private final Select select;
private final Expression[] args; private final Expression[] args;
private int[] argTypes; private int[] argTypes;
private final boolean distinct; private final boolean distinct;
private Expression filterCondition;
private Window over;
private int dataType; private int dataType;
private Connection userConnection; private Connection userConnection;
private int lastGroupRowId; private int lastGroupRowId;
public JavaAggregate(UserAggregate userAggregate, Expression[] args, public JavaAggregate(UserAggregate userAggregate, Expression[] args, Select select, boolean distinct) {
Select select, boolean distinct, Expression filterCondition) {
this.userAggregate = userAggregate; this.userAggregate = userAggregate;
this.args = args; this.args = args;
this.select = select; this.select = select;
this.distinct = distinct; this.distinct = distinct;
this.filterCondition = filterCondition;
}
/**
* Sets the OVER condition.
*
* @param over OVER condition
*/
public void setOverCondition(Window over) {
this.over = over;
} }
@Override @Override
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论