Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
fca685a7
提交
fca685a7
authored
6 年前
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix GROUPS BETWEEN with same direction
上级
e5d78948
master
version-1.4.198
无相关合并请求
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
86 行增加
和
19 行删除
+86
-19
WindowFrame.java
h2/src/main/org/h2/expression/aggregate/WindowFrame.java
+43
-19
array-agg.sql
...est/org/h2/test/scripts/functions/aggregate/array-agg.sql
+43
-0
没有找到文件。
h2/src/main/org/h2/expression/aggregate/WindowFrame.java
浏览文件 @
fca685a7
...
@@ -269,8 +269,8 @@ public final class WindowFrame {
...
@@ -269,8 +269,8 @@ public final class WindowFrame {
*/
*/
public
Iterator
<
Value
[]>
iterator
(
Session
session
,
ArrayList
<
Value
[]>
orderedRows
,
SortOrder
sortOrder
,
public
Iterator
<
Value
[]>
iterator
(
Session
session
,
ArrayList
<
Value
[]>
orderedRows
,
SortOrder
sortOrder
,
int
currentRow
,
boolean
reverse
)
{
int
currentRow
,
boolean
reverse
)
{
int
startIndex
=
getIndex
(
session
,
orderedRows
,
sortOrder
,
currentRow
,
starting
);
int
startIndex
=
getIndex
(
session
,
orderedRows
,
sortOrder
,
currentRow
,
starting
,
false
);
int
endIndex
=
following
!=
null
?
getIndex
(
session
,
orderedRows
,
sortOrder
,
currentRow
,
following
)
int
endIndex
=
following
!=
null
?
getIndex
(
session
,
orderedRows
,
sortOrder
,
currentRow
,
following
,
true
)
:
currentRow
;
:
currentRow
;
if
(
endIndex
<
startIndex
)
{
if
(
endIndex
<
startIndex
)
{
throw
DbException
.
get
(
ErrorCode
.
SYNTAX_ERROR_1
,
getSQL
());
throw
DbException
.
get
(
ErrorCode
.
SYNTAX_ERROR_1
,
getSQL
());
...
@@ -293,13 +293,13 @@ public final class WindowFrame {
...
@@ -293,13 +293,13 @@ public final class WindowFrame {
}
}
private
int
getIndex
(
Session
session
,
ArrayList
<
Value
[]>
orderedRows
,
SortOrder
sortOrder
,
int
currentRow
,
private
int
getIndex
(
Session
session
,
ArrayList
<
Value
[]>
orderedRows
,
SortOrder
sortOrder
,
int
currentRow
,
WindowFrameBound
bound
)
{
WindowFrameBound
bound
,
boolean
forFollowing
)
{
int
size
=
orderedRows
.
size
();
int
size
=
orderedRows
.
size
();
int
last
=
size
-
1
;
int
last
=
size
-
1
;
int
index
;
int
index
;
switch
(
bound
.
getType
())
{
switch
(
bound
.
getType
())
{
case
UNBOUNDED_PRECEDING:
case
UNBOUNDED_PRECEDING:
index
=
0
;
index
=
-
1
;
break
;
break
;
case
PRECEDING:
case
PRECEDING:
switch
(
units
)
{
switch
(
units
)
{
...
@@ -310,13 +310,25 @@ public final class WindowFrame {
...
@@ -310,13 +310,25 @@ public final class WindowFrame {
}
}
case
GROUPS:
{
case
GROUPS:
{
int
value
=
getIntOffset
(
bound
,
session
);
int
value
=
getIntOffset
(
bound
,
session
);
index
=
toGroupStart
(
orderedRows
,
sortOrder
,
currentRow
,
0
);
if
(!
forFollowing
)
{
while
(
value
>
0
&&
index
>
0
)
{
index
=
toGroupStart
(
orderedRows
,
sortOrder
,
currentRow
,
0
);
value
--;
while
(
value
>
0
&&
index
>
0
)
{
index
=
toGroupStart
(
orderedRows
,
sortOrder
,
index
-
1
,
0
);
value
--;
}
index
=
toGroupStart
(
orderedRows
,
sortOrder
,
index
-
1
,
0
);
if
(
value
>
0
)
{
}
index
=
-
1
;
if
(
value
>
0
)
{
index
=
-
1
;
}
}
else
{
if
(
value
==
0
)
{
index
=
toGroupEnd
(
orderedRows
,
sortOrder
,
currentRow
,
last
);
}
else
{
index
=
currentRow
;
while
(
value
>
0
&&
index
>=
0
)
{
value
--;
index
=
toGroupStart
(
orderedRows
,
sortOrder
,
index
,
0
)
-
1
;
}
}
}
}
break
;
break
;
}
}
...
@@ -353,13 +365,25 @@ public final class WindowFrame {
...
@@ -353,13 +365,25 @@ public final class WindowFrame {
}
}
case
GROUPS:
{
case
GROUPS:
{
int
value
=
getIntOffset
(
bound
,
session
);
int
value
=
getIntOffset
(
bound
,
session
);
index
=
toGroupEnd
(
orderedRows
,
sortOrder
,
currentRow
,
last
);
if
(
forFollowing
)
{
while
(
value
>
0
&&
index
<
last
)
{
index
=
toGroupEnd
(
orderedRows
,
sortOrder
,
currentRow
,
last
);
value
--;
while
(
value
>
0
&&
index
<
last
)
{
index
=
toGroupEnd
(
orderedRows
,
sortOrder
,
index
+
1
,
last
);
value
--;
}
index
=
toGroupEnd
(
orderedRows
,
sortOrder
,
index
+
1
,
last
);
if
(
value
>
0
)
{
}
index
=
size
;
if
(
value
>
0
)
{
index
=
size
;
}
}
else
{
if
(
value
==
0
)
{
index
=
toGroupStart
(
orderedRows
,
sortOrder
,
currentRow
,
0
);
}
else
{
index
=
currentRow
;
while
(
value
>
0
&&
index
<=
last
)
{
value
--;
index
=
toGroupEnd
(
orderedRows
,
sortOrder
,
index
,
last
)
+
1
;
}
}
}
}
break
;
break
;
}
}
...
@@ -386,7 +410,7 @@ public final class WindowFrame {
...
@@ -386,7 +410,7 @@ public final class WindowFrame {
}
}
break
;
break
;
case
UNBOUNDED_FOLLOWING:
case
UNBOUNDED_FOLLOWING:
index
=
last
;
index
=
size
;
break
;
break
;
default
:
default
:
throw
DbException
.
getUnsupportedException
(
"window frame bound type="
+
bound
.
getType
());
throw
DbException
.
getUnsupportedException
(
"window frame bound type="
+
bound
.
getType
());
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/scripts/functions/aggregate/array-agg.sql
浏览文件 @
fca685a7
...
@@ -323,6 +323,49 @@ SELECT *, ARRAY_AGG(ID) OVER (ORDER BY ID ROWS BETWEEN 2 PRECEDING AND 1 PRECEDI
...
@@ -323,6 +323,49 @@ SELECT *, ARRAY_AGG(ID) OVER (ORDER BY ID ROWS BETWEEN 2 PRECEDING AND 1 PRECEDI
>
4
8
(
2
,
3
)
>
4
8
(
2
,
3
)
>
rows
(
ordered
):
4
>
rows
(
ordered
):
4
SELECT
*
,
ARRAY_AGG
(
ID
)
OVER
(
ORDER
BY
ID
ROWS
BETWEEN
1
FOLLOWING
AND
2
FOLLOWING
)
FROM
TEST
OFFSET
4
ROWS
;
>
ID
VALUE
ARRAY_AGG
(
ID
)
OVER
(
ORDER
BY
ID
ROWS
BETWEEN
1
FOLLOWING
AND
2
FOLLOWING
)
>
-- ----- -------------------------------------------------------------------------
>
5
8
(
6
,
7
)
>
6
8
(
7
,
8
)
>
7
9
(
8
)
>
8
9
null
>
rows
(
ordered
):
4
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
2
PRECEDING
AND
1
PRECEDING
)
P
,
ARRAY_AGG
(
ID
)
OVER
(
ORDER
BY
VALUE
GROUPS
BETWEEN
1
FOLLOWING
AND
2
FOLLOWING
)
F
,
ARRAY_AGG
(
ID
)
OVER
(
ORDER
BY
VALUE
GROUPS
BETWEEN
1
FOLLOWING
AND
UNBOUNDED
FOLLOWING
)
U_F
FROM
TEST
;
>
ID
VALUE
U_P
P
F
U_F
>
-- ----- ------------------ ------------ --------------- ------------------
>
1
1
null
null
(
3
,
4
,
5
,
6
)
(
3
,
4
,
5
,
6
,
7
,
8
)
>
2
1
null
null
(
3
,
4
,
5
,
6
)
(
3
,
4
,
5
,
6
,
7
,
8
)
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EN
CURRENT
ROW
AND
1
PRECEDING
)
FROM
TEST
;
>
exception
SYNTAX_ERROR_1
>
exception
SYNTAX_ERROR_1
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论