Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
c2f95233
提交
c2f95233
authored
10月 01, 2018
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Optimize EXCLUDE GROUP part 1
上级
eca0feef
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
98 行增加
和
10 行删除
+98
-10
WindowFrame.java
h2/src/main/org/h2/expression/aggregate/WindowFrame.java
+14
-10
array-agg.sql
...est/org/h2/test/scripts/functions/aggregate/array-agg.sql
+34
-0
nth_value.sql
...c/test/org/h2/test/scripts/functions/window/nth_value.sql
+50
-0
没有找到文件。
h2/src/main/org/h2/expression/aggregate/WindowFrame.java
浏览文件 @
c2f95233
...
...
@@ -535,21 +535,25 @@ public final class WindowFrame {
}
else
{
return
biIterator
(
orderedRows
,
startIndex
,
currentRow
-
1
,
currentRow
+
1
,
endIndex
,
reverse
);
}
return
plainIterator
(
orderedRows
,
startIndex
,
endIndex
,
reverse
);
}
else
{
BitSet
set
=
new
BitSet
(
endIndex
+
1
);
set
.
set
(
startIndex
,
endIndex
+
1
);
int
exStart
=
toGroupStart
(
orderedRows
,
sortOrder
,
currentRow
,
startIndex
);
int
exEnd
=
toGroupEnd
(
orderedRows
,
sortOrder
,
currentRow
,
endIndex
);
set
.
clear
(
exStart
,
exEnd
+
1
);
if
(
exclusion
==
WindowFrameExclusion
.
EXCLUDE_TIES
)
{
set
.
set
(
currentRow
);
}
if
(
set
.
isEmpty
())
{
return
Collections
.
emptyIterator
();
if
(
exEnd
<
startIndex
||
exStart
>
endIndex
)
{
// Nothing to do
}
else
{
BitSet
set
=
new
BitSet
(
endIndex
+
1
);
set
.
set
(
startIndex
,
endIndex
+
1
);
set
.
clear
(
exStart
,
exEnd
+
1
);
if
(
exclusion
==
WindowFrameExclusion
.
EXCLUDE_TIES
)
{
set
.
set
(
currentRow
);
}
if
(
set
.
isEmpty
())
{
return
Collections
.
emptyIterator
();
}
return
reverse
?
new
BitSetReverseItr
(
orderedRows
,
set
)
:
new
BitSetItr
(
orderedRows
,
set
);
}
return
reverse
?
new
BitSetReverseItr
(
orderedRows
,
set
)
:
new
BitSetItr
(
orderedRows
,
set
);
}
return
plainIterator
(
orderedRows
,
startIndex
,
endIndex
,
reverse
);
}
/**
...
...
h2/src/test/org/h2/test/scripts/functions/aggregate/array-agg.sql
浏览文件 @
c2f95233
...
...
@@ -384,6 +384,40 @@ SELECT *,
>
8
9
(
4
,
5
,
6
,
7
,
8
)
(
7
,
8
)
>
rows
:
8
SELECT
ID
,
VALUE
,
ARRAY_AGG
(
ID
)
OVER
(
ORDER
BY
VALUE
ROWS
BETWEEN
2
PRECEDING
AND
2
FOLLOWING
EXCLUDE
GROUP
)
G
,
ARRAY_AGG
(
ID
)
OVER
(
ORDER
BY
VALUE
ROWS
BETWEEN
2
PRECEDING
AND
2
FOLLOWING
EXCLUDE
TIES
)
T
FROM
TEST
;
>
ID
VALUE
G
T
>
-- ----- ------------ ---------------
>
1
1
(
3
)
(
1
,
3
)
>
2
1
(
3
,
4
)
(
2
,
3
,
4
)
>
3
5
(
1
,
2
,
4
,
5
)
(
1
,
2
,
3
,
4
,
5
)
>
4
8
(
2
,
3
)
(
2
,
3
,
4
)
>
5
8
(
3
,
7
)
(
3
,
5
,
7
)
>
6
8
(
7
,
8
)
(
6
,
7
,
8
)
>
7
9
(
5
,
6
)
(
5
,
6
,
7
)
>
8
9
(
6
)
(
6
,
8
)
>
rows
:
8
SELECT
ID
,
VALUE
,
ARRAY_AGG
(
ID
)
OVER
(
ORDER
BY
VALUE
ROWS
BETWEEN
1
FOLLOWING
AND
2
FOLLOWING
EXCLUDE
GROUP
)
G
FROM
TEST
ORDER
BY
ID
FETCH
FIRST
3
ROWS
ONLY
;
>
ID
VALUE
G
>
-- ----- ------
>
1
1
(
3
)
>
2
1
(
3
,
4
)
>
3
5
(
4
,
5
)
>
rows
(
ordered
):
3
SELECT
ID
,
VALUE
,
ARRAY_AGG
(
ID
)
OVER
(
ORDER
BY
VALUE
ROWS
BETWEEN
2
PRECEDING
AND
1
PRECEDING
EXCLUDE
GROUP
)
G
FROM
TEST
ORDER
BY
ID
FETCH
FIRST
3
ROWS
ONLY
;
>
ID
VALUE
G
>
-- ----- ------
>
1
1
null
>
2
1
null
>
3
5
(
1
,
2
)
>
rows
(
ordered
):
3
SELECT
*
,
ARRAY_AGG
(
ID
)
OVER
(
ORDER
BY
ID
RANGE
BETWEEN
CURRENT
ROW
AND
1
PRECEDING
)
FROM
TEST
;
>
exception
SYNTAX_ERROR_1
...
...
h2/src/test/org/h2/test/scripts/functions/window/nth_value.sql
浏览文件 @
c2f95233
...
...
@@ -167,5 +167,55 @@ SELECT ID, CATEGORY,
>
13
4
3
>
rows
:
3
SELECT
ID
,
CATEGORY
,
NTH_VALUE
(
CATEGORY
,
1
)
OVER
(
ORDER
BY
CATEGORY
RANGE
BETWEEN
UNBOUNDED
PRECEDING
AND
UNBOUNDED
FOLLOWING
EXCLUDE
GROUP
)
F1
,
NTH_VALUE
(
CATEGORY
,
2
)
OVER
(
ORDER
BY
CATEGORY
RANGE
BETWEEN
UNBOUNDED
PRECEDING
AND
UNBOUNDED
FOLLOWING
EXCLUDE
GROUP
)
F2
,
NTH_VALUE
(
CATEGORY
,
5
)
OVER
(
ORDER
BY
CATEGORY
RANGE
BETWEEN
UNBOUNDED
PRECEDING
AND
UNBOUNDED
FOLLOWING
EXCLUDE
GROUP
)
F5
,
NTH_VALUE
(
CATEGORY
,
5
)
FROM
LAST
OVER
(
ORDER
BY
CATEGORY
RANGE
BETWEEN
UNBOUNDED
PRECEDING
AND
UNBOUNDED
FOLLOWING
EXCLUDE
GROUP
)
L5
,
NTH_VALUE
(
CATEGORY
,
2
)
FROM
LAST
OVER
(
ORDER
BY
CATEGORY
RANGE
BETWEEN
UNBOUNDED
PRECEDING
AND
UNBOUNDED
FOLLOWING
EXCLUDE
GROUP
)
L2
,
NTH_VALUE
(
CATEGORY
,
1
)
FROM
LAST
OVER
(
ORDER
BY
CATEGORY
RANGE
BETWEEN
UNBOUNDED
PRECEDING
AND
UNBOUNDED
FOLLOWING
EXCLUDE
GROUP
)
L1
FROM
TEST
ORDER
BY
ID
;
>
ID
CATEGORY
F1
F2
F5
L5
L2
L1
>
-- -------- -- -- -- -- -- --
>
1
1
2
2
3
3
4
4
>
2
1
2
2
3
3
4
4
>
3
1
2
2
3
3
4
4
>
4
1
2
2
3
3
4
4
>
5
1
2
2
3
3
4
4
>
6
1
2
2
3
3
4
4
>
7
2
1
1
1
3
4
4
>
8
2
1
1
1
3
4
4
>
9
3
1
1
1
1
4
4
>
10
3
1
1
1
1
4
4
>
11
3
1
1
1
1
4
4
>
12
4
1
1
1
2
3
3
>
13
4
1
1
1
2
3
3
>
rows
(
ordered
):
13
SELECT
ID
,
CATEGORY
,
NTH_VALUE
(
CATEGORY
,
1
)
OVER
(
ORDER
BY
CATEGORY
RANGE
BETWEEN
UNBOUNDED
PRECEDING
AND
UNBOUNDED
FOLLOWING
EXCLUDE
TIES
)
F1
,
NTH_VALUE
(
CATEGORY
,
2
)
OVER
(
ORDER
BY
CATEGORY
RANGE
BETWEEN
UNBOUNDED
PRECEDING
AND
UNBOUNDED
FOLLOWING
EXCLUDE
TIES
)
F2
,
NTH_VALUE
(
CATEGORY
,
5
)
OVER
(
ORDER
BY
CATEGORY
RANGE
BETWEEN
UNBOUNDED
PRECEDING
AND
UNBOUNDED
FOLLOWING
EXCLUDE
TIES
)
F5
,
NTH_VALUE
(
CATEGORY
,
5
)
FROM
LAST
OVER
(
ORDER
BY
CATEGORY
RANGE
BETWEEN
UNBOUNDED
PRECEDING
AND
UNBOUNDED
FOLLOWING
EXCLUDE
TIES
)
L5
,
NTH_VALUE
(
CATEGORY
,
2
)
FROM
LAST
OVER
(
ORDER
BY
CATEGORY
RANGE
BETWEEN
UNBOUNDED
PRECEDING
AND
UNBOUNDED
FOLLOWING
EXCLUDE
TIES
)
L2
,
NTH_VALUE
(
CATEGORY
,
1
)
FROM
LAST
OVER
(
ORDER
BY
CATEGORY
RANGE
BETWEEN
UNBOUNDED
PRECEDING
AND
UNBOUNDED
FOLLOWING
EXCLUDE
TIES
)
L1
FROM
TEST
ORDER
BY
ID
;
>
ID
CATEGORY
F1
F2
F5
L5
L2
L1
>
-- -------- -- -- -- -- -- --
>
1
1
1
2
3
3
4
4
>
2
1
1
2
3
3
4
4
>
3
1
1
2
3
3
4
4
>
4
1
1
2
3
3
4
4
>
5
1
1
2
3
3
4
4
>
6
1
1
2
3
3
4
4
>
7
2
1
1
1
3
4
4
>
8
2
1
1
1
3
4
4
>
9
3
1
1
1
2
4
4
>
10
3
1
1
1
2
4
4
>
11
3
1
1
1
2
4
4
>
12
4
1
1
1
2
3
4
>
13
4
1
1
1
2
3
4
>
rows
(
ordered
):
13
DROP
TABLE
TEST
;
>
ok
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论