Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
5bedf88f
提交
5bedf88f
authored
9月 19, 2018
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Require ORDER BY for window functions where required by standard
上级
ccacc3b8
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
59 行增加
和
25 行删除
+59
-25
WindowFunction.java
h2/src/main/org/h2/expression/aggregate/WindowFunction.java
+14
-0
lead.sql
h2/src/test/org/h2/test/scripts/functions/window/lead.sql
+6
-0
ntile.sql
h2/src/test/org/h2/test/scripts/functions/window/ntile.sql
+3
-0
row_number.sql
.../test/org/h2/test/scripts/functions/window/row_number.sql
+36
-25
没有找到文件。
h2/src/main/org/h2/expression/aggregate/WindowFunction.java
浏览文件 @
5bedf88f
...
@@ -10,6 +10,7 @@ import java.util.HashMap;
...
@@ -10,6 +10,7 @@ import java.util.HashMap;
import
java.util.Iterator
;
import
java.util.Iterator
;
import
org.h2.command.dml.Select
;
import
org.h2.command.dml.Select
;
import
org.h2.command.dml.SelectOrderBy
;
import
org.h2.engine.Session
;
import
org.h2.engine.Session
;
import
org.h2.expression.Expression
;
import
org.h2.expression.Expression
;
import
org.h2.message.DbException
;
import
org.h2.message.DbException
;
...
@@ -411,6 +412,19 @@ public class WindowFunction extends AbstractAggregate {
...
@@ -411,6 +412,19 @@ public class WindowFunction extends AbstractAggregate {
throw
DbException
.
getSyntaxError
(
sql
,
sql
.
length
()
-
1
);
throw
DbException
.
getSyntaxError
(
sql
,
sql
.
length
()
-
1
);
}
}
}
}
ArrayList
<
SelectOrderBy
>
orderBy
=
over
.
getOrderBy
();
if
(
orderBy
==
null
||
orderBy
.
isEmpty
())
{
switch
(
type
)
{
case
RANK:
case
DENSE_RANK:
case
NTILE:
case
LEAD:
case
LAG:
String
sql
=
getSQL
();
throw
DbException
.
getSyntaxError
(
sql
,
sql
.
length
()
-
1
,
"ORDER BY"
);
default
:
}
}
super
.
optimize
(
session
);
super
.
optimize
(
session
);
if
(
args
!=
null
)
{
if
(
args
!=
null
)
{
for
(
int
i
=
0
;
i
<
args
.
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
args
.
length
;
i
++)
{
...
...
h2/src/test/org/h2/test/scripts/functions/window/lead.sql
浏览文件 @
5bedf88f
...
@@ -129,6 +129,12 @@ SELECT LEAD(VALUE, -1) OVER (ORDER BY ID) FROM TEST;
...
@@ -129,6 +129,12 @@ SELECT LEAD(VALUE, -1) OVER (ORDER BY ID) FROM TEST;
SELECT
LAG
(
VALUE
,
-
1
)
OVER
(
ORDER
BY
ID
)
FROM
TEST
;
SELECT
LAG
(
VALUE
,
-
1
)
OVER
(
ORDER
BY
ID
)
FROM
TEST
;
>
exception
INVALID_VALUE_2
>
exception
INVALID_VALUE_2
SELECT
LEAD
(
VALUE
)
OVER
()
FROM
TEST
;
>
exception
SYNTAX_ERROR_2
SELECT
LAG
(
VALUE
)
OVER
()
FROM
TEST
;
>
exception
SYNTAX_ERROR_2
SELECT
LEAD
(
VALUE
)
OVER
(
ORDER
BY
ID
RANGE
CURRENT
ROW
)
FROM
TEST
;
SELECT
LEAD
(
VALUE
)
OVER
(
ORDER
BY
ID
RANGE
CURRENT
ROW
)
FROM
TEST
;
>
exception
SYNTAX_ERROR_1
>
exception
SYNTAX_ERROR_1
...
...
h2/src/test/org/h2/test/scripts/functions/window/ntile.sql
浏览文件 @
5bedf88f
...
@@ -113,5 +113,8 @@ SELECT NTILE(X) OVER (ORDER BY X) FROM (SELECT * FROM SYSTEM_RANGE(1, 6));
...
@@ -113,5 +113,8 @@ SELECT NTILE(X) OVER (ORDER BY X) FROM (SELECT * FROM SYSTEM_RANGE(1, 6));
>
6
>
6
>
rows
(
ordered
):
6
>
rows
(
ordered
):
6
SELECT
NTILE
(
X
)
OVER
()
FROM
(
SELECT
*
FROM
SYSTEM_RANGE
(
1
,
1
));
>
exception
SYNTAX_ERROR_2
SELECT
NTILE
(
X
)
OVER
(
ORDER
BY
X
RANGE
CURRENT
ROW
)
FROM
(
SELECT
*
FROM
SYSTEM_RANGE
(
1
,
1
));
SELECT
NTILE
(
X
)
OVER
(
ORDER
BY
X
RANGE
CURRENT
ROW
)
FROM
(
SELECT
*
FROM
SYSTEM_RANGE
(
1
,
1
));
>
exception
SYNTAX_ERROR_1
>
exception
SYNTAX_ERROR_1
h2/src/test/org/h2/test/scripts/functions/window/row_number.sql
浏览文件 @
5bedf88f
...
@@ -20,8 +20,6 @@ INSERT INTO TEST VALUES
...
@@ -20,8 +20,6 @@ INSERT INTO TEST VALUES
SELECT
*
,
SELECT
*
,
ROW_NUMBER
()
OVER
()
RN
,
ROW_NUMBER
()
OVER
()
RN
,
RANK
()
OVER
()
RK
,
DENSE_RANK
()
OVER
()
DR
,
ROUND
(
PERCENT_RANK
()
OVER
(),
2
)
PR
,
ROUND
(
PERCENT_RANK
()
OVER
(),
2
)
PR
,
ROUND
(
CUME_DIST
()
OVER
(),
2
)
CD
,
ROUND
(
CUME_DIST
()
OVER
(),
2
)
CD
,
...
@@ -32,17 +30,17 @@ SELECT *,
...
@@ -32,17 +30,17 @@ SELECT *,
ROUND
(
CUME_DIST
()
OVER
(
ORDER
BY
ID
),
2
)
CDO
ROUND
(
CUME_DIST
()
OVER
(
ORDER
BY
ID
),
2
)
CDO
FROM
TEST
;
FROM
TEST
;
>
ID
CATEGORY
VALUE
RN
RK
DR
PR
CD
RNO
RKO
DRO
PRO
CDO
>
ID
CATEGORY
VALUE
RN
PR
CD
RNO
RKO
DRO
PRO
CDO
>
-- -------- ----- -- --
-- --
- --- --- --- --- ---- ----
>
-- -------- ----- -- --- --- --- --- --- ---- ----
>
1
1
11
1
1
1
0
.
0
1
.
0
1
1
1
0
.
0
0
.
11
>
1
1
11
1
0
.
0
1
.
0
1
1
1
0
.
0
0
.
11
>
2
1
12
2
1
1
0
.
0
1
.
0
2
2
2
0
.
13
0
.
22
>
2
1
12
2
0
.
0
1
.
0
2
2
2
0
.
13
0
.
22
>
3
1
13
3
1
1
0
.
0
1
.
0
3
3
3
0
.
25
0
.
33
>
3
1
13
3
0
.
0
1
.
0
3
3
3
0
.
25
0
.
33
>
4
2
21
4
1
1
0
.
0
1
.
0
4
4
4
0
.
38
0
.
44
>
4
2
21
4
0
.
0
1
.
0
4
4
4
0
.
38
0
.
44
>
5
2
22
5
1
1
0
.
0
1
.
0
5
5
5
0
.
5
0
.
56
>
5
2
22
5
0
.
0
1
.
0
5
5
5
0
.
5
0
.
56
>
6
3
31
6
1
1
0
.
0
1
.
0
6
6
6
0
.
63
0
.
67
>
6
3
31
6
0
.
0
1
.
0
6
6
6
0
.
63
0
.
67
>
7
3
32
7
1
1
0
.
0
1
.
0
7
7
7
0
.
75
0
.
78
>
7
3
32
7
0
.
0
1
.
0
7
7
7
0
.
75
0
.
78
>
8
3
33
8
1
1
0
.
0
1
.
0
8
8
8
0
.
88
0
.
89
>
8
3
33
8
0
.
0
1
.
0
8
8
8
0
.
88
0
.
89
>
9
4
41
9
1
1
0
.
0
1
.
0
9
9
9
1
.
0
1
.
0
>
9
4
41
9
0
.
0
1
.
0
9
9
9
1
.
0
1
.
0
>
rows
(
ordered
):
9
>
rows
(
ordered
):
9
SELECT
*
,
SELECT
*
,
...
@@ -86,19 +84,26 @@ SELECT *,
...
@@ -86,19 +84,26 @@ SELECT *,
>
rows
(
ordered
):
9
>
rows
(
ordered
):
9
SELECT
SELECT
ROW_NUMBER
()
OVER
()
RN
,
ROW_NUMBER
()
OVER
(
ORDER
BY
CATEGORY
)
RN
,
RANK
()
OVER
()
RK
,
RANK
()
OVER
(
ORDER
BY
CATEGORY
)
RK
,
DENSE_RANK
()
OVER
()
DR
,
DENSE_RANK
()
OVER
(
ORDER
BY
CATEGORY
)
DR
,
PERCENT_RANK
()
OVER
()
PR
,
PERCENT_RANK
()
OVER
()
PR
,
CUME_DIST
()
OVER
()
CD
CUME_DIST
()
OVER
()
CD
,
FROM
TEST
GROUP
BY
CATEGORY
;
CATEGORY
C
>
RN
RK
DR
PR
CD
FROM
TEST
GROUP
BY
CATEGORY
ORDER
BY
RN
;
>
-- -- -- --- ---
>
RN
RK
DR
PR
CD
C
>
1
1
1
0
.
0
1
.
0
>
-- -- -- --- --- -
>
2
1
1
0
.
0
1
.
0
>
1
1
1
0
.
0
1
.
0
1
>
3
1
1
0
.
0
1
.
0
>
2
2
2
0
.
0
1
.
0
2
>
4
1
1
0
.
0
1
.
0
>
3
3
3
0
.
0
1
.
0
3
>
rows
:
4
>
4
4
4
0
.
0
1
.
0
4
>
rows
(
ordered
):
4
SELECT
RANK
()
OVER
()
FROM
TEST
;
>
exception
SYNTAX_ERROR_2
SELECT
DENSE_RANK
()
OVER
()
FROM
TEST
;
>
exception
SYNTAX_ERROR_2
SELECT
ROW_NUMBER
()
OVER
(
ORDER
BY
ID
RANGE
CURRENT
ROW
)
FROM
TEST
;
SELECT
ROW_NUMBER
()
OVER
(
ORDER
BY
ID
RANGE
CURRENT
ROW
)
FROM
TEST
;
>
exception
SYNTAX_ERROR_1
>
exception
SYNTAX_ERROR_1
...
@@ -136,5 +141,11 @@ SELECT ROW_NUMBER() OVER(ORDER /**/ BY TYPE) RN, TYPE, SUM(CNT) SUM FROM TEST GR
...
@@ -136,5 +141,11 @@ SELECT ROW_NUMBER() OVER(ORDER /**/ BY TYPE) RN, TYPE, SUM(CNT) SUM FROM TEST GR
>
3
c
4
>
3
c
4
>
rows
:
3
>
rows
:
3
SELECT
RANK
()
OVER
()
FROM
TEST
;
>
exception
SYNTAX_ERROR_2
SELECT
DENSE_RANK
()
OVER
()
FROM
TEST
;
>
exception
SYNTAX_ERROR_2
DROP
TABLE
TEST
;
DROP
TABLE
TEST
;
>
ok
>
ok
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论