Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
e8b7f57d
Unverified
提交
e8b7f57d
authored
9月 23, 2018
作者:
Evgenij Ryazanov
提交者:
GitHub
9月 23, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1469 from katzyn/window
Forbid incorrect nesting of aggregates and window functions
上级
f30a0ba7
0d26b305
隐藏空白字符变更
内嵌
并排
正在显示
41 个修改的文件
包含
132 行增加
和
93 行删除
+132
-93
AlterTableAddConstraint.java
h2/src/main/org/h2/command/ddl/AlterTableAddConstraint.java
+1
-1
Delete.java
h2/src/main/org/h2/command/dml/Delete.java
+2
-2
Insert.java
h2/src/main/org/h2/command/dml/Insert.java
+1
-1
MergeUsing.java
h2/src/main/org/h2/command/dml/MergeUsing.java
+2
-2
Select.java
h2/src/main/org/h2/command/dml/Select.java
+3
-3
Update.java
h2/src/main/org/h2/command/dml/Update.java
+3
-3
Alias.java
h2/src/main/org/h2/expression/Alias.java
+2
-2
BinaryOperation.java
h2/src/main/org/h2/expression/BinaryOperation.java
+3
-3
CompareLike.java
h2/src/main/org/h2/expression/CompareLike.java
+4
-4
Comparison.java
h2/src/main/org/h2/expression/Comparison.java
+3
-3
ConditionAndOr.java
h2/src/main/org/h2/expression/ConditionAndOr.java
+3
-3
ConditionExists.java
h2/src/main/org/h2/expression/ConditionExists.java
+1
-1
ConditionIn.java
h2/src/main/org/h2/expression/ConditionIn.java
+3
-3
ConditionInConstantSet.java
h2/src/main/org/h2/expression/ConditionInConstantSet.java
+2
-2
ConditionInParameter.java
h2/src/main/org/h2/expression/ConditionInParameter.java
+2
-2
ConditionInSelect.java
h2/src/main/org/h2/expression/ConditionInSelect.java
+2
-2
ConditionNot.java
h2/src/main/org/h2/expression/ConditionNot.java
+2
-2
Expression.java
h2/src/main/org/h2/expression/Expression.java
+20
-1
ExpressionColumn.java
h2/src/main/org/h2/expression/ExpressionColumn.java
+1
-1
ExpressionList.java
h2/src/main/org/h2/expression/ExpressionList.java
+2
-2
Function.java
h2/src/main/org/h2/expression/Function.java
+2
-2
IntervalOperation.java
h2/src/main/org/h2/expression/IntervalOperation.java
+3
-3
JavaFunction.java
h2/src/main/org/h2/expression/JavaFunction.java
+2
-2
Parameter.java
h2/src/main/org/h2/expression/Parameter.java
+1
-1
Rownum.java
h2/src/main/org/h2/expression/Rownum.java
+1
-1
SequenceValue.java
h2/src/main/org/h2/expression/SequenceValue.java
+1
-1
Subquery.java
h2/src/main/org/h2/expression/Subquery.java
+1
-1
UnaryOperation.java
h2/src/main/org/h2/expression/UnaryOperation.java
+2
-2
ValueExpression.java
h2/src/main/org/h2/expression/ValueExpression.java
+1
-1
Variable.java
h2/src/main/org/h2/expression/Variable.java
+1
-1
Wildcard.java
h2/src/main/org/h2/expression/Wildcard.java
+1
-1
AbstractAggregate.java
...c/main/org/h2/expression/aggregate/AbstractAggregate.java
+3
-3
Aggregate.java
h2/src/main/org/h2/expression/aggregate/Aggregate.java
+5
-5
DataAnalysisOperation.java
...in/org/h2/expression/aggregate/DataAnalysisOperation.java
+17
-6
JavaAggregate.java
h2/src/main/org/h2/expression/aggregate/JavaAggregate.java
+3
-3
PartitionData.java
h2/src/main/org/h2/expression/aggregate/PartitionData.java
+3
-1
Window.java
h2/src/main/org/h2/expression/aggregate/Window.java
+3
-3
WindowFunction.java
h2/src/main/org/h2/expression/aggregate/WindowFunction.java
+4
-6
Column.java
h2/src/main/org/h2/table/Column.java
+3
-3
TableFilter.java
h2/src/main/org/h2/table/TableFilter.java
+4
-4
window.sql
h2/src/test/org/h2/test/scripts/window.sql
+9
-0
没有找到文件。
h2/src/main/org/h2/command/ddl/AlterTableAddConstraint.java
浏览文件 @
e8b7f57d
...
...
@@ -191,7 +191,7 @@ public class AlterTableAddConstraint extends SchemaCommand {
String
name
=
generateConstraintName
(
table
);
ConstraintCheck
check
=
new
ConstraintCheck
(
getSchema
(),
id
,
name
,
table
);
TableFilter
filter
=
new
TableFilter
(
session
,
table
,
null
,
false
,
null
,
0
,
null
);
checkExpression
.
mapColumns
(
filter
,
0
);
checkExpression
.
mapColumns
(
filter
,
0
,
Expression
.
MAP_INITIAL
);
checkExpression
=
checkExpression
.
optimize
(
session
);
check
.
setExpression
(
checkExpression
);
check
.
setTableFilter
(
filter
);
...
...
h2/src/main/org/h2/command/dml/Delete.java
浏览文件 @
e8b7f57d
...
...
@@ -133,9 +133,9 @@ public class Delete extends Prepared {
@Override
public
void
prepare
()
{
if
(
condition
!=
null
)
{
condition
.
mapColumns
(
targetTableFilter
,
0
);
condition
.
mapColumns
(
targetTableFilter
,
0
,
Expression
.
MAP_INITIAL
);
if
(
sourceTableFilter
!=
null
)
{
condition
.
mapColumns
(
sourceTableFilter
,
0
);
condition
.
mapColumns
(
sourceTableFilter
,
0
,
Expression
.
MAP_INITIAL
);
}
condition
=
condition
.
optimize
(
session
);
condition
.
createIndexConditions
(
session
,
targetTableFilter
);
...
...
h2/src/main/org/h2/command/dml/Insert.java
浏览文件 @
e8b7f57d
...
...
@@ -333,7 +333,7 @@ public class Insert extends Prepared implements ResultTarget {
Expression
e
=
expr
[
i
];
if
(
e
!=
null
)
{
if
(
sourceTableFilter
!=
null
){
e
.
mapColumns
(
sourceTableFilter
,
0
);
e
.
mapColumns
(
sourceTableFilter
,
0
,
Expression
.
MAP_INITIAL
);
}
e
=
e
.
optimize
(
session
);
if
(
e
instanceof
Parameter
)
{
...
...
h2/src/main/org/h2/command/dml/MergeUsing.java
浏览文件 @
e8b7f57d
...
...
@@ -319,8 +319,8 @@ public class MergeUsing extends Prepared {
onCondition
.
addFilterConditions
(
sourceTableFilter
,
true
);
onCondition
.
addFilterConditions
(
targetTableFilter
,
true
);
onCondition
.
mapColumns
(
sourceTableFilter
,
2
);
onCondition
.
mapColumns
(
targetTableFilter
,
1
);
onCondition
.
mapColumns
(
sourceTableFilter
,
2
,
Expression
.
MAP_INITIAL
);
onCondition
.
mapColumns
(
targetTableFilter
,
1
,
Expression
.
MAP_INITIAL
);
if
(
keys
==
null
)
{
keys
=
buildColumnListFromOnCondition
(
targetTableFilter
.
getTable
());
...
...
h2/src/main/org/h2/command/dml/Select.java
浏览文件 @
e8b7f57d
...
...
@@ -1043,7 +1043,7 @@ public class Select extends Query {
if
(
havingIndex
>=
0
)
{
Expression
expr
=
expressions
.
get
(
havingIndex
);
SelectListColumnResolver
res
=
new
SelectListColumnResolver
(
this
);
expr
.
mapColumns
(
res
,
0
);
expr
.
mapColumns
(
res
,
0
,
Expression
.
MAP_INITIAL
);
}
checkInit
=
true
;
}
...
...
@@ -1448,10 +1448,10 @@ public class Select extends Query {
@Override
public
void
mapColumns
(
ColumnResolver
resolver
,
int
level
)
{
for
(
Expression
e
:
expressions
)
{
e
.
mapColumns
(
resolver
,
level
);
e
.
mapColumns
(
resolver
,
level
,
Expression
.
MAP_INITIAL
);
}
if
(
condition
!=
null
)
{
condition
.
mapColumns
(
resolver
,
level
);
condition
.
mapColumns
(
resolver
,
level
,
Expression
.
MAP_INITIAL
);
}
}
...
...
h2/src/main/org/h2/command/dml/Update.java
浏览文件 @
e8b7f57d
...
...
@@ -216,15 +216,15 @@ public class Update extends Prepared {
@Override
public
void
prepare
()
{
if
(
condition
!=
null
)
{
condition
.
mapColumns
(
targetTableFilter
,
0
);
condition
.
mapColumns
(
targetTableFilter
,
0
,
Expression
.
MAP_INITIAL
);
condition
=
condition
.
optimize
(
session
);
condition
.
createIndexConditions
(
session
,
targetTableFilter
);
}
for
(
Column
c
:
columns
)
{
Expression
e
=
expressionMap
.
get
(
c
);
e
.
mapColumns
(
targetTableFilter
,
0
);
e
.
mapColumns
(
targetTableFilter
,
0
,
Expression
.
MAP_INITIAL
);
if
(
sourceTableFilter
!=
null
){
e
.
mapColumns
(
sourceTableFilter
,
0
);
e
.
mapColumns
(
sourceTableFilter
,
0
,
Expression
.
MAP_INITIAL
);
}
expressionMap
.
put
(
c
,
e
.
optimize
(
session
));
}
...
...
h2/src/main/org/h2/expression/Alias.java
浏览文件 @
e8b7f57d
...
...
@@ -42,8 +42,8 @@ public class Alias extends Expression {
}
@Override
public
void
mapColumns
(
ColumnResolver
resolver
,
int
level
)
{
expr
.
mapColumns
(
resolver
,
level
);
public
void
mapColumns
(
ColumnResolver
resolver
,
int
level
,
int
state
)
{
expr
.
mapColumns
(
resolver
,
level
,
state
);
}
@Override
...
...
h2/src/main/org/h2/expression/BinaryOperation.java
浏览文件 @
e8b7f57d
...
...
@@ -150,9 +150,9 @@ public class BinaryOperation extends Expression {
}
@Override
public
void
mapColumns
(
ColumnResolver
resolver
,
int
level
)
{
left
.
mapColumns
(
resolver
,
level
);
right
.
mapColumns
(
resolver
,
level
);
public
void
mapColumns
(
ColumnResolver
resolver
,
int
level
,
int
state
)
{
left
.
mapColumns
(
resolver
,
level
,
state
);
right
.
mapColumns
(
resolver
,
level
,
state
);
}
@Override
...
...
h2/src/main/org/h2/expression/CompareLike.java
浏览文件 @
e8b7f57d
...
...
@@ -477,11 +477,11 @@ public class CompareLike extends Condition {
}
@Override
public
void
mapColumns
(
ColumnResolver
resolver
,
int
level
)
{
left
.
mapColumns
(
resolver
,
level
);
right
.
mapColumns
(
resolver
,
level
);
public
void
mapColumns
(
ColumnResolver
resolver
,
int
level
,
int
state
)
{
left
.
mapColumns
(
resolver
,
level
,
state
);
right
.
mapColumns
(
resolver
,
level
,
state
);
if
(
escape
!=
null
)
{
escape
.
mapColumns
(
resolver
,
level
);
escape
.
mapColumns
(
resolver
,
level
,
state
);
}
}
...
...
h2/src/main/org/h2/expression/Comparison.java
浏览文件 @
e8b7f57d
...
...
@@ -497,10 +497,10 @@ public class Comparison extends Condition {
}
@Override
public
void
mapColumns
(
ColumnResolver
resolver
,
int
level
)
{
left
.
mapColumns
(
resolver
,
level
);
public
void
mapColumns
(
ColumnResolver
resolver
,
int
level
,
int
state
)
{
left
.
mapColumns
(
resolver
,
level
,
state
);
if
(
right
!=
null
)
{
right
.
mapColumns
(
resolver
,
level
);
right
.
mapColumns
(
resolver
,
level
,
state
);
}
}
...
...
h2/src/main/org/h2/expression/ConditionAndOr.java
浏览文件 @
e8b7f57d
...
...
@@ -256,9 +256,9 @@ public class ConditionAndOr extends Condition {
}
@Override
public
void
mapColumns
(
ColumnResolver
resolver
,
int
level
)
{
left
.
mapColumns
(
resolver
,
level
);
right
.
mapColumns
(
resolver
,
level
);
public
void
mapColumns
(
ColumnResolver
resolver
,
int
level
,
int
state
)
{
left
.
mapColumns
(
resolver
,
level
,
state
);
right
.
mapColumns
(
resolver
,
level
,
state
);
}
@Override
...
...
h2/src/main/org/h2/expression/ConditionExists.java
浏览文件 @
e8b7f57d
...
...
@@ -54,7 +54,7 @@ public class ConditionExists extends Condition {
}
@Override
public
void
mapColumns
(
ColumnResolver
resolver
,
int
level
)
{
public
void
mapColumns
(
ColumnResolver
resolver
,
int
level
,
int
state
)
{
query
.
mapColumns
(
resolver
,
level
+
1
);
}
...
...
h2/src/main/org/h2/expression/ConditionIn.java
浏览文件 @
e8b7f57d
...
...
@@ -66,10 +66,10 @@ public class ConditionIn extends Condition {
}
@Override
public
void
mapColumns
(
ColumnResolver
resolver
,
int
level
)
{
left
.
mapColumns
(
resolver
,
level
);
public
void
mapColumns
(
ColumnResolver
resolver
,
int
level
,
int
state
)
{
left
.
mapColumns
(
resolver
,
level
,
state
);
for
(
Expression
e
:
valueList
)
{
e
.
mapColumns
(
resolver
,
level
);
e
.
mapColumns
(
resolver
,
level
,
state
);
}
this
.
queryLevel
=
Math
.
max
(
level
,
this
.
queryLevel
);
}
...
...
h2/src/main/org/h2/expression/ConditionInConstantSet.java
浏览文件 @
e8b7f57d
...
...
@@ -83,8 +83,8 @@ public class ConditionInConstantSet extends Condition {
}
@Override
public
void
mapColumns
(
ColumnResolver
resolver
,
int
level
)
{
left
.
mapColumns
(
resolver
,
level
);
public
void
mapColumns
(
ColumnResolver
resolver
,
int
level
,
int
state
)
{
left
.
mapColumns
(
resolver
,
level
,
state
);
this
.
queryLevel
=
Math
.
max
(
level
,
this
.
queryLevel
);
}
...
...
h2/src/main/org/h2/expression/ConditionInParameter.java
浏览文件 @
e8b7f57d
...
...
@@ -109,8 +109,8 @@ public class ConditionInParameter extends Condition {
}
@Override
public
void
mapColumns
(
ColumnResolver
resolver
,
int
level
)
{
left
.
mapColumns
(
resolver
,
level
);
public
void
mapColumns
(
ColumnResolver
resolver
,
int
level
,
int
state
)
{
left
.
mapColumns
(
resolver
,
level
,
state
);
}
@Override
...
...
h2/src/main/org/h2/expression/ConditionInSelect.java
浏览文件 @
e8b7f57d
...
...
@@ -101,8 +101,8 @@ public class ConditionInSelect extends Condition {
}
@Override
public
void
mapColumns
(
ColumnResolver
resolver
,
int
level
)
{
left
.
mapColumns
(
resolver
,
level
);
public
void
mapColumns
(
ColumnResolver
resolver
,
int
level
,
int
state
)
{
left
.
mapColumns
(
resolver
,
level
,
state
);
query
.
mapColumns
(
resolver
,
level
+
1
);
this
.
queryLevel
=
Math
.
max
(
level
,
this
.
queryLevel
);
}
...
...
h2/src/main/org/h2/expression/ConditionNot.java
浏览文件 @
e8b7f57d
...
...
@@ -37,8 +37,8 @@ public class ConditionNot extends Condition {
}
@Override
public
void
mapColumns
(
ColumnResolver
resolver
,
int
level
)
{
condition
.
mapColumns
(
resolver
,
level
);
public
void
mapColumns
(
ColumnResolver
resolver
,
int
level
,
int
state
)
{
condition
.
mapColumns
(
resolver
,
level
,
state
);
}
@Override
...
...
h2/src/main/org/h2/expression/Expression.java
浏览文件 @
e8b7f57d
...
...
@@ -24,6 +24,23 @@ import org.h2.value.ValueArray;
*/
public
abstract
class
Expression
{
/**
* Initial state for {@link #mapColumns(ColumnResolver, int, int)}.
*/
public
static
final
int
MAP_INITIAL
=
0
;
/**
* State for expressions inside a window function for
* {@link #mapColumns(ColumnResolver, int, int)}.
*/
public
static
final
int
MAP_IN_WINDOW
=
1
;
/**
* State for expressions inside an aggregate for
* {@link #mapColumns(ColumnResolver, int, int)}.
*/
public
static
final
int
MAP_IN_AGGREGATE
=
2
;
private
boolean
addedToFilter
;
/**
...
...
@@ -47,8 +64,10 @@ public abstract class Expression {
*
* @param resolver the column resolver
* @param level the subquery nesting level
* @param state current state for nesting checks, initial value is
* {@link #MAP_INITIAL}
*/
public
abstract
void
mapColumns
(
ColumnResolver
resolver
,
int
level
);
public
abstract
void
mapColumns
(
ColumnResolver
resolver
,
int
level
,
int
state
);
/**
* Try to optimize the expression.
...
...
h2/src/main/org/h2/expression/ExpressionColumn.java
浏览文件 @
e8b7f57d
...
...
@@ -79,7 +79,7 @@ public class ExpressionColumn extends Expression {
}
@Override
public
void
mapColumns
(
ColumnResolver
resolver
,
int
level
)
{
public
void
mapColumns
(
ColumnResolver
resolver
,
int
level
,
int
state
)
{
if
(
tableAlias
!=
null
&&
!
database
.
equalsIdentifiers
(
tableAlias
,
resolver
.
getTableAlias
()))
{
return
;
...
...
h2/src/main/org/h2/expression/ExpressionList.java
浏览文件 @
e8b7f57d
...
...
@@ -40,9 +40,9 @@ public class ExpressionList extends Expression {
}
@Override
public
void
mapColumns
(
ColumnResolver
resolver
,
int
level
)
{
public
void
mapColumns
(
ColumnResolver
resolver
,
int
level
,
int
state
)
{
for
(
Expression
e
:
list
)
{
e
.
mapColumns
(
resolver
,
level
);
e
.
mapColumns
(
resolver
,
level
,
state
);
}
}
...
...
h2/src/main/org/h2/expression/Function.java
浏览文件 @
e8b7f57d
...
...
@@ -2062,10 +2062,10 @@ public class Function extends Expression implements FunctionCall {
}
@Override
public
void
mapColumns
(
ColumnResolver
resolver
,
int
level
)
{
public
void
mapColumns
(
ColumnResolver
resolver
,
int
level
,
int
state
)
{
for
(
Expression
e
:
args
)
{
if
(
e
!=
null
)
{
e
.
mapColumns
(
resolver
,
level
);
e
.
mapColumns
(
resolver
,
level
,
state
);
}
}
}
...
...
h2/src/main/org/h2/expression/IntervalOperation.java
浏览文件 @
e8b7f57d
...
...
@@ -249,10 +249,10 @@ public class IntervalOperation extends Expression {
}
@Override
public
void
mapColumns
(
ColumnResolver
resolver
,
int
level
)
{
left
.
mapColumns
(
resolver
,
level
);
public
void
mapColumns
(
ColumnResolver
resolver
,
int
level
,
int
state
)
{
left
.
mapColumns
(
resolver
,
level
,
state
);
if
(
right
!=
null
)
{
right
.
mapColumns
(
resolver
,
level
);
right
.
mapColumns
(
resolver
,
level
,
state
);
}
}
...
...
h2/src/main/org/h2/expression/JavaFunction.java
浏览文件 @
e8b7f57d
...
...
@@ -44,9 +44,9 @@ public class JavaFunction extends Expression implements FunctionCall {
}
@Override
public
void
mapColumns
(
ColumnResolver
resolver
,
int
level
)
{
public
void
mapColumns
(
ColumnResolver
resolver
,
int
level
,
int
state
)
{
for
(
Expression
e
:
args
)
{
e
.
mapColumns
(
resolver
,
level
);
e
.
mapColumns
(
resolver
,
level
,
state
);
}
}
...
...
h2/src/main/org/h2/expression/Parameter.java
浏览文件 @
e8b7f57d
...
...
@@ -71,7 +71,7 @@ public class Parameter extends Expression implements ParameterInterface {
}
@Override
public
void
mapColumns
(
ColumnResolver
resolver
,
int
level
)
{
public
void
mapColumns
(
ColumnResolver
resolver
,
int
level
,
int
state
)
{
// can't map
}
...
...
h2/src/main/org/h2/expression/Rownum.java
浏览文件 @
e8b7f57d
...
...
@@ -38,7 +38,7 @@ public class Rownum extends Expression {
}
@Override
public
void
mapColumns
(
ColumnResolver
resolver
,
int
level
)
{
public
void
mapColumns
(
ColumnResolver
resolver
,
int
level
,
int
state
)
{
// nothing to do
}
...
...
h2/src/main/org/h2/expression/SequenceValue.java
浏览文件 @
e8b7f57d
...
...
@@ -37,7 +37,7 @@ public class SequenceValue extends Expression {
}
@Override
public
void
mapColumns
(
ColumnResolver
resolver
,
int
level
)
{
public
void
mapColumns
(
ColumnResolver
resolver
,
int
level
,
int
state
)
{
// nothing to do
}
...
...
h2/src/main/org/h2/expression/Subquery.java
浏览文件 @
e8b7f57d
...
...
@@ -58,7 +58,7 @@ public class Subquery extends Expression {
}
@Override
public
void
mapColumns
(
ColumnResolver
resolver
,
int
level
)
{
public
void
mapColumns
(
ColumnResolver
resolver
,
int
level
,
int
state
)
{
query
.
mapColumns
(
resolver
,
level
+
1
);
}
...
...
h2/src/main/org/h2/expression/UnaryOperation.java
浏览文件 @
e8b7f57d
...
...
@@ -37,8 +37,8 @@ public class UnaryOperation extends Expression {
}
@Override
public
void
mapColumns
(
ColumnResolver
resolver
,
int
level
)
{
arg
.
mapColumns
(
resolver
,
level
);
public
void
mapColumns
(
ColumnResolver
resolver
,
int
level
,
int
state
)
{
arg
.
mapColumns
(
resolver
,
level
,
state
);
}
@Override
...
...
h2/src/main/org/h2/expression/ValueExpression.java
浏览文件 @
e8b7f57d
...
...
@@ -95,7 +95,7 @@ public class ValueExpression extends Expression {
}
@Override
public
void
mapColumns
(
ColumnResolver
resolver
,
int
level
)
{
public
void
mapColumns
(
ColumnResolver
resolver
,
int
level
,
int
state
)
{
// nothing to do
}
...
...
h2/src/main/org/h2/expression/Variable.java
浏览文件 @
e8b7f57d
...
...
@@ -86,7 +86,7 @@ public class Variable extends Expression {
}
@Override
public
void
mapColumns
(
ColumnResolver
resolver
,
int
level
)
{
public
void
mapColumns
(
ColumnResolver
resolver
,
int
level
,
int
state
)
{
// nothing to do
}
...
...
h2/src/main/org/h2/expression/Wildcard.java
浏览文件 @
e8b7f57d
...
...
@@ -43,7 +43,7 @@ public class Wildcard extends Expression {
}
@Override
public
void
mapColumns
(
ColumnResolver
resolver
,
int
level
)
{
public
void
mapColumns
(
ColumnResolver
resolver
,
int
level
,
int
state
)
{
throw
DbException
.
get
(
ErrorCode
.
SYNTAX_ERROR_1
,
table
);
}
...
...
h2/src/main/org/h2/expression/aggregate/AbstractAggregate.java
浏览文件 @
e8b7f57d
...
...
@@ -48,11 +48,11 @@ public abstract class AbstractAggregate extends DataAnalysisOperation {
}
@Override
public
void
mapColumns
(
ColumnResolver
resolver
,
int
level
)
{
public
void
mapColumns
Analysis
(
ColumnResolver
resolver
,
int
level
,
int
innerState
)
{
if
(
filterCondition
!=
null
)
{
filterCondition
.
mapColumns
(
resolver
,
level
);
filterCondition
.
mapColumns
(
resolver
,
level
,
innerState
);
}
super
.
mapColumns
(
resolver
,
level
);
super
.
mapColumns
Analysis
(
resolver
,
level
,
innerState
);
}
@Override
...
...
h2/src/main/org/h2/expression/aggregate/Aggregate.java
浏览文件 @
e8b7f57d
...
...
@@ -512,19 +512,19 @@ public class Aggregate extends AbstractAggregate {
}
@Override
public
void
mapColumns
(
ColumnResolver
resolver
,
int
level
)
{
public
void
mapColumns
Analysis
(
ColumnResolver
resolver
,
int
level
,
int
innerState
)
{
if
(
on
!=
null
)
{
on
.
mapColumns
(
resolver
,
level
);
on
.
mapColumns
(
resolver
,
level
,
innerState
);
}
if
(
orderByList
!=
null
)
{
for
(
SelectOrderBy
o
:
orderByList
)
{
o
.
expression
.
mapColumns
(
resolver
,
level
);
o
.
expression
.
mapColumns
(
resolver
,
level
,
innerState
);
}
}
if
(
groupConcatSeparator
!=
null
)
{
groupConcatSeparator
.
mapColumns
(
resolver
,
level
);
groupConcatSeparator
.
mapColumns
(
resolver
,
level
,
innerState
);
}
super
.
mapColumns
(
resolver
,
level
);
super
.
mapColumns
Analysis
(
resolver
,
level
,
innerState
);
}
@Override
...
...
h2/src/main/org/h2/expression/aggregate/DataAnalysisOperation.java
浏览文件 @
e8b7f57d
...
...
@@ -81,7 +81,22 @@ public abstract class DataAnalysisOperation extends Expression {
}
@Override
public
void
mapColumns
(
ColumnResolver
resolver
,
int
level
)
{
public
final
void
mapColumns
(
ColumnResolver
resolver
,
int
level
,
int
state
)
{
if
(
over
!=
null
)
{
if
(
state
!=
MAP_INITIAL
)
{
throw
DbException
.
get
(
ErrorCode
.
INVALID_USE_OF_AGGREGATE_FUNCTION_1
,
getSQL
());
}
state
=
MAP_IN_WINDOW
;
}
else
{
if
(
state
==
MAP_IN_AGGREGATE
)
{
throw
DbException
.
get
(
ErrorCode
.
INVALID_USE_OF_AGGREGATE_FUNCTION_1
,
getSQL
());
}
state
=
MAP_IN_AGGREGATE
;
}
mapColumnsAnalysis
(
resolver
,
level
,
state
);
}
protected
void
mapColumnsAnalysis
(
ColumnResolver
resolver
,
int
level
,
int
innerState
)
{
if
(
over
!=
null
)
{
over
.
mapColumns
(
resolver
,
level
);
}
...
...
@@ -109,7 +124,7 @@ public abstract class DataAnalysisOperation extends Expression {
}
@Override
public
void
updateAggregate
(
Session
session
,
int
stage
)
{
public
final
void
updateAggregate
(
Session
session
,
int
stage
)
{
if
(
stage
==
Aggregate
.
STAGE_RESET
)
{
updateGroupAggregates
(
session
,
Aggregate
.
STAGE_RESET
);
lastGroupRowId
=
0
;
...
...
@@ -122,10 +137,6 @@ public abstract class DataAnalysisOperation extends Expression {
}
return
;
}
// TODO aggregates: check nested MIN(MAX(ID)) and so on
// if (on != null) {
// on.updateAggregate();
// }
SelectGroups
groupData
=
select
.
getGroupDataIfCurrent
(
window
);
if
(
groupData
==
null
)
{
// this is a different level (the enclosing query)
...
...
h2/src/main/org/h2/expression/aggregate/JavaAggregate.java
浏览文件 @
e8b7f57d
...
...
@@ -110,11 +110,11 @@ public class JavaAggregate extends AbstractAggregate {
}
@Override
public
void
mapColumns
(
ColumnResolver
resolver
,
int
level
)
{
public
void
mapColumns
Analysis
(
ColumnResolver
resolver
,
int
level
,
int
innerState
)
{
for
(
Expression
arg
:
args
)
{
arg
.
mapColumns
(
resolver
,
level
);
arg
.
mapColumns
(
resolver
,
level
,
innerState
);
}
super
.
mapColumns
(
resolver
,
level
);
super
.
mapColumns
Analysis
(
resolver
,
level
,
innerState
);
}
@Override
...
...
h2/src/main/org/h2/expression/aggregate/PartitionData.java
浏览文件 @
e8b7f57d
...
...
@@ -17,7 +17,7 @@ public final class PartitionData {
/**
* Aggregate data.
*/
private
final
Object
data
;
private
Object
data
;
/**
* Evaluated result.
...
...
@@ -65,6 +65,7 @@ public final class PartitionData {
*/
void
setResult
(
Value
result
)
{
this
.
result
=
result
;
data
=
null
;
}
/**
...
...
@@ -84,6 +85,7 @@ public final class PartitionData {
*/
void
setOrderedResult
(
HashMap
<
Integer
,
Value
>
orderedResult
)
{
this
.
orderedResult
=
orderedResult
;
data
=
null
;
}
}
h2/src/main/org/h2/expression/aggregate/Window.java
浏览文件 @
e8b7f57d
...
...
@@ -82,18 +82,18 @@ public final class Window {
* the column resolver
* @param level
* the subquery nesting level
* @see Expression#mapColumns(ColumnResolver, int)
* @see Expression#mapColumns(ColumnResolver, int
, int
)
*/
public
void
mapColumns
(
ColumnResolver
resolver
,
int
level
)
{
resolveWindows
(
resolver
);
if
(
partitionBy
!=
null
)
{
for
(
Expression
e
:
partitionBy
)
{
e
.
mapColumns
(
resolver
,
level
);
e
.
mapColumns
(
resolver
,
level
,
Expression
.
MAP_IN_WINDOW
);
}
}
if
(
orderBy
!=
null
)
{
for
(
SelectOrderBy
o
:
orderBy
)
{
o
.
expression
.
mapColumns
(
resolver
,
level
);
o
.
expression
.
mapColumns
(
resolver
,
level
,
Expression
.
MAP_IN_WINDOW
);
}
}
}
...
...
h2/src/main/org/h2/expression/aggregate/WindowFunction.java
浏览文件 @
e8b7f57d
...
...
@@ -11,7 +11,6 @@ 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
;
import
org.h2.message.DbException
;
...
...
@@ -383,13 +382,13 @@ public class WindowFunction extends DataAnalysisOperation {
}
@Override
public
void
mapColumns
(
ColumnResolver
resolver
,
int
level
)
{
public
void
mapColumns
Analysis
(
ColumnResolver
resolver
,
int
level
,
int
innerState
)
{
if
(
args
!=
null
)
{
for
(
Expression
arg
:
args
)
{
arg
.
mapColumns
(
resolver
,
level
);
arg
.
mapColumns
(
resolver
,
level
,
innerState
);
}
}
super
.
mapColumns
(
resolver
,
level
);
super
.
mapColumns
Analysis
(
resolver
,
level
,
innerState
);
}
@Override
...
...
@@ -405,8 +404,7 @@ public class WindowFunction extends DataAnalysisOperation {
throw
DbException
.
getSyntaxError
(
sql
,
sql
.
length
()
-
1
);
}
}
ArrayList
<
SelectOrderBy
>
orderBy
=
over
.
getOrderBy
();
if
(
orderBy
==
null
||
orderBy
.
isEmpty
())
{
if
(
over
.
getOrderBy
()
==
null
)
{
switch
(
type
)
{
case
RANK:
case
DENSE_RANK:
...
...
h2/src/main/org/h2/table/Column.java
浏览文件 @
e8b7f57d
...
...
@@ -475,11 +475,11 @@ public class Column {
if
(
defaultExpression
!=
null
||
onUpdateExpression
!=
null
)
{
computeTableFilter
=
new
TableFilter
(
session
,
table
,
null
,
false
,
null
,
0
,
null
);
if
(
defaultExpression
!=
null
)
{
defaultExpression
.
mapColumns
(
computeTableFilter
,
0
);
defaultExpression
.
mapColumns
(
computeTableFilter
,
0
,
Expression
.
MAP_INITIAL
);
defaultExpression
=
defaultExpression
.
optimize
(
session
);
}
if
(
onUpdateExpression
!=
null
)
{
onUpdateExpression
.
mapColumns
(
computeTableFilter
,
0
);
onUpdateExpression
.
mapColumns
(
computeTableFilter
,
0
,
Expression
.
MAP_INITIAL
);
onUpdateExpression
=
onUpdateExpression
.
optimize
(
session
);
}
}
...
...
@@ -683,7 +683,7 @@ public class Column {
if
(
name
==
null
)
{
name
=
"VALUE"
;
}
expr
.
mapColumns
(
resolver
,
0
);
expr
.
mapColumns
(
resolver
,
0
,
Expression
.
MAP_INITIAL
);
name
=
oldName
;
}
expr
=
expr
.
optimize
(
session
);
...
...
h2/src/main/org/h2/table/TableFilter.java
浏览文件 @
e8b7f57d
...
...
@@ -663,7 +663,7 @@ public class TableFilter implements ColumnResolver {
*/
public
void
addJoin
(
TableFilter
filter
,
boolean
outer
,
Expression
on
)
{
if
(
on
!=
null
)
{
on
.
mapColumns
(
this
,
0
);
on
.
mapColumns
(
this
,
0
,
Expression
.
MAP_INITIAL
);
TableFilterVisitor
visitor
=
new
MapColumnsVisitor
(
on
);
visit
(
visitor
);
filter
.
visit
(
visitor
);
...
...
@@ -697,11 +697,11 @@ public class TableFilter implements ColumnResolver {
* @param on the condition
*/
public
void
mapAndAddFilter
(
Expression
on
)
{
on
.
mapColumns
(
this
,
0
);
on
.
mapColumns
(
this
,
0
,
Expression
.
MAP_INITIAL
);
addFilterCondition
(
on
,
true
);
on
.
createIndexConditions
(
session
,
this
);
if
(
nestedJoin
!=
null
)
{
on
.
mapColumns
(
nestedJoin
,
0
);
on
.
mapColumns
(
nestedJoin
,
0
,
Expression
.
MAP_INITIAL
);
on
.
createIndexConditions
(
session
,
nestedJoin
);
}
if
(
join
!=
null
)
{
...
...
@@ -1219,7 +1219,7 @@ public class TableFilter implements ColumnResolver {
@Override
public
void
accept
(
TableFilter
f
)
{
on
.
mapColumns
(
f
,
0
);
on
.
mapColumns
(
f
,
0
,
Expression
.
MAP_INITIAL
);
}
}
...
...
h2/src/test/org/h2/test/scripts/window.sql
浏览文件 @
e8b7f57d
...
...
@@ -41,3 +41,12 @@ SELECT *, LAST_VALUE(ID) OVER W FROM TEST
DROP
TABLE
TEST
;
>
ok
SELECT
MAX
(
MAX
(
X
)
OVER
())
OVER
()
FROM
VALUES
(
1
);
>
exception
INVALID_USE_OF_AGGREGATE_FUNCTION_1
SELECT
MAX
(
MAX
(
X
)
OVER
())
FROM
VALUES
(
1
);
>
exception
INVALID_USE_OF_AGGREGATE_FUNCTION_1
SELECT
MAX
(
MAX
(
X
))
FROM
VALUES
(
1
);
>
exception
INVALID_USE_OF_AGGREGATE_FUNCTION_1
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论