Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
dcc0ecbc
提交
dcc0ecbc
authored
9月 21, 2018
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use separate maps for partitioned and not partitioned window functions
上级
73f31b32
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
48 行增加
和
62 行删除
+48
-62
SelectGroups.java
h2/src/main/org/h2/command/dml/SelectGroups.java
+34
-8
DataAnalysisOperation.java
...in/org/h2/expression/aggregate/DataAnalysisOperation.java
+13
-53
PartitionData.java
h2/src/main/org/h2/expression/aggregate/PartitionData.java
+1
-1
没有找到文件。
h2/src/main/org/h2/command/dml/SelectGroups.java
浏览文件 @
dcc0ecbc
...
@@ -15,6 +15,8 @@ import java.util.Map.Entry;
...
@@ -15,6 +15,8 @@ import java.util.Map.Entry;
import
org.h2.engine.Session
;
import
org.h2.engine.Session
;
import
org.h2.expression.Expression
;
import
org.h2.expression.Expression
;
import
org.h2.expression.aggregate.DataAnalysisOperation
;
import
org.h2.expression.aggregate.DataAnalysisOperation
;
import
org.h2.expression.aggregate.PartitionData
;
import
org.h2.util.ValueHashMap
;
import
org.h2.value.Value
;
import
org.h2.value.Value
;
import
org.h2.value.ValueArray
;
import
org.h2.value.ValueArray
;
...
@@ -209,9 +211,14 @@ public abstract class SelectGroups {
...
@@ -209,9 +211,14 @@ public abstract class SelectGroups {
final
HashMap
<
Expression
,
Integer
>
exprToIndexInGroupByData
=
new
HashMap
<>();
final
HashMap
<
Expression
,
Integer
>
exprToIndexInGroupByData
=
new
HashMap
<>();
/**
/**
* Maps an expression object to its data.
* Maps an
window
expression object to its data.
*/
*/
private
final
HashMap
<
DataAnalysisOperation
,
Object
>
windowData
=
new
HashMap
<>();
private
final
HashMap
<
DataAnalysisOperation
,
PartitionData
>
windowData
=
new
HashMap
<>();
/**
* Maps an partitioned window expression object to its data.
*/
private
final
HashMap
<
DataAnalysisOperation
,
ValueHashMap
<
PartitionData
>>
windowPartitionData
=
new
HashMap
<>();
/**
/**
* The id of the current group.
* The id of the current group.
...
@@ -291,10 +298,17 @@ public abstract class SelectGroups {
...
@@ -291,10 +298,17 @@ public abstract class SelectGroups {
*
*
* @param expr
* @param expr
* expression
* expression
* @param partitionKey
* a key of partition
* @return expression data or null
* @return expression data or null
*/
*/
public
final
Object
getWindowExprData
(
DataAnalysisOperation
expr
)
{
public
final
PartitionData
getWindowExprData
(
DataAnalysisOperation
expr
,
ValueArray
partitionKey
)
{
return
windowData
.
get
(
expr
);
if
(
partitionKey
==
null
)
{
return
windowData
.
get
(
expr
);
}
else
{
ValueHashMap
<
PartitionData
>
map
=
windowPartitionData
.
get
(
expr
);
return
map
!=
null
?
map
.
get
(
partitionKey
)
:
null
;
}
}
}
/**
/**
...
@@ -302,12 +316,23 @@ public abstract class SelectGroups {
...
@@ -302,12 +316,23 @@ public abstract class SelectGroups {
*
*
* @param expr
* @param expr
* expression
* expression
* @param partitionKey
* a key of partition
* @param object
* @param object
* expression data to set
*
window
expression data to set
*/
*/
public
final
void
setWindowExprData
(
DataAnalysisOperation
expr
,
Object
obj
)
{
public
final
void
setWindowExprData
(
DataAnalysisOperation
expr
,
ValueArray
partitionKey
,
PartitionData
obj
)
{
Object
old
=
windowData
.
put
(
expr
,
obj
);
if
(
partitionKey
==
null
)
{
assert
old
==
null
;
Object
old
=
windowData
.
put
(
expr
,
obj
);
assert
old
==
null
;
}
else
{
ValueHashMap
<
PartitionData
>
map
=
windowPartitionData
.
get
(
expr
);
if
(
map
==
null
)
{
map
=
new
ValueHashMap
<>();
windowPartitionData
.
put
(
expr
,
map
);
}
map
.
put
(
partitionKey
,
obj
);
}
}
}
abstract
void
updateCurrentGroupExprData
();
abstract
void
updateCurrentGroupExprData
();
...
@@ -329,6 +354,7 @@ public abstract class SelectGroups {
...
@@ -329,6 +354,7 @@ public abstract class SelectGroups {
currentGroupByExprData
=
null
;
currentGroupByExprData
=
null
;
exprToIndexInGroupByData
.
clear
();
exprToIndexInGroupByData
.
clear
();
windowData
.
clear
();
windowData
.
clear
();
windowPartitionData
.
clear
();
currentGroupRowId
=
0
;
currentGroupRowId
=
0
;
}
}
...
...
h2/src/main/org/h2/expression/aggregate/DataAnalysisOperation.java
浏览文件 @
dcc0ecbc
...
@@ -20,7 +20,6 @@ import org.h2.message.DbException;
...
@@ -20,7 +20,6 @@ import org.h2.message.DbException;
import
org.h2.result.SortOrder
;
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.util.ValueHashMap
;
import
org.h2.value.Value
;
import
org.h2.value.Value
;
import
org.h2.value.ValueArray
;
import
org.h2.value.ValueArray
;
import
org.h2.value.ValueInt
;
import
org.h2.value.ValueInt
;
...
@@ -187,37 +186,15 @@ public abstract class DataAnalysisOperation extends Expression {
...
@@ -187,37 +186,15 @@ public abstract class DataAnalysisOperation extends Expression {
Object
data
;
Object
data
;
if
(
over
!=
null
)
{
if
(
over
!=
null
)
{
ValueArray
key
=
over
.
getCurrentKey
(
session
);
ValueArray
key
=
over
.
getCurrentKey
(
session
);
if
(
key
!=
null
)
{
PartitionData
partition
=
groupData
.
getWindowExprData
(
this
,
key
);
@SuppressWarnings
(
"unchecked"
)
if
(
partition
==
null
)
{
ValueHashMap
<
Object
>
map
=
(
ValueHashMap
<
Object
>)
groupData
.
getWindowExprData
(
this
);
if
(
ifExists
)
{
if
(
map
==
null
)
{
return
null
;
if
(
ifExists
)
{
return
null
;
}
map
=
new
ValueHashMap
<>();
groupData
.
setWindowExprData
(
this
,
map
);
}
PartitionData
partition
=
(
PartitionData
)
map
.
get
(
key
);
if
(
partition
==
null
)
{
if
(
ifExists
)
{
return
null
;
}
data
=
forOrderBy
?
new
ArrayList
<>()
:
createAggregateData
();
map
.
put
(
key
,
new
PartitionData
(
data
));
}
else
{
data
=
partition
.
getData
();
}
}
data
=
forOrderBy
?
new
ArrayList
<>()
:
createAggregateData
();
groupData
.
setWindowExprData
(
this
,
key
,
new
PartitionData
(
data
));
}
else
{
}
else
{
PartitionData
partition
=
(
PartitionData
)
groupData
.
getWindowExprData
(
this
);
data
=
partition
.
getData
();
if
(
partition
==
null
)
{
if
(
ifExists
)
{
return
null
;
}
data
=
forOrderBy
?
new
ArrayList
<>()
:
createAggregateData
();
groupData
.
setWindowExprData
(
this
,
new
PartitionData
(
data
));
}
else
{
data
=
partition
.
getData
();
}
}
}
}
else
{
}
else
{
data
=
groupData
.
getCurrentGroupExprData
(
this
);
data
=
groupData
.
getCurrentGroupExprData
(
this
);
...
@@ -273,30 +250,13 @@ public abstract class DataAnalysisOperation extends Expression {
...
@@ -273,30 +250,13 @@ public abstract class DataAnalysisOperation extends Expression {
Object
data
;
Object
data
;
boolean
forOrderBy
=
over
.
getOrderBy
()
!=
null
;
boolean
forOrderBy
=
over
.
getOrderBy
()
!=
null
;
ValueArray
key
=
over
.
getCurrentKey
(
session
);
ValueArray
key
=
over
.
getCurrentKey
(
session
);
if
(
key
!=
null
)
{
partition
=
groupData
.
getWindowExprData
(
this
,
key
);
@SuppressWarnings
(
"unchecked"
)
if
(
partition
==
null
)
{
ValueHashMap
<
Object
>
map
=
(
ValueHashMap
<
Object
>)
groupData
.
getWindowExprData
(
this
);
data
=
forOrderBy
?
new
ArrayList
<>()
:
createAggregateData
();
if
(
map
==
null
)
{
partition
=
new
PartitionData
(
data
);
map
=
new
ValueHashMap
<>();
groupData
.
setWindowExprData
(
this
,
key
,
partition
);
groupData
.
setWindowExprData
(
this
,
map
);
}
partition
=
(
PartitionData
)
map
.
get
(
key
);
if
(
partition
==
null
)
{
data
=
forOrderBy
?
new
ArrayList
<>()
:
createAggregateData
();
partition
=
new
PartitionData
(
data
);
map
.
put
(
key
,
partition
);
}
else
{
data
=
partition
.
getData
();
}
}
else
{
}
else
{
partition
=
(
PartitionData
)
groupData
.
getWindowExprData
(
this
);
data
=
partition
.
getData
();
if
(
partition
==
null
)
{
data
=
forOrderBy
?
new
ArrayList
<>()
:
createAggregateData
();
partition
=
new
PartitionData
(
data
);
groupData
.
setWindowExprData
(
this
,
partition
);
}
else
{
data
=
partition
.
getData
();
}
}
}
if
(
over
.
getOrderBy
()
!=
null
||
!
isAggregate
())
{
if
(
over
.
getOrderBy
()
!=
null
||
!
isAggregate
())
{
return
getOrderedResult
(
session
,
groupData
,
partition
,
data
);
return
getOrderedResult
(
session
,
groupData
,
partition
,
data
);
...
...
h2/src/main/org/h2/expression/aggregate/PartitionData.java
浏览文件 @
dcc0ecbc
...
@@ -12,7 +12,7 @@ import org.h2.value.Value;
...
@@ -12,7 +12,7 @@ import org.h2.value.Value;
/**
/**
* Partition data of a window aggregate.
* Partition data of a window aggregate.
*/
*/
final
class
PartitionData
{
public
final
class
PartitionData
{
/**
/**
* Aggregate data.
* Aggregate data.
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论