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

Add AbstractAggregate as a base class

上级 aee4cfaa
......@@ -170,6 +170,7 @@ import org.h2.expression.UnaryOperation;
import org.h2.expression.ValueExpression;
import org.h2.expression.Variable;
import org.h2.expression.Wildcard;
import org.h2.expression.aggregate.AbstractAggregate;
import org.h2.expression.aggregate.Aggregate;
import org.h2.expression.aggregate.Aggregate.AggregateType;
import org.h2.expression.aggregate.JavaAggregate;
......@@ -2967,27 +2968,11 @@ public class Parser {
}
read(CLOSE_PAREN);
if (r != null) {
r.setFilterCondition(readFilterCondition());
Window over = readOver();
if (over != null) {
r.setOverCondition(over);
currentSelect.setWindowQuery();
} else {
currentSelect.setGroupQuery();
}
readFilterAndOver(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) {
ArrayList<SelectOrderBy> orderList = new ArrayList<>(1);
SelectOrderBy order = new SelectOrderBy();
......@@ -3040,28 +3025,28 @@ public class Parser {
do {
params.add(readExpression());
} while (readIfMore(true));
Expression filterCondition = readFilterCondition();
Expression[] list = params.toArray(new Expression[0]);
JavaAggregate agg = new JavaAggregate(aggregate, list, currentSelect, distinct, filterCondition);
Window over = readOver();
if (over != null) {
agg.setOverCondition(over);
currentSelect.setWindowQuery();
} else {
currentSelect.setGroupQuery();
}
JavaAggregate agg = new JavaAggregate(aggregate, list, currentSelect, distinct);
readFilterAndOver(agg);
return agg;
}
private Expression readFilterCondition() {
private void readFilterAndOver(AbstractAggregate aggregate) {
if (readIf("FILTER")) {
read(OPEN_PAREN);
read(WHERE);
Expression filterCondition = readExpression();
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) {
......
/*
* 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;
/**
* Implements the integrated aggregate functions, such as COUNT, MAX, SUM.
*/
public class Aggregate extends Expression {
public class Aggregate extends AbstractAggregate {
public enum AggregateType {
/**
......@@ -166,10 +166,6 @@ public class Aggregate extends Expression {
private int displaySize;
private int lastGroupRowId;
private Expression filterCondition;
private Window over;
/**
* Create a new aggregate object.
*
......@@ -257,24 +253,6 @@ public class Aggregate extends Expression {
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) {
int size = orderByList.size();
int[] index = new int[size];
......
......@@ -28,35 +28,22 @@ import org.h2.value.ValueNull;
/**
* This class wraps a user-defined aggregate.
*/
public class JavaAggregate extends Expression {
public class JavaAggregate extends AbstractAggregate {
private final UserAggregate userAggregate;
private final Select select;
private final Expression[] args;
private int[] argTypes;
private final boolean distinct;
private Expression filterCondition;
private Window over;
private int dataType;
private Connection userConnection;
private int lastGroupRowId;
public JavaAggregate(UserAggregate userAggregate, Expression[] args,
Select select, boolean distinct, Expression filterCondition) {
public JavaAggregate(UserAggregate userAggregate, Expression[] args, Select select, boolean distinct) {
this.userAggregate = userAggregate;
this.args = args;
this.select = select;
this.distinct = distinct;
this.filterCondition = filterCondition;
}
/**
* Sets the OVER condition.
*
* @param over OVER condition
*/
public void setOverCondition(Window over) {
this.over = over;
}
@Override
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论