提交 3814c595 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Split group and window methods in SelectGroups

上级 d432403d
......@@ -251,14 +251,9 @@ public abstract class SelectGroups {
*
* @param expr
* expression
* @param window
* true if expression is a window expression
* @return expression data or null
*/
public Object getCurrentGroupExprData(Expression expr, boolean window) {
if (window) {
return windowData.get(expr);
}
public final Object getCurrentGroupExprData(Expression expr) {
Integer index = exprToIndexInGroupByData.get(expr);
if (index == null) {
return null;
......@@ -273,15 +268,8 @@ public abstract class SelectGroups {
* expression
* @param object
* expression data to set
* @param window
* true if expression is a window expression
*/
public void setCurrentGroupExprData(Expression expr, Object obj, boolean window) {
if (window) {
Object old = windowData.put(expr, obj);
assert old == null;
return;
}
public final void setCurrentGroupExprData(Expression expr, Object obj) {
Integer index = exprToIndexInGroupByData.get(expr);
if (index != null) {
assert currentGroupByExprData[index] == null;
......@@ -297,6 +285,30 @@ public abstract class SelectGroups {
currentGroupByExprData[index] = obj;
}
/**
* Get the window data for the specified expression.
*
* @param expr
* expression
* @return expression data or null
*/
public final Object getWindowExprData(Expression expr) {
return windowData.get(expr);
}
/**
* Set the window data for the specified expression.
*
* @param expr
* expression
* @param object
* expression data to set
*/
public final void setWindowExprData(Expression expr, Object obj) {
Object old = windowData.put(expr, obj);
assert old == null;
}
abstract void updateCurrentGroupExprData();
/**
......
......@@ -164,9 +164,9 @@ public class ExpressionColumn extends Expression {
// this is a different level (the enclosing query)
return;
}
Value v = (Value) groupData.getCurrentGroupExprData(this, false);
Value v = (Value) groupData.getCurrentGroupExprData(this);
if (v == null) {
groupData.setCurrentGroupExprData(this, now, false);
groupData.setCurrentGroupExprData(this, now);
} else {
if (!database.areEqual(now, v)) {
throw DbException.get(ErrorCode.MUST_GROUP_BY_COLUMN_1, getSQL());
......@@ -180,7 +180,7 @@ public class ExpressionColumn extends Expression {
if (select != null) {
SelectGroups groupData = select.getGroupDataIfCurrent(false);
if (groupData != null) {
Value v = (Value) groupData.getCurrentGroupExprData(this, false);
Value v = (Value) groupData.getCurrentGroupExprData(this);
if (v != null) {
return v;
}
......
......@@ -252,13 +252,13 @@ public abstract class AbstractAggregate extends Expression {
ValueArray key = over.getCurrentKey(session);
if (key != null) {
@SuppressWarnings("unchecked")
ValueHashMap<Object> map = (ValueHashMap<Object>) groupData.getCurrentGroupExprData(this, true);
ValueHashMap<Object> map = (ValueHashMap<Object>) groupData.getWindowExprData(this);
if (map == null) {
if (ifExists) {
return null;
}
map = new ValueHashMap<>();
groupData.setCurrentGroupExprData(this, map, true);
groupData.setWindowExprData(this, map);
}
PartitionData partition = (PartitionData) map.get(key);
if (partition == null) {
......@@ -271,25 +271,25 @@ public abstract class AbstractAggregate extends Expression {
data = partition.getData();
}
} else {
PartitionData partition = (PartitionData) groupData.getCurrentGroupExprData(this, true);
PartitionData partition = (PartitionData) groupData.getWindowExprData(this);
if (partition == null) {
if (ifExists) {
return null;
}
data = forOrderBy ? new ArrayList<>() : createAggregateData();
groupData.setCurrentGroupExprData(this, new PartitionData(data), true);
groupData.setWindowExprData(this, new PartitionData(data));
} else {
data = partition.getData();
}
}
} else {
data = groupData.getCurrentGroupExprData(this, false);
data = groupData.getCurrentGroupExprData(this);
if (data == null) {
if (ifExists) {
return null;
}
data = forOrderBy ? new ArrayList<>() : createAggregateData();
groupData.setCurrentGroupExprData(this, data, false);
groupData.setCurrentGroupExprData(this, data);
}
}
return data;
......@@ -338,10 +338,10 @@ public abstract class AbstractAggregate extends Expression {
ValueArray key = over.getCurrentKey(session);
if (key != null) {
@SuppressWarnings("unchecked")
ValueHashMap<Object> map = (ValueHashMap<Object>) groupData.getCurrentGroupExprData(this, true);
ValueHashMap<Object> map = (ValueHashMap<Object>) groupData.getWindowExprData(this);
if (map == null) {
map = new ValueHashMap<>();
groupData.setCurrentGroupExprData(this, map, true);
groupData.setWindowExprData(this, map);
}
partition = (PartitionData) map.get(key);
if (partition == null) {
......@@ -352,11 +352,11 @@ public abstract class AbstractAggregate extends Expression {
data = partition.getData();
}
} else {
partition = (PartitionData) groupData.getCurrentGroupExprData(this, true);
partition = (PartitionData) groupData.getWindowExprData(this);
if (partition == null) {
data = forOrderBy ? new ArrayList<>() : createAggregateData();
partition = new PartitionData(data);
groupData.setCurrentGroupExprData(this, partition, true);
groupData.setWindowExprData(this, partition);
} else {
data = partition.getData();
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论