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