Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
eca0feef
提交
eca0feef
authored
10月 01, 2018
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Optimize EXCLUDE CURRENT ROW
上级
c970bb05
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
129 行增加
和
15 行删除
+129
-15
WindowFrame.java
h2/src/main/org/h2/expression/aggregate/WindowFrame.java
+77
-14
TestScript.java
h2/src/test/org/h2/test/scripts/TestScript.java
+3
-1
array-agg.sql
...est/org/h2/test/scripts/functions/aggregate/array-agg.sql
+28
-0
nth_value.sql
...c/test/org/h2/test/scripts/functions/window/nth_value.sql
+21
-0
没有找到文件。
h2/src/main/org/h2/expression/aggregate/WindowFrame.java
浏览文件 @
eca0feef
...
@@ -39,11 +39,11 @@ public final class WindowFrame {
...
@@ -39,11 +39,11 @@ public final class WindowFrame {
}
}
private
static
final
class
PlainItr
extends
Itr
{
private
static
class
PlainItr
extends
Itr
{
private
final
int
endIndex
;
final
int
endIndex
;
private
int
cursor
;
int
cursor
;
PlainItr
(
ArrayList
<
Value
[]>
orderedRows
,
int
startIndex
,
int
endIndex
)
{
PlainItr
(
ArrayList
<
Value
[]>
orderedRows
,
int
startIndex
,
int
endIndex
)
{
super
(
orderedRows
);
super
(
orderedRows
);
...
@@ -66,11 +66,11 @@ public final class WindowFrame {
...
@@ -66,11 +66,11 @@ public final class WindowFrame {
}
}
private
static
final
class
PlainReverseItr
extends
Itr
{
private
static
class
PlainReverseItr
extends
Itr
{
private
final
int
startIndex
;
final
int
startIndex
;
private
int
cursor
;
int
cursor
;
PlainReverseItr
(
ArrayList
<
Value
[]>
orderedRows
,
int
startIndex
,
int
endIndex
)
{
PlainReverseItr
(
ArrayList
<
Value
[]>
orderedRows
,
int
startIndex
,
int
endIndex
)
{
super
(
orderedRows
);
super
(
orderedRows
);
...
@@ -93,6 +93,50 @@ public final class WindowFrame {
...
@@ -93,6 +93,50 @@ public final class WindowFrame {
}
}
private
static
final
class
BiItr
extends
PlainItr
{
private
final
int
endIndex1
,
startIndex2
;
BiItr
(
ArrayList
<
Value
[]>
orderedRows
,
int
startIndex1
,
int
endIndex1
,
int
startIndex2
,
int
endIndex2
)
{
super
(
orderedRows
,
startIndex1
,
endIndex2
);
this
.
endIndex1
=
endIndex1
;
this
.
startIndex2
=
startIndex2
;
}
@Override
public
Value
[]
next
()
{
if
(
cursor
>
endIndex
)
{
throw
new
NoSuchElementException
();
}
Value
[]
r
=
orderedRows
.
get
(
cursor
);
cursor
=
cursor
!=
endIndex1
?
cursor
+
1
:
startIndex2
;
return
r
;
}
}
private
static
final
class
BiReverseItr
extends
PlainReverseItr
{
private
final
int
endIndex1
,
startIndex2
;
BiReverseItr
(
ArrayList
<
Value
[]>
orderedRows
,
int
startIndex1
,
int
endIndex1
,
int
startIndex2
,
int
endIndex2
)
{
super
(
orderedRows
,
startIndex1
,
endIndex2
);
this
.
endIndex1
=
endIndex1
;
this
.
startIndex2
=
startIndex2
;
}
@Override
public
Value
[]
next
()
{
if
(
cursor
<
startIndex
)
{
throw
new
NoSuchElementException
();
}
Value
[]
r
=
orderedRows
.
get
(
cursor
);
cursor
=
cursor
!=
startIndex2
?
cursor
-
1
:
endIndex1
;
return
r
;
}
}
private
static
abstract
class
AbstractBitSetItr
extends
Itr
{
private
static
abstract
class
AbstractBitSetItr
extends
Itr
{
final
BitSet
set
;
final
BitSet
set
;
...
@@ -182,11 +226,21 @@ public final class WindowFrame {
...
@@ -182,11 +226,21 @@ public final class WindowFrame {
:
plainIterator
(
orderedRows
,
0
,
currentRow
,
reverse
);
:
plainIterator
(
orderedRows
,
0
,
currentRow
,
reverse
);
}
}
private
static
Itr
plainIterator
(
ArrayList
<
Value
[]>
orderedRows
,
int
startIndex
,
int
endIndex
,
boolean
reverse
)
{
private
static
Iterator
<
Value
[]>
plainIterator
(
ArrayList
<
Value
[]>
orderedRows
,
int
startIndex
,
int
endIndex
,
boolean
reverse
)
{
if
(
endIndex
<
startIndex
)
{
return
Collections
.
emptyIterator
();
}
return
reverse
?
new
PlainReverseItr
(
orderedRows
,
startIndex
,
endIndex
)
return
reverse
?
new
PlainReverseItr
(
orderedRows
,
startIndex
,
endIndex
)
:
new
PlainItr
(
orderedRows
,
startIndex
,
endIndex
);
:
new
PlainItr
(
orderedRows
,
startIndex
,
endIndex
);
}
}
private
static
Iterator
<
Value
[]>
biIterator
(
ArrayList
<
Value
[]>
orderedRows
,
int
startIndex1
,
int
endIndex1
,
int
startIndex2
,
int
endIndex2
,
boolean
reverse
)
{
return
reverse
?
new
BiReverseItr
(
orderedRows
,
startIndex1
,
endIndex1
,
startIndex2
,
endIndex2
)
:
new
BiItr
(
orderedRows
,
startIndex1
,
endIndex1
,
startIndex2
,
endIndex2
);
}
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
)
{
...
@@ -471,22 +525,31 @@ public final class WindowFrame {
...
@@ -471,22 +525,31 @@ public final class WindowFrame {
private
Iterator
<
Value
[]>
complexIterator
(
ArrayList
<
Value
[]>
orderedRows
,
SortOrder
sortOrder
,
int
currentRow
,
private
Iterator
<
Value
[]>
complexIterator
(
ArrayList
<
Value
[]>
orderedRows
,
SortOrder
sortOrder
,
int
currentRow
,
int
startIndex
,
int
endIndex
,
boolean
reverse
)
{
int
startIndex
,
int
endIndex
,
boolean
reverse
)
{
BitSet
set
=
new
BitSet
(
endIndex
+
1
);
set
.
set
(
startIndex
,
endIndex
+
1
);
if
(
exclusion
==
WindowFrameExclusion
.
EXCLUDE_CURRENT_ROW
)
{
if
(
exclusion
==
WindowFrameExclusion
.
EXCLUDE_CURRENT_ROW
)
{
set
.
clear
(
currentRow
);
if
(
currentRow
<
startIndex
||
currentRow
>
endIndex
)
{
// Nothing to do
}
else
if
(
currentRow
==
startIndex
)
{
startIndex
++;
}
else
if
(
currentRow
==
endIndex
)
{
endIndex
--;
}
else
{
return
biIterator
(
orderedRows
,
startIndex
,
currentRow
-
1
,
currentRow
+
1
,
endIndex
,
reverse
);
}
return
plainIterator
(
orderedRows
,
startIndex
,
endIndex
,
reverse
);
}
else
{
}
else
{
BitSet
set
=
new
BitSet
(
endIndex
+
1
);
set
.
set
(
startIndex
,
endIndex
+
1
);
int
exStart
=
toGroupStart
(
orderedRows
,
sortOrder
,
currentRow
,
startIndex
);
int
exStart
=
toGroupStart
(
orderedRows
,
sortOrder
,
currentRow
,
startIndex
);
int
exEnd
=
toGroupEnd
(
orderedRows
,
sortOrder
,
currentRow
,
endIndex
);
int
exEnd
=
toGroupEnd
(
orderedRows
,
sortOrder
,
currentRow
,
endIndex
);
set
.
clear
(
exStart
,
exEnd
+
1
);
set
.
clear
(
exStart
,
exEnd
+
1
);
if
(
exclusion
==
WindowFrameExclusion
.
EXCLUDE_TIES
)
{
if
(
exclusion
==
WindowFrameExclusion
.
EXCLUDE_TIES
)
{
set
.
set
(
currentRow
);
set
.
set
(
currentRow
);
}
}
if
(
set
.
isEmpty
())
{
return
Collections
.
emptyIterator
();
}
return
reverse
?
new
BitSetReverseItr
(
orderedRows
,
set
)
:
new
BitSetItr
(
orderedRows
,
set
);
}
}
if
(
set
.
isEmpty
())
{
return
Collections
.
emptyIterator
();
}
return
reverse
?
new
BitSetReverseItr
(
orderedRows
,
set
)
:
new
BitSetItr
(
orderedRows
,
set
);
}
}
/**
/**
...
...
h2/src/test/org/h2/test/scripts/TestScript.java
浏览文件 @
eca0feef
...
@@ -653,7 +653,9 @@ public class TestScript extends TestDb {
...
@@ -653,7 +653,9 @@ public class TestScript extends TestDb {
}
}
}
else
{
}
else
{
addWriteResultError
(
"<nothing>"
,
s
);
addWriteResultError
(
"<nothing>"
,
s
);
putBack
(
compare
);
if
(
compare
!=
null
)
{
putBack
(
compare
);
}
}
}
write
(
s
);
write
(
s
);
}
}
...
...
h2/src/test/org/h2/test/scripts/functions/aggregate/array-agg.sql
浏览文件 @
eca0feef
...
@@ -430,5 +430,33 @@ SELECT *, ARRAY_AGG(ID) OVER (ORDER BY VALUE RANGE BETWEEN 1 FOLLOWING AND 2 FOL
...
@@ -430,5 +430,33 @@ SELECT *, ARRAY_AGG(ID) OVER (ORDER BY VALUE RANGE BETWEEN 1 FOLLOWING AND 2 FOL
>
8
4
null
>
8
4
null
>
rows
:
8
>
rows
:
8
SELECT
ID
,
VALUE
,
ARRAY_AGG
(
ID
)
OVER
(
ORDER
BY
VALUE
RANGE
BETWEEN
2
PRECEDING
AND
1
PRECEDING
EXCLUDE
CURRENT
ROW
)
A
FROM
TEST
;
>
ID
VALUE
A
>
-- ----- ------------
>
1
1
null
>
2
1
null
>
3
2
(
1
,
2
)
>
4
2
(
1
,
2
)
>
5
3
(
1
,
2
,
3
,
4
)
>
6
3
(
1
,
2
,
3
,
4
)
>
7
4
(
3
,
4
,
5
,
6
)
>
8
4
(
3
,
4
,
5
,
6
)
>
rows
:
8
SELECT
ID
,
VALUE
,
ARRAY_AGG
(
ID
)
OVER
(
ORDER
BY
VALUE
RANGE
BETWEEN
1
FOLLOWING
AND
1
FOLLOWING
EXCLUDE
CURRENT
ROW
)
A
FROM
TEST
;
>
ID
VALUE
A
>
-- ----- ------
>
1
1
(
3
,
4
)
>
2
1
(
3
,
4
)
>
3
2
(
5
,
6
)
>
4
2
(
5
,
6
)
>
5
3
(
7
,
8
)
>
6
3
(
7
,
8
)
>
7
4
null
>
8
4
null
>
rows
:
8
DROP
TABLE
TEST
;
DROP
TABLE
TEST
;
>
ok
>
ok
h2/src/test/org/h2/test/scripts/functions/window/nth_value.sql
浏览文件 @
eca0feef
...
@@ -146,5 +146,26 @@ SELECT ID, CATEGORY,
...
@@ -146,5 +146,26 @@ SELECT ID, CATEGORY,
>
3
1
1
1
>
3
1
1
1
>
rows
:
3
>
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
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
>
rows
:
3
SELECT
ID
,
CATEGORY
,
NTH_VALUE
(
CATEGORY
,
2
)
FROM
LAST
OVER
(
ORDER
BY
CATEGORY
RANGE
BETWEEN
UNBOUNDED
PRECEDING
AND
UNBOUNDED
FOLLOWING
EXCLUDE
CURRENT
ROW
)
C
FROM
TEST
OFFSET
10
ROWS
;
>
ID
CATEGORY
C
>
-- -------- -
>
11
3
4
>
12
4
3
>
13
4
3
>
rows
:
3
DROP
TABLE
TEST
;
DROP
TABLE
TEST
;
>
ok
>
ok
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论