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

Add execution-time check for invalid grouped window queries

上级 eb22d7ff
...@@ -113,6 +113,8 @@ public class Select extends Query { ...@@ -113,6 +113,8 @@ public class Select extends Query {
private boolean isPrepared, checkInit; private boolean isPrepared, checkInit;
private boolean sortUsingIndex; private boolean sortUsingIndex;
private boolean isGroupWindowStage2;
public Select(Session session) { public Select(Session session) {
super(session); super(session);
} }
...@@ -383,7 +385,12 @@ public class Select extends Query { ...@@ -383,7 +385,12 @@ public class Select extends Query {
updateAgg(columnCount, true); updateAgg(columnCount, true);
} }
groupData.done(); groupData.done();
processGroupResult(columnCount, result, offset, quickOffset); try {
isGroupWindowStage2 = true;
processGroupResult(columnCount, result, offset, quickOffset);
} finally {
isGroupWindowStage2 = false;
}
} finally { } finally {
groupData.reset(); groupData.reset();
} }
...@@ -1462,6 +1469,16 @@ public class Select extends Query { ...@@ -1462,6 +1469,16 @@ public class Select extends Query {
return isWindowQuery; return isWindowQuery;
} }
/**
* Checks if window stage of group window query is performed. If true,
* column resolver may not be used.
*
* @return true if window stage of group window query is performed
*/
public boolean isGroupWindowStage2() {
return isGroupWindowStage2;
}
@Override @Override
public void addGlobalCondition(Parameter param, int columnId, public void addGlobalCondition(Parameter param, int columnId,
int comparisonType) { int comparisonType) {
......
...@@ -184,6 +184,9 @@ public class ExpressionColumn extends Expression { ...@@ -184,6 +184,9 @@ public class ExpressionColumn extends Expression {
if (v != null) { if (v != null) {
return v; return v;
} }
if (select.isGroupWindowStage2()) {
throw DbException.get(ErrorCode.MUST_GROUP_BY_COLUMN_1, getSQL());
}
} }
} }
Value value = columnResolver.getValue(column); Value value = columnResolver.getValue(column);
......
...@@ -158,5 +158,8 @@ SELECT ARRAY_AGG(ARRAY_AGG(ID ORDER BY ID)) OVER (PARTITION BY NAME), NAME FROM ...@@ -158,5 +158,8 @@ SELECT ARRAY_AGG(ARRAY_AGG(ID ORDER BY ID)) OVER (PARTITION BY NAME), NAME FROM
> ((4, 5, 6)) c > ((4, 5, 6)) c
> rows: 2 > rows: 2
SELECT ARRAY_AGG(ID) OVER() FROM TEST GROUP BY NAME;
> exception MUST_GROUP_BY_COLUMN_1
DROP TABLE TEST; DROP TABLE TEST;
> ok > ok
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论