Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
b244ed67
提交
b244ed67
authored
9月 25, 2018
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix window functions in queries with HAVING
上级
d9a7cf0d
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
88 行增加
和
8 行删除
+88
-8
Select.java
h2/src/main/org/h2/command/dml/Select.java
+8
-4
SelectGroups.java
h2/src/main/org/h2/command/dml/SelectGroups.java
+16
-0
ExpressionColumn.java
h2/src/main/org/h2/expression/ExpressionColumn.java
+3
-4
window.sql
h2/src/test/org/h2/test/scripts/window.sql
+61
-0
没有找到文件。
h2/src/main/org/h2/command/dml/Select.java
浏览文件 @
b244ed67
...
...
@@ -400,12 +400,16 @@ public class Select extends Query {
initGroupData
(
columnCount
);
try
{
gatherGroup
(
columnCount
,
Aggregate
.
STAGE_GROUP
);
while
(
groupData
.
next
()
!=
null
)
{
updateAgg
(
columnCount
,
Aggregate
.
STAGE_WINDOW
);
}
groupData
.
done
();
try
{
isGroupWindowStage2
=
true
;
while
(
groupData
.
next
()
!=
null
)
{
if
(
havingIndex
<
0
||
expressions
.
get
(
havingIndex
).
getBooleanValue
(
session
))
{
updateAgg
(
columnCount
,
Aggregate
.
STAGE_WINDOW
);
}
else
{
groupData
.
remove
();
}
}
groupData
.
done
();
processGroupResult
(
columnCount
,
result
,
offset
,
quickOffset
);
}
finally
{
isGroupWindowStage2
=
false
;
...
...
h2/src/main/org/h2/command/dml/SelectGroups.java
浏览文件 @
b244ed67
...
...
@@ -130,6 +130,13 @@ public abstract class SelectGroups {
return
null
;
}
@Override
public
void
remove
()
{
cursor
.
remove
();
currentGroupByExprData
=
null
;
currentGroupRowId
--;
}
@Override
public
void
resetLazy
()
{
super
.
resetLazy
();
...
...
@@ -374,6 +381,15 @@ public abstract class SelectGroups {
*/
public
abstract
ValueArray
next
();
/**
* Removes the data for the current key.
*
* @see #next()
*/
public
void
remove
()
{
throw
new
UnsupportedOperationException
();
}
/**
* Resets this group data for reuse in lazy mode.
*/
...
...
h2/src/main/org/h2/expression/ExpressionColumn.java
浏览文件 @
b244ed67
...
...
@@ -154,7 +154,6 @@ public class ExpressionColumn extends Expression {
@Override
public
void
updateAggregate
(
Session
session
,
int
stage
)
{
Value
now
=
columnResolver
.
getValue
(
column
);
Select
select
=
columnResolver
.
getSelect
();
if
(
select
==
null
)
{
throw
DbException
.
get
(
ErrorCode
.
MUST_GROUP_BY_COLUMN_1
,
getSQL
());
...
...
@@ -166,9 +165,9 @@ public class ExpressionColumn extends Expression {
}
Value
v
=
(
Value
)
groupData
.
getCurrentGroupExprData
(
this
);
if
(
v
==
null
)
{
groupData
.
setCurrentGroupExprData
(
this
,
now
);
}
else
{
if
(!
database
.
areEqual
(
now
,
v
))
{
groupData
.
setCurrentGroupExprData
(
this
,
columnResolver
.
getValue
(
column
)
);
}
else
if
(!
select
.
isGroupWindowStage2
())
{
if
(!
database
.
areEqual
(
columnResolver
.
getValue
(
column
)
,
v
))
{
throw
DbException
.
get
(
ErrorCode
.
MUST_GROUP_BY_COLUMN_1
,
getSQL
());
}
}
...
...
h2/src/test/org/h2/test/scripts/window.sql
浏览文件 @
b244ed67
...
...
@@ -50,3 +50,64 @@ SELECT MAX(MAX(X) OVER ()) FROM VALUES (1);
SELECT
MAX
(
MAX
(
X
))
FROM
VALUES
(
1
);
>
exception
INVALID_USE_OF_AGGREGATE_FUNCTION_1
CREATE
TABLE
TEST
(
ID
INT
,
CATEGORY
INT
);
>
ok
INSERT
INTO
TEST
VALUES
(
1
,
1
),
(
2
,
1
),
(
4
,
2
),
(
8
,
2
),
(
16
,
3
),
(
32
,
3
);
>
update
count
:
6
SELECT
ROW_NUMBER
()
OVER
(
ORDER
BY
CATEGORY
),
SUM
(
ID
)
FROM
TEST
GROUP
BY
CATEGORY
HAVING
SUM
(
ID
)
=
12
;
>
ROW_NUMBER
()
OVER
(
ORDER
BY
CATEGORY
)
SUM
(
ID
)
>
------------------------------------- -------
>
1
12
>
rows
(
ordered
):
1
SELECT
ROW_NUMBER
()
OVER
(
ORDER
BY
CATEGORY
),
SUM
(
ID
)
FROM
TEST
GROUP
BY
CATEGORY
HAVING
CATEGORY
=
2
;
>
ROW_NUMBER
()
OVER
(
ORDER
BY
CATEGORY
)
SUM
(
ID
)
>
------------------------------------- -------
>
1
12
>
rows
(
ordered
):
1
SELECT
ROW_NUMBER
()
OVER
(
ORDER
BY
CATEGORY
),
SUM
(
ID
)
FROM
TEST
GROUP
BY
CATEGORY
HAVING
CATEGORY
>
1
;
>
ROW_NUMBER
()
OVER
(
ORDER
BY
CATEGORY
)
SUM
(
ID
)
>
------------------------------------- -------
>
1
12
>
2
48
>
rows
(
ordered
):
2
DROP
TABLE
TEST
;
>
ok
CREATE
TABLE
TEST
(
ID
INT
,
CATEGORY
BOOLEAN
);
>
ok
INSERT
INTO
TEST
VALUES
(
1
,
FALSE
),
(
2
,
FALSE
),
(
4
,
TRUE
),
(
8
,
TRUE
),
(
16
,
FALSE
),
(
32
,
FALSE
);
>
update
count
:
6
SELECT
ROW_NUMBER
()
OVER
(
ORDER
BY
CATEGORY
),
SUM
(
ID
)
FROM
TEST
GROUP
BY
CATEGORY
HAVING
SUM
(
ID
)
=
12
;
>
ROW_NUMBER
()
OVER
(
ORDER
BY
CATEGORY
)
SUM
(
ID
)
>
------------------------------------- -------
>
1
12
>
rows
(
ordered
):
1
SELECT
ROW_NUMBER
()
OVER
(
ORDER
BY
CATEGORY
),
SUM
(
ID
)
FROM
TEST
GROUP
BY
CATEGORY
HAVING
CATEGORY
;
>
ROW_NUMBER
()
OVER
(
ORDER
BY
CATEGORY
)
SUM
(
ID
)
>
------------------------------------- -------
>
1
12
>
rows
(
ordered
):
1
DROP
TABLE
TEST
;
>
ok
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论