Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
de4aaa48
提交
de4aaa48
authored
10月 02, 2018
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Optimize EXCLUDE TIES part 2
上级
96f6476f
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
95 行增加
和
13 行删除
+95
-13
WindowFrame.java
h2/src/main/org/h2/expression/aggregate/WindowFrame.java
+78
-13
array-agg.sql
...est/org/h2/test/scripts/functions/aggregate/array-agg.sql
+17
-0
没有找到文件。
h2/src/main/org/h2/expression/aggregate/WindowFrame.java
浏览文件 @
de4aaa48
...
@@ -93,14 +93,14 @@ public final class WindowFrame {
...
@@ -93,14 +93,14 @@ public final class WindowFrame {
}
}
private
static
final
class
BiItr
extends
PlainItr
{
private
static
class
BiItr
extends
PlainItr
{
private
final
int
endIndex1
,
startIndex2
;
final
int
end1
,
start1
;
BiItr
(
ArrayList
<
Value
[]>
orderedRows
,
int
startIndex1
,
int
endIndex1
,
int
startIndex2
,
int
endIndex2
)
{
BiItr
(
ArrayList
<
Value
[]>
orderedRows
,
int
startIndex1
,
int
endIndex1
,
int
startIndex2
,
int
endIndex2
)
{
super
(
orderedRows
,
startIndex1
,
endIndex2
);
super
(
orderedRows
,
startIndex1
,
endIndex2
);
this
.
endIndex
1
=
endIndex1
;
end
1
=
endIndex1
;
this
.
startIndex2
=
startIndex2
;
start1
=
startIndex2
;
}
}
@Override
@Override
...
@@ -109,20 +109,20 @@ public final class WindowFrame {
...
@@ -109,20 +109,20 @@ public final class WindowFrame {
throw
new
NoSuchElementException
();
throw
new
NoSuchElementException
();
}
}
Value
[]
r
=
orderedRows
.
get
(
cursor
);
Value
[]
r
=
orderedRows
.
get
(
cursor
);
cursor
=
cursor
!=
end
Index1
?
cursor
+
1
:
startIndex2
;
cursor
=
cursor
!=
end
1
?
cursor
+
1
:
start1
;
return
r
;
return
r
;
}
}
}
}
private
static
final
class
BiReverseItr
extends
PlainReverseItr
{
private
static
class
BiReverseItr
extends
PlainReverseItr
{
private
final
int
endIndex1
,
startIndex2
;
final
int
end1
,
start1
;
BiReverseItr
(
ArrayList
<
Value
[]>
orderedRows
,
int
startIndex1
,
int
endIndex1
,
int
startIndex2
,
int
endIndex2
)
{
BiReverseItr
(
ArrayList
<
Value
[]>
orderedRows
,
int
startIndex1
,
int
endIndex1
,
int
startIndex2
,
int
endIndex2
)
{
super
(
orderedRows
,
startIndex1
,
endIndex2
);
super
(
orderedRows
,
startIndex1
,
endIndex2
);
this
.
endIndex
1
=
endIndex1
;
end
1
=
endIndex1
;
this
.
startIndex2
=
startIndex2
;
start1
=
startIndex2
;
}
}
@Override
@Override
...
@@ -131,7 +131,53 @@ public final class WindowFrame {
...
@@ -131,7 +131,53 @@ public final class WindowFrame {
throw
new
NoSuchElementException
();
throw
new
NoSuchElementException
();
}
}
Value
[]
r
=
orderedRows
.
get
(
cursor
);
Value
[]
r
=
orderedRows
.
get
(
cursor
);
cursor
=
cursor
!=
startIndex2
?
cursor
-
1
:
endIndex1
;
cursor
=
cursor
!=
start1
?
cursor
-
1
:
end1
;
return
r
;
}
}
private
static
final
class
TriItr
extends
BiItr
{
private
final
int
end2
,
start2
;
TriItr
(
ArrayList
<
Value
[]>
orderedRows
,
int
startIndex1
,
int
endIndex1
,
int
startIndex2
,
int
endIndex2
,
int
startIndex3
,
int
endIndex3
)
{
super
(
orderedRows
,
startIndex1
,
endIndex1
,
startIndex2
,
endIndex3
);
end2
=
endIndex2
;
start2
=
startIndex3
;
}
@Override
public
Value
[]
next
()
{
if
(
cursor
>
endIndex
)
{
throw
new
NoSuchElementException
();
}
Value
[]
r
=
orderedRows
.
get
(
cursor
);
cursor
=
cursor
!=
end1
?
cursor
!=
end2
?
cursor
+
1
:
start2
:
start1
;
return
r
;
}
}
private
static
final
class
TriReverseItr
extends
BiReverseItr
{
private
final
int
end2
,
start2
;
TriReverseItr
(
ArrayList
<
Value
[]>
orderedRows
,
int
startIndex1
,
int
endIndex1
,
int
startIndex2
,
int
endIndex2
,
int
startIndex3
,
int
endIndex3
)
{
super
(
orderedRows
,
startIndex1
,
endIndex1
,
startIndex2
,
endIndex3
);
end2
=
endIndex2
;
start2
=
startIndex3
;
}
@Override
public
Value
[]
next
()
{
if
(
cursor
<
startIndex
)
{
throw
new
NoSuchElementException
();
}
Value
[]
r
=
orderedRows
.
get
(
cursor
);
cursor
=
cursor
!=
start1
?
cursor
!=
start2
?
cursor
-
1
:
end2
:
end1
;
return
r
;
return
r
;
}
}
...
@@ -241,6 +287,13 @@ public final class WindowFrame {
...
@@ -241,6 +287,13 @@ public final class WindowFrame {
:
new
BiItr
(
orderedRows
,
startIndex1
,
endIndex1
,
startIndex2
,
endIndex2
);
:
new
BiItr
(
orderedRows
,
startIndex1
,
endIndex1
,
startIndex2
,
endIndex2
);
}
}
private
static
Iterator
<
Value
[]>
triIterator
(
ArrayList
<
Value
[]>
orderedRows
,
int
startIndex1
,
int
endIndex1
,
int
startIndex2
,
int
endIndex2
,
int
startIndex3
,
int
endIndex3
,
boolean
reverse
)
{
return
reverse
?
new
TriReverseItr
(
orderedRows
,
startIndex1
,
endIndex1
,
startIndex2
,
endIndex2
,
//
startIndex3
,
endIndex3
)
:
new
TriItr
(
orderedRows
,
startIndex1
,
endIndex1
,
startIndex2
,
endIndex2
,
startIndex3
,
endIndex3
);
}
private
static
int
toGroupStart
(
ArrayList
<
Value
[]>
orderedRows
,
SortOrder
sortOrder
,
int
offset
,
int
minOffset
)
{
private
static
int
toGroupStart
(
ArrayList
<
Value
[]>
orderedRows
,
SortOrder
sortOrder
,
int
offset
,
int
minOffset
)
{
Value
[]
row
=
orderedRows
.
get
(
offset
);
Value
[]
row
=
orderedRows
.
get
(
offset
);
while
(
offset
>
minOffset
&&
sortOrder
.
compare
(
row
,
orderedRows
.
get
(
offset
-
1
))
==
0
)
{
while
(
offset
>
minOffset
&&
sortOrder
.
compare
(
row
,
orderedRows
.
get
(
offset
-
1
))
==
0
)
{
...
@@ -550,13 +603,25 @@ public final class WindowFrame {
...
@@ -550,13 +603,25 @@ public final class WindowFrame {
}
}
if
(
exStart
>
exEnd
||
exEnd
<
startIndex
||
exStart
>
endIndex
)
{
if
(
exStart
>
exEnd
||
exEnd
<
startIndex
||
exStart
>
endIndex
)
{
// Nothing to do
// Nothing to do
}
else
if
(
includeCurrentRow
)
{
if
(
startIndex
==
exStart
)
{
if
(
endIndex
==
exEnd
)
{
return
Collections
.
singleton
(
orderedRows
.
get
(
currentRow
)).
iterator
();
}
else
{
return
biIterator
(
orderedRows
,
currentRow
,
currentRow
,
exEnd
+
1
,
endIndex
,
reverse
);
}
}
else
{
if
(
endIndex
==
exEnd
)
{
return
biIterator
(
orderedRows
,
startIndex
,
exStart
-
1
,
currentRow
,
currentRow
,
reverse
);
}
else
{
return
triIterator
(
orderedRows
,
startIndex
,
exStart
-
1
,
currentRow
,
currentRow
,
exEnd
+
1
,
endIndex
,
reverse
);
}
}
}
else
{
}
else
{
BitSet
set
=
new
BitSet
(
endIndex
+
1
);
BitSet
set
=
new
BitSet
(
endIndex
+
1
);
set
.
set
(
startIndex
,
endIndex
+
1
);
set
.
set
(
startIndex
,
endIndex
+
1
);
set
.
clear
(
exStart
,
exEnd
+
1
);
set
.
clear
(
exStart
,
exEnd
+
1
);
if
(
includeCurrentRow
)
{
set
.
set
(
currentRow
);
}
if
(
set
.
isEmpty
())
{
if
(
set
.
isEmpty
())
{
return
Collections
.
emptyIterator
();
return
Collections
.
emptyIterator
();
}
}
...
...
h2/src/test/org/h2/test/scripts/functions/aggregate/array-agg.sql
浏览文件 @
de4aaa48
...
@@ -350,6 +350,23 @@ SELECT *, ARRAY_AGG(ID) OVER (ORDER BY ID RANGE BETWEEN 1 FOLLOWING AND 2 FOLLOW
...
@@ -350,6 +350,23 @@ SELECT *, ARRAY_AGG(ID) OVER (ORDER BY ID RANGE BETWEEN 1 FOLLOWING AND 2 FOLLOW
>
8
9
null
>
8
9
null
>
rows
:
4
>
rows
:
4
SELECT
*
,
ARRAY_AGG
(
ID
)
OVER
(
ORDER
BY
VALUE
GROUPS
BETWEEN
0
PRECEDING
AND
0
FOLLOWING
)
N
,
ARRAY_AGG
(
ID
)
OVER
(
ORDER
BY
VALUE
GROUPS
BETWEEN
0
PRECEDING
AND
0
FOLLOWING
EXCLUDE
TIES
)
T
,
ARRAY_AGG
(
ID
)
OVER
(
ORDER
BY
VALUE
GROUPS
BETWEEN
1
PRECEDING
AND
0
FOLLOWING
EXCLUDE
TIES
)
T1
FROM
TEST
;
>
ID
VALUE
N
T
T1
>
-- ----- --------- --- ------------
>
1
1
(
1
,
2
)
(
1
)
(
1
)
>
2
1
(
1
,
2
)
(
2
)
(
2
)
>
3
5
(
3
)
(
3
)
(
1
,
2
,
3
)
>
4
8
(
4
,
5
,
6
)
(
4
)
(
3
,
4
)
>
5
8
(
4
,
5
,
6
)
(
5
)
(
3
,
5
)
>
6
8
(
4
,
5
,
6
)
(
6
)
(
3
,
6
)
>
7
9
(
7
,
8
)
(
7
)
(
4
,
5
,
6
,
7
)
>
8
9
(
7
,
8
)
(
8
)
(
4
,
5
,
6
,
8
)
>
rows
:
8
SELECT
*
,
SELECT
*
,
ARRAY_AGG
(
ID
)
OVER
(
ORDER
BY
VALUE
GROUPS
BETWEEN
UNBOUNDED
PRECEDING
AND
1
PRECEDING
)
U_P
,
ARRAY_AGG
(
ID
)
OVER
(
ORDER
BY
VALUE
GROUPS
BETWEEN
UNBOUNDED
PRECEDING
AND
1
PRECEDING
)
U_P
,
ARRAY_AGG
(
ID
)
OVER
(
ORDER
BY
VALUE
GROUPS
BETWEEN
2
PRECEDING
AND
1
PRECEDING
)
P
,
ARRAY_AGG
(
ID
)
OVER
(
ORDER
BY
VALUE
GROUPS
BETWEEN
2
PRECEDING
AND
1
PRECEDING
)
P
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论