提交 08913f79 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Extract DataAnalysisOperation from AbstractAggregate

上级 3814c595
......@@ -171,6 +171,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.DataAnalysisOperation;
import org.h2.expression.aggregate.AbstractAggregate;
import org.h2.expression.aggregate.Aggregate;
import org.h2.expression.aggregate.Aggregate.AggregateType;
......@@ -3053,23 +3054,24 @@ public class Parser {
}
private void readFilterAndOver(AbstractAggregate aggregate) {
boolean isAggregate = aggregate.isAggregate();
if (isAggregate && readIf("FILTER")) {
if (readIf("FILTER")) {
read(OPEN_PAREN);
read(WHERE);
Expression filterCondition = readExpression();
read(CLOSE_PAREN);
aggregate.setFilterCondition(filterCondition);
}
Window over = null;
readOver(aggregate);
}
private void readOver(DataAnalysisOperation operation) {
if (readIf("OVER")) {
over = readWindowNameOrSpecification();
aggregate.setOverCondition(over);
operation.setOverCondition(readWindowNameOrSpecification());
currentSelect.setWindowQuery();
} else if (!isAggregate) {
throw getSyntaxError();
} else {
} else if (operation.isAggregate()) {
currentSelect.setGroupQuery();
} else {
throw getSyntaxError();
}
}
......@@ -3440,7 +3442,7 @@ public class Parser {
default:
// Avoid warning
}
readFilterAndOver(function);
readOver(function);
return function;
}
......
......@@ -14,6 +14,7 @@ import java.util.Map.Entry;
import org.h2.engine.Session;
import org.h2.expression.Expression;
import org.h2.expression.aggregate.DataAnalysisOperation;
import org.h2.value.Value;
import org.h2.value.ValueArray;
......@@ -210,7 +211,7 @@ public abstract class SelectGroups {
/**
* Maps an expression object to its data.
*/
private final HashMap<Expression, Object> windowData = new HashMap<>();
private final HashMap<DataAnalysisOperation, Object> windowData = new HashMap<>();
/**
* The id of the current group.
......@@ -292,7 +293,7 @@ public abstract class SelectGroups {
* expression
* @return expression data or null
*/
public final Object getWindowExprData(Expression expr) {
public final Object getWindowExprData(DataAnalysisOperation expr) {
return windowData.get(expr);
}
......@@ -304,7 +305,7 @@ public abstract class SelectGroups {
* @param object
* expression data to set
*/
public final void setWindowExprData(Expression expr, Object obj) {
public final void setWindowExprData(DataAnalysisOperation expr, Object obj) {
Object old = windowData.put(expr, obj);
assert old == null;
}
......
......@@ -251,11 +251,6 @@ public class Aggregate extends AbstractAggregate {
return AGGREGATES.get(name);
}
@Override
public boolean isAggregate() {
return true;
}
/**
* Set the order for ARRAY_AGG() or GROUP_CONCAT() aggregate.
*
......@@ -312,6 +307,7 @@ public class Aggregate extends AbstractAggregate {
@Override
protected void updateGroupAggregates(Session session, int stage) {
super.updateGroupAggregates(session, stage);
if (on != null) {
on.updateAggregate(session, stage);
}
......@@ -514,9 +510,6 @@ public class Aggregate extends AbstractAggregate {
if (groupConcatSeparator != null) {
groupConcatSeparator = groupConcatSeparator.optimize(session);
}
if (filterCondition != null) {
filterCondition = filterCondition.optimize(session);
}
switch (type) {
case GROUP_CONCAT:
dataType = Value.STRING;
......
......@@ -40,11 +40,6 @@ public class JavaAggregate extends AbstractAggregate {
this.args = args;
}
@Override
public boolean isAggregate() {
return true;
}
@Override
public int getCost() {
int cost = 5;
......@@ -140,9 +135,6 @@ public class JavaAggregate extends AbstractAggregate {
} catch (SQLException e) {
throw DbException.convert(e);
}
if (filterCondition != null) {
filterCondition = filterCondition.optimize(session);
}
return this;
}
......@@ -237,6 +229,7 @@ public class JavaAggregate extends AbstractAggregate {
@Override
protected void updateGroupAggregates(Session session, int stage) {
super.updateGroupAggregates(session, stage);
for (Expression expr : args) {
expr.updateAggregate(session, stage);
}
......
......@@ -10,6 +10,7 @@ import java.util.HashMap;
import java.util.Iterator;
import org.h2.command.dml.Select;
import org.h2.command.dml.SelectGroups;
import org.h2.command.dml.SelectOrderBy;
import org.h2.engine.Session;
import org.h2.expression.Expression;
......@@ -24,7 +25,7 @@ import org.h2.value.ValueNull;
/**
* A window function.
*/
public class WindowFunction extends AbstractAggregate {
public class WindowFunction extends DataAnalysisOperation {
private final WindowFunctionType type;
......@@ -105,7 +106,7 @@ public class WindowFunction extends AbstractAggregate {
* arguments, or null
*/
public WindowFunction(WindowFunctionType type, Select select, Expression[] args) {
super(select, false);
super(select);
this.type = type;
this.args = args;
}
......@@ -145,12 +146,13 @@ public class WindowFunction extends AbstractAggregate {
}
@Override
protected void updateAggregate(Session session, Object aggregateData) {
throw DbException.getUnsupportedException("Window function");
protected void updateAggregate(Session session, SelectGroups groupData, int groupRowId) {
updateOrderedAggregate(session, groupData, groupRowId, over.getOrderBy());
}
@Override
protected void updateGroupAggregates(Session session, int stage) {
super.updateGroupAggregates(session, stage);
if (args != null) {
for (Expression expr : args) {
expr.updateAggregate(session, stage);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论