Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
77ab3a41
提交
77ab3a41
authored
9月 21, 2018
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add some comments and reuse variable
上级
3d50985a
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
18 行增加
和
1 行删除
+18
-1
AbstractAggregate.java
...c/main/org/h2/expression/aggregate/AbstractAggregate.java
+5
-0
DataAnalysisOperation.java
...in/org/h2/expression/aggregate/DataAnalysisOperation.java
+13
-1
没有找到文件。
h2/src/main/org/h2/expression/aggregate/AbstractAggregate.java
浏览文件 @
77ab3a41
...
@@ -76,21 +76,26 @@ public abstract class AbstractAggregate extends DataAnalysisOperation {
...
@@ -76,21 +76,26 @@ public abstract class AbstractAggregate extends DataAnalysisOperation {
int
rowIdColumn
)
{
int
rowIdColumn
)
{
WindowFrame
frame
=
over
.
getWindowFrame
();
WindowFrame
frame
=
over
.
getWindowFrame
();
if
(
frame
==
null
||
frame
.
isDefault
())
{
if
(
frame
==
null
||
frame
.
isDefault
())
{
// Aggregate all values before the current row (including)
Object
aggregateData
=
createAggregateData
();
Object
aggregateData
=
createAggregateData
();
for
(
Value
[]
row
:
ordered
)
{
for
(
Value
[]
row
:
ordered
)
{
// Collect values one by one
updateFromExpressions
(
session
,
aggregateData
,
row
);
updateFromExpressions
(
session
,
aggregateData
,
row
);
result
.
put
(
row
[
rowIdColumn
].
getInt
(),
getAggregatedValue
(
session
,
aggregateData
));
result
.
put
(
row
[
rowIdColumn
].
getInt
(),
getAggregatedValue
(
session
,
aggregateData
));
}
}
}
else
if
(
frame
.
isFullPartition
())
{
}
else
if
(
frame
.
isFullPartition
())
{
// Aggregate values from the whole partition
Object
aggregateData
=
createAggregateData
();
Object
aggregateData
=
createAggregateData
();
for
(
Value
[]
row
:
ordered
)
{
for
(
Value
[]
row
:
ordered
)
{
updateFromExpressions
(
session
,
aggregateData
,
row
);
updateFromExpressions
(
session
,
aggregateData
,
row
);
}
}
// All rows have the same value
Value
value
=
getAggregatedValue
(
session
,
aggregateData
);
Value
value
=
getAggregatedValue
(
session
,
aggregateData
);
for
(
Value
[]
row
:
ordered
)
{
for
(
Value
[]
row
:
ordered
)
{
result
.
put
(
row
[
rowIdColumn
].
getInt
(),
value
);
result
.
put
(
row
[
rowIdColumn
].
getInt
(),
value
);
}
}
}
else
{
}
else
{
// All other types of frames (slow)
int
size
=
ordered
.
size
();
int
size
=
ordered
.
size
();
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
Object
aggregateData
=
createAggregateData
();
Object
aggregateData
=
createAggregateData
();
...
...
h2/src/main/org/h2/expression/aggregate/DataAnalysisOperation.java
浏览文件 @
77ab3a41
...
@@ -244,6 +244,16 @@ public abstract class DataAnalysisOperation extends Expression {
...
@@ -244,6 +244,16 @@ public abstract class DataAnalysisOperation extends Expression {
:
getWindowResult
(
session
,
groupData
);
:
getWindowResult
(
session
,
groupData
);
}
}
/**
* Returns result of this window function or window aggregate. This method
* is not used for plain aggregates.
*
* @param session
* the session
* @param groupData
* the group data
* @return result of this function
*/
private
Value
getWindowResult
(
Session
session
,
SelectGroups
groupData
)
{
private
Value
getWindowResult
(
Session
session
,
SelectGroups
groupData
)
{
PartitionData
partition
;
PartitionData
partition
;
Object
data
;
Object
data
;
...
@@ -251,15 +261,17 @@ public abstract class DataAnalysisOperation extends Expression {
...
@@ -251,15 +261,17 @@ public abstract class DataAnalysisOperation extends Expression {
ValueArray
key
=
over
.
getCurrentKey
(
session
);
ValueArray
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
data
=
forOrderBy
?
new
ArrayList
<>()
:
createAggregateData
();
data
=
forOrderBy
?
new
ArrayList
<>()
:
createAggregateData
();
partition
=
new
PartitionData
(
data
);
partition
=
new
PartitionData
(
data
);
groupData
.
setWindowExprData
(
this
,
key
,
partition
);
groupData
.
setWindowExprData
(
this
,
key
,
partition
);
}
else
{
}
else
{
data
=
partition
.
getData
();
data
=
partition
.
getData
();
}
}
if
(
over
.
getOrderBy
()
!=
null
||
!
isAggregate
())
{
if
(
forOrderBy
||
!
isAggregate
())
{
return
getOrderedResult
(
session
,
groupData
,
partition
,
data
);
return
getOrderedResult
(
session
,
groupData
,
partition
,
data
);
}
}
// Window aggregate without ORDER BY clause in window specification
Value
result
=
partition
.
getResult
();
Value
result
=
partition
.
getResult
();
if
(
result
==
null
)
{
if
(
result
==
null
)
{
result
=
getAggregatedValue
(
session
,
data
);
result
=
getAggregatedValue
(
session
,
data
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论