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

Move some common fields and code to AbstractAggregate

上级 2a755298
......@@ -22,6 +22,7 @@ import org.h2.expression.analysis.WindowFrameExclusion;
import org.h2.expression.analysis.WindowFrameUnits;
import org.h2.table.ColumnResolver;
import org.h2.table.TableFilter;
import org.h2.value.TypeInfo;
import org.h2.value.Value;
/**
......@@ -34,13 +35,24 @@ public abstract class AbstractAggregate extends DataAnalysisOperation {
*/
protected final boolean distinct;
/**
* The arguments.
*/
protected final Expression[] args;
/**
* FILTER condition for aggregate
*/
protected Expression filterCondition;
AbstractAggregate(Select select, boolean distinct) {
/**
* The type of the result.
*/
protected TypeInfo type;
AbstractAggregate(Select select, Expression[] args, boolean distinct) {
super(select);
this.args = args;
this.distinct = distinct;
}
......@@ -59,8 +71,16 @@ public abstract class AbstractAggregate extends DataAnalysisOperation {
this.filterCondition = filterCondition;
}
@Override
public TypeInfo getType() {
return type;
}
@Override
public void mapColumnsAnalysis(ColumnResolver resolver, int level, int innerState) {
for (Expression arg : args) {
arg.mapColumns(resolver, level, innerState);
}
if (filterCondition != null) {
filterCondition.mapColumns(resolver, level, innerState);
}
......@@ -69,6 +89,9 @@ public abstract class AbstractAggregate extends DataAnalysisOperation {
@Override
public Expression optimize(Session session) {
for (int i = 0; i < args.length; i++) {
args[i] = args[i].optimize(session);
}
if (filterCondition != null) {
filterCondition = filterCondition.optimize(session);
}
......@@ -77,6 +100,9 @@ public abstract class AbstractAggregate extends DataAnalysisOperation {
@Override
public void setEvaluatable(TableFilter tableFilter, boolean b) {
for (Expression arg : args) {
arg.setEvaluatable(tableFilter, b);
}
if (filterCondition != null) {
filterCondition.setEvaluatable(tableFilter, b);
}
......
......@@ -53,10 +53,8 @@ public class Aggregate extends AbstractAggregate {
private final AggregateType aggregateType;
private final Expression[] args;
private ArrayList<SelectOrderBy> orderByList;
private SortOrder orderBySort;
private TypeInfo type;
/**
* Create a new aggregate object.
......@@ -71,12 +69,11 @@ public class Aggregate extends AbstractAggregate {
* if distinct is used
*/
public Aggregate(AggregateType aggregateType, Expression[] args, Select select, boolean distinct) {
super(select, distinct);
super(select, args, distinct);
if (distinct && aggregateType == AggregateType.COUNT_ALL) {
throw DbException.throwInternalError();
}
this.aggregateType = aggregateType;
this.args = args;
}
static {
......@@ -510,16 +507,8 @@ public class Aggregate extends AbstractAggregate {
return v.convertTo(type.getValueType());
}
@Override
public TypeInfo getType() {
return type;
}
@Override
public void mapColumnsAnalysis(ColumnResolver resolver, int level, int innerState) {
for (Expression arg : args) {
arg.mapColumns(resolver, level, innerState);
}
if (orderByList != null) {
for (SelectOrderBy o : orderByList) {
o.expression.mapColumns(resolver, level, innerState);
......@@ -531,9 +520,6 @@ public class Aggregate extends AbstractAggregate {
@Override
public Expression optimize(Session session) {
super.optimize(session);
for (int i = 0; i < args.length; i++) {
args[i] = args[i].optimize(session);
}
if (args.length == 1) {
type = args[0].getType();
}
......@@ -627,9 +613,6 @@ public class Aggregate extends AbstractAggregate {
@Override
public void setEvaluatable(TableFilter tableFilter, boolean b) {
for (Expression arg : args) {
arg.setEvaluatable(tableFilter, b);
}
if (orderByList != null) {
for (SelectOrderBy o : orderByList) {
o.expression.setEvaluatable(tableFilter, b);
......
......@@ -15,8 +15,6 @@ import org.h2.engine.UserAggregate;
import org.h2.expression.Expression;
import org.h2.expression.ExpressionVisitor;
import org.h2.message.DbException;
import org.h2.table.ColumnResolver;
import org.h2.table.TableFilter;
import org.h2.value.DataType;
import org.h2.value.TypeInfo;
import org.h2.value.Value;
......@@ -30,16 +28,13 @@ import org.h2.value.ValueRow;
public class JavaAggregate extends AbstractAggregate {
private final UserAggregate userAggregate;
private final Expression[] args;
private int[] argTypes;
private TypeInfo type;
private int dataType;
private Connection userConnection;
public JavaAggregate(UserAggregate userAggregate, Expression[] args, Select select, boolean distinct) {
super(select, distinct);
super(select, args, distinct);
this.userAggregate = userAggregate;
this.args = args;
}
@Override
......@@ -62,11 +57,6 @@ public class JavaAggregate extends AbstractAggregate {
return appendTailConditions(builder);
}
@Override
public TypeInfo getType() {
return type;
}
@Override
public boolean isEverything(ExpressionVisitor visitor) {
if (!super.isEverything(visitor)) {
......@@ -92,14 +82,6 @@ public class JavaAggregate extends AbstractAggregate {
return filterCondition == null || filterCondition.isEverything(visitor);
}
@Override
public void mapColumnsAnalysis(ColumnResolver resolver, int level, int innerState) {
for (Expression arg : args) {
arg.mapColumns(resolver, level, innerState);
}
super.mapColumnsAnalysis(resolver, level, innerState);
}
@Override
public Expression optimize(Session session) {
super.optimize(session);
......@@ -107,9 +89,7 @@ public class JavaAggregate extends AbstractAggregate {
int len = args.length;
argTypes = new int[len];
for (int i = 0; i < len; i++) {
Expression expr = args[i];
args[i] = expr.optimize(session);
int type = expr.getType().getValueType();
int type = args[i].getType().getValueType();
argTypes[i] = type;
}
try {
......@@ -122,14 +102,6 @@ public class JavaAggregate extends AbstractAggregate {
return this;
}
@Override
public void setEvaluatable(TableFilter tableFilter, boolean b) {
for (Expression e : args) {
e.setEvaluatable(tableFilter, b);
}
super.setEvaluatable(tableFilter, b);
}
private Aggregate getInstance() {
Aggregate agg = userAggregate.getInstance();
try {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论