Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
2f0271fb
提交
2f0271fb
authored
6 年前
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix CURRENT ROW handling in window functions
上级
5ea4c890
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
65 行增加
和
12 行删除
+65
-12
WindowFrame.java
h2/src/main/org/h2/expression/aggregate/WindowFrame.java
+14
-2
array-agg.sql
...est/org/h2/test/scripts/functions/aggregate/array-agg.sql
+40
-0
nth_value.sql
...c/test/org/h2/test/scripts/functions/window/nth_value.sql
+11
-10
没有找到文件。
h2/src/main/org/h2/expression/aggregate/WindowFrame.java
浏览文件 @
2f0271fb
...
...
@@ -352,7 +352,8 @@ public final class WindowFrame {
int
currentRow
,
boolean
reverse
)
{
int
startIndex
=
getIndex
(
session
,
orderedRows
,
sortOrder
,
currentRow
,
starting
,
false
);
int
endIndex
=
following
!=
null
?
getIndex
(
session
,
orderedRows
,
sortOrder
,
currentRow
,
following
,
true
)
:
currentRow
;
:
units
==
WindowFrameUnits
.
ROWS
?
currentRow
:
toGroupEnd
(
orderedRows
,
sortOrder
,
currentRow
,
orderedRows
.
size
()
-
1
);
if
(
endIndex
<
startIndex
)
{
return
Collections
.
emptyIterator
();
}
...
...
@@ -442,8 +443,19 @@ public final class WindowFrame {
}
break
;
case
CURRENT_ROW:
switch
(
units
)
{
case
ROWS:
index
=
currentRow
;
break
;
case
GROUPS:
case
RANGE:
index
=
forFollowing
?
toGroupEnd
(
orderedRows
,
sortOrder
,
currentRow
,
last
)
:
toGroupStart
(
orderedRows
,
sortOrder
,
currentRow
,
0
);
break
;
default
:
throw
DbException
.
getUnsupportedException
(
"units="
+
units
);
}
break
;
case
FOLLOWING:
switch
(
units
)
{
case
ROWS:
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/scripts/functions/aggregate/array-agg.sql
浏览文件 @
2f0271fb
...
...
@@ -449,6 +449,26 @@ SELECT ID, VALUE, ARRAY_AGG(ID) OVER (ORDER BY VALUE RANGE BETWEEN 2 PRECEDING A
>
8
9
(
4
,
5
,
6
)
>
rows
:
8
SELECT
ID
,
VALUE
,
ARRAY_AGG
(
ID
)
OVER
(
ORDER
BY
VALUE
ROWS
BETWEEN
UNBOUNDED
PRECEDING
AND
CURRENT
ROW
)
CP
,
ARRAY_AGG
(
ID
)
OVER
(
ORDER
BY
VALUE
ROWS
BETWEEN
CURRENT
ROW
AND
UNBOUNDED
FOLLOWING
)
CF
,
ARRAY_AGG
(
ID
)
OVER
(
ORDER
BY
VALUE
RANGE
BETWEEN
UNBOUNDED
PRECEDING
AND
CURRENT
ROW
)
RP
,
ARRAY_AGG
(
ID
)
OVER
(
ORDER
BY
VALUE
RANGE
BETWEEN
CURRENT
ROW
AND
UNBOUNDED
FOLLOWING
)
RF
,
ARRAY_AGG
(
ID
)
OVER
(
ORDER
BY
VALUE
GROUPS
BETWEEN
UNBOUNDED
PRECEDING
AND
CURRENT
ROW
)
GP
,
ARRAY_AGG
(
ID
)
OVER
(
ORDER
BY
VALUE
GROUPS
BETWEEN
CURRENT
ROW
AND
UNBOUNDED
FOLLOWING
)
GF
FROM
TEST
;
>
ID
VALUE
CP
CF
RP
RF
GP
GF
>
-- ----- ------------------------ ------------------------ ------------------------ ------------------------ ------------------------ ------------------------
>
1
1
(
1
)
(
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
)
(
1
,
2
)
(
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
)
(
1
,
2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)
OVER
(
ORDER
BY
ID
RANGE
BETWEEN
CURRENT
ROW
AND
1
PRECEDING
)
FROM
TEST
;
>
exception
SYNTAX_ERROR_1
...
...
@@ -523,5 +543,25 @@ SELECT ID, VALUE, ARRAY_AGG(ID) OVER (ORDER BY VALUE RANGE BETWEEN 1 FOLLOWING A
>
8
4
null
>
rows
:
8
SELECT
ID
,
VALUE
,
ARRAY_AGG
(
ID
)
OVER
(
ORDER
BY
VALUE
ROWS
BETWEEN
UNBOUNDED
PRECEDING
AND
CURRENT
ROW
)
CP
,
ARRAY_AGG
(
ID
)
OVER
(
ORDER
BY
VALUE
ROWS
BETWEEN
CURRENT
ROW
AND
UNBOUNDED
FOLLOWING
)
CF
,
ARRAY_AGG
(
ID
)
OVER
(
ORDER
BY
VALUE
RANGE
BETWEEN
UNBOUNDED
PRECEDING
AND
CURRENT
ROW
)
RP
,
ARRAY_AGG
(
ID
)
OVER
(
ORDER
BY
VALUE
RANGE
BETWEEN
CURRENT
ROW
AND
UNBOUNDED
FOLLOWING
)
RF
,
ARRAY_AGG
(
ID
)
OVER
(
ORDER
BY
VALUE
GROUPS
BETWEEN
UNBOUNDED
PRECEDING
AND
CURRENT
ROW
)
GP
,
ARRAY_AGG
(
ID
)
OVER
(
ORDER
BY
VALUE
GROUPS
BETWEEN
CURRENT
ROW
AND
UNBOUNDED
FOLLOWING
)
GF
FROM
TEST
;
>
ID
VALUE
CP
CF
RP
RF
GP
GF
>
-- ----- ------------------------ ------------------------ ------------------------ ------------------------ ------------------------ ------------------------
>
1
1
(
1
)
(
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
)
(
1
,
2
)
(
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
)
(
1
,
2
)
(
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
)
>
2
1
(
1
,
2
)
(
2
,
3
,
4
,
5
,
6
,
7
,
8
)
(
1
,
2
)
(
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
)
(
1
,
2
)
(
1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BY
CATEGORY
R
ANGE
BETWEEN
UNBOUNDED
PRECEDING
AND
CURRENT
ROW
)
C
,
NTH_VALUE
(
CATEGORY
,
2
)
OVER
(
ORDER
BY
CATEGORY
R
ANGE
BETWEEN
UNBOUNDED
PRECEDING
AND
CURRENT
ROW
EXCLUDE
CURRENT
ROW
)
NTH_VALUE
(
CATEGORY
,
2
)
OVER
(
ORDER
BY
CATEGORY
R
OWS
BETWEEN
UNBOUNDED
PRECEDING
AND
CURRENT
ROW
)
C
,
NTH_VALUE
(
CATEGORY
,
2
)
OVER
(
ORDER
BY
CATEGORY
R
OWS
BETWEEN
UNBOUNDED
PRECEDING
AND
CURRENT
ROW
EXCLUDE
CURRENT
ROW
)
FROM
TEST
FETCH
FIRST
3
ROWS
ONLY
;
>
ID
CATEGORY
C
NTH_VALUE
(
CATEGORY
,
2
)
OVER
(
ORDER
BY
CATEGORY
R
ANGE
UNBOUNDED
PRECEDING
EXCLUDE
CURRENT
ROW
)
>
-- -------- ---- --------------------------------------------------------------------------------------------
-
>
ID
CATEGORY
C
NTH_VALUE
(
CATEGORY
,
2
)
OVER
(
ORDER
BY
CATEGORY
R
OWS
UNBOUNDED
PRECEDING
EXCLUDE
CURRENT
ROW
)
>
-- -------- ---- --------------------------------------------------------------------------------------------
>
1
1
null
null
>
2
1
1
null
>
3
1
1
1
>
rows
:
3
SELECT
ID
,
CATEGORY
,
NTH_VALUE
(
CATEGORY
,
2
)
FROM
LAST
OVER
(
ORDER
BY
CATEGORY
RANGE
BETWEEN
CURRENT
ROW
AND
UNBOUNDED
FOLLOWING
)
C
,
NTH_VALUE
(
CATEGORY
,
2
)
FROM
LAST
OVER
(
ORDER
BY
CATEGORY
RANGE
BETWEEN
CURRENT
ROW
AND
UNBOUNDED
FOLLOWING
)
C2
,
NTH_VALUE
(
CATEGORY
,
3
)
FROM
LAST
OVER
(
ORDER
BY
CATEGORY
RANGE
BETWEEN
CURRENT
ROW
AND
UNBOUNDED
FOLLOWING
)
C3
,
NTH_VALUE
(
CATEGORY
,
2
)
FROM
LAST
OVER
(
ORDER
BY
CATEGORY
RANGE
BETWEEN
CURRENT
ROW
AND
UNBOUNDED
FOLLOWING
EXCLUDE
CURRENT
ROW
)
FROM
TEST
OFFSET
10
ROWS
;
>
ID
CATEGORY
C
NTH_VALUE
(
CATEGORY
,
2
)
FROM
LAST
OVER
(
ORDER
BY
CATEGORY
RANGE
BETWEEN
CURRENT_ROW
AND
UNBOUNDED
FOLLOWING
EXCLUDE
CURRENT
ROW
)
>
-- -------- ---- -------------------------------------------------------------------------------------------------------------------------------
>
11
3
4
4
>
12
4
4
null
>
13
4
null
null
>
ID
CATEGORY
C
2
C3
NTH_VALUE
(
CATEGORY
,
2
)
FROM
LAST
OVER
(
ORDER
BY
CATEGORY
RANGE
BETWEEN
CURRENT_ROW
AND
UNBOUNDED
FOLLOWING
EXCLUDE
CURRENT
ROW
)
>
-- -------- --
--
-- -------------------------------------------------------------------------------------------------------------------------------
>
11
3
4
3
4
>
12
4
4
null
null
>
13
4
4
null
null
>
rows
:
3
SELECT
ID
,
CATEGORY
,
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论