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

Split group and window methods in SelectGroups

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