Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
d10900d4
提交
d10900d4
authored
9月 21, 2018
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Do not use ValueArray as key for PARTITION BY with 1 column
上级
85a79304
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
26 行增加
和
13 行删除
+26
-13
SelectGroups.java
h2/src/main/org/h2/command/dml/SelectGroups.java
+2
-2
DataAnalysisOperation.java
...in/org/h2/expression/aggregate/DataAnalysisOperation.java
+2
-3
Window.java
h2/src/main/org/h2/expression/aggregate/Window.java
+11
-7
row_number.sql
.../test/org/h2/test/scripts/functions/window/row_number.sql
+11
-1
没有找到文件。
h2/src/main/org/h2/command/dml/SelectGroups.java
浏览文件 @
d10900d4
...
@@ -298,7 +298,7 @@ public abstract class SelectGroups {
...
@@ -298,7 +298,7 @@ public abstract class SelectGroups {
* a key of partition
* a key of partition
* @return expression data or null
* @return expression data or null
*/
*/
public
final
PartitionData
getWindowExprData
(
DataAnalysisOperation
expr
,
Value
Array
partitionKey
)
{
public
final
PartitionData
getWindowExprData
(
DataAnalysisOperation
expr
,
Value
partitionKey
)
{
if
(
partitionKey
==
null
)
{
if
(
partitionKey
==
null
)
{
return
windowData
.
get
(
expr
);
return
windowData
.
get
(
expr
);
}
else
{
}
else
{
...
@@ -317,7 +317,7 @@ public abstract class SelectGroups {
...
@@ -317,7 +317,7 @@ public abstract class SelectGroups {
* @param object
* @param object
* window expression data to set
* window expression data to set
*/
*/
public
final
void
setWindowExprData
(
DataAnalysisOperation
expr
,
Value
Array
partitionKey
,
PartitionData
obj
)
{
public
final
void
setWindowExprData
(
DataAnalysisOperation
expr
,
Value
partitionKey
,
PartitionData
obj
)
{
if
(
partitionKey
==
null
)
{
if
(
partitionKey
==
null
)
{
Object
old
=
windowData
.
put
(
expr
,
obj
);
Object
old
=
windowData
.
put
(
expr
,
obj
);
assert
old
==
null
;
assert
old
==
null
;
...
...
h2/src/main/org/h2/expression/aggregate/DataAnalysisOperation.java
浏览文件 @
d10900d4
...
@@ -21,7 +21,6 @@ import org.h2.result.SortOrder;
...
@@ -21,7 +21,6 @@ import org.h2.result.SortOrder;
import
org.h2.table.ColumnResolver
;
import
org.h2.table.ColumnResolver
;
import
org.h2.table.TableFilter
;
import
org.h2.table.TableFilter
;
import
org.h2.value.Value
;
import
org.h2.value.Value
;
import
org.h2.value.ValueArray
;
import
org.h2.value.ValueInt
;
import
org.h2.value.ValueInt
;
/**
/**
...
@@ -184,7 +183,7 @@ public abstract class DataAnalysisOperation extends Expression {
...
@@ -184,7 +183,7 @@ public abstract class DataAnalysisOperation extends Expression {
protected
Object
getWindowData
(
Session
session
,
SelectGroups
groupData
,
boolean
forOrderBy
)
{
protected
Object
getWindowData
(
Session
session
,
SelectGroups
groupData
,
boolean
forOrderBy
)
{
Object
data
;
Object
data
;
Value
Array
key
=
over
.
getCurrentKey
(
session
);
Value
key
=
over
.
getCurrentKey
(
session
);
PartitionData
partition
=
groupData
.
getWindowExprData
(
this
,
key
);
PartitionData
partition
=
groupData
.
getWindowExprData
(
this
,
key
);
if
(
partition
==
null
)
{
if
(
partition
==
null
)
{
data
=
forOrderBy
?
new
ArrayList
<>()
:
createAggregateData
();
data
=
forOrderBy
?
new
ArrayList
<>()
:
createAggregateData
();
...
@@ -258,7 +257,7 @@ public abstract class DataAnalysisOperation extends Expression {
...
@@ -258,7 +257,7 @@ public abstract class DataAnalysisOperation extends Expression {
PartitionData
partition
;
PartitionData
partition
;
Object
data
;
Object
data
;
boolean
forOrderBy
=
over
.
getOrderBy
()
!=
null
;
boolean
forOrderBy
=
over
.
getOrderBy
()
!=
null
;
Value
Array
key
=
over
.
getCurrentKey
(
session
);
Value
key
=
over
.
getCurrentKey
(
session
);
partition
=
groupData
.
getWindowExprData
(
this
,
key
);
partition
=
groupData
.
getWindowExprData
(
this
,
key
);
if
(
partition
==
null
)
{
if
(
partition
==
null
)
{
// Window aggregates with FILTER clause may have no collected values
// Window aggregates with FILTER clause may have no collected values
...
...
h2/src/main/org/h2/expression/aggregate/Window.java
浏览文件 @
d10900d4
...
@@ -185,18 +185,22 @@ public final class Window {
...
@@ -185,18 +185,22 @@ public final class Window {
* session
* session
* @return key for the current group, or null
* @return key for the current group, or null
*/
*/
public
Value
Array
getCurrentKey
(
Session
session
)
{
public
Value
getCurrentKey
(
Session
session
)
{
if
(
partitionBy
==
null
)
{
if
(
partitionBy
==
null
)
{
return
null
;
return
null
;
}
}
int
len
=
partitionBy
.
size
();
int
len
=
partitionBy
.
size
();
Value
[]
keyValues
=
new
Value
[
len
];
if
(
len
==
1
)
{
// update group
return
partitionBy
.
get
(
0
).
getValue
(
session
);
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
}
else
{
Expression
expr
=
partitionBy
.
get
(
i
);
Value
[]
keyValues
=
new
Value
[
len
];
keyValues
[
i
]
=
expr
.
getValue
(
session
);
// update group
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
Expression
expr
=
partitionBy
.
get
(
i
);
keyValues
[
i
]
=
expr
.
getValue
(
session
);
}
return
ValueArray
.
get
(
keyValues
);
}
}
return
ValueArray
.
get
(
keyValues
);
}
}
/**
/**
...
...
h2/src/test/org/h2/test/scripts/functions/window/row_number.sql
浏览文件 @
d10900d4
...
@@ -133,7 +133,7 @@ INSERT INTO TEST VALUES
...
@@ -133,7 +133,7 @@ INSERT INTO TEST VALUES
(
4
,
'b'
,
8
);
(
4
,
'b'
,
8
);
>
update
count
:
4
>
update
count
:
4
SELECT
ROW_NUMBER
()
OVER
(
ORDER
/**/
BY
TYPE
)
RN
,
TYPE
,
SUM
(
CNT
)
SUM
FROM
TEST
GROUP
BY
TYPE
;
SELECT
ROW_NUMBER
()
OVER
(
ORDER
/**/
BY
TYPE
)
RN
,
TYPE
,
SUM
(
CNT
)
SUM
FROM
TEST
GROUP
BY
TYPE
;
>
RN
TYPE
SUM
>
RN
TYPE
SUM
>
-- ---- ---
>
-- ---- ---
>
1
a
1
>
1
a
1
...
@@ -141,6 +141,16 @@ SELECT ROW_NUMBER() OVER(ORDER /**/ BY TYPE) RN, TYPE, SUM(CNT) SUM FROM TEST GR
...
@@ -141,6 +141,16 @@ SELECT ROW_NUMBER() OVER(ORDER /**/ BY TYPE) RN, TYPE, SUM(CNT) SUM FROM TEST GR
>
3
c
4
>
3
c
4
>
rows
:
3
>
rows
:
3
SELECT
A
,
B
,
C
,
ROW_NUMBER
()
OVER
(
PARTITION
BY
A
,
B
)
N
FROM
VALUES
(
1
,
1
,
1
),
(
1
,
1
,
2
),
(
1
,
2
,
3
),
(
2
,
1
,
4
)
T
(
A
,
B
,
C
);
>
A
B
C
N
>
-
-
-
-
>
1
1
1
1
>
1
1
2
2
>
1
2
3
1
>
2
1
4
1
>
rows
:
4
SELECT
RANK
()
OVER
()
FROM
TEST
;
SELECT
RANK
()
OVER
()
FROM
TEST
;
>
exception
SYNTAX_ERROR_2
>
exception
SYNTAX_ERROR_2
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论