Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
afa9a0b5
提交
afa9a0b5
authored
9月 16, 2018
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move more common code to AbstractAggregate
上级
bd864e33
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
67 行增加
和
109 行删除
+67
-109
AbstractAggregate.java
...c/main/org/h2/expression/aggregate/AbstractAggregate.java
+42
-4
Aggregate.java
h2/src/main/org/h2/expression/aggregate/Aggregate.java
+11
-30
JavaAggregate.java
h2/src/main/org/h2/expression/aggregate/JavaAggregate.java
+14
-75
没有找到文件。
h2/src/main/org/h2/expression/aggregate/AbstractAggregate.java
浏览文件 @
afa9a0b5
...
...
@@ -11,6 +11,8 @@ import org.h2.engine.Session;
import
org.h2.expression.Expression
;
import
org.h2.table.ColumnResolver
;
import
org.h2.table.TableFilter
;
import
org.h2.util.ValueHashMap
;
import
org.h2.value.ValueArray
;
/**
* A base class for aggregates.
...
...
@@ -111,7 +113,7 @@ public abstract class AbstractAggregate extends Expression {
return
;
}
}
updateAggregate
(
session
,
g
roupData
);
updateAggregate
(
session
,
g
etData
(
session
,
groupData
,
false
)
);
}
/**
...
...
@@ -119,10 +121,10 @@ public abstract class AbstractAggregate extends Expression {
*
* @param session
* the session
* @param
group
Data
*
group data from the select
* @param
aggregate
Data
*
aggregate data
*/
protected
abstract
void
updateAggregate
(
Session
session
,
SelectGroups
group
Data
);
protected
abstract
void
updateAggregate
(
Session
session
,
Object
aggregate
Data
);
/**
* Invoked when processing group stage of grouped window queries to update
...
...
@@ -133,6 +135,42 @@ public abstract class AbstractAggregate extends Expression {
*/
protected
abstract
void
updateGroupAggregates
(
Session
session
);
protected
Object
getData
(
Session
session
,
SelectGroups
groupData
,
boolean
ifExists
)
{
Object
data
;
ValueArray
key
;
if
(
over
!=
null
&&
(
key
=
over
.
getCurrentKey
(
session
))
!=
null
)
{
@SuppressWarnings
(
"unchecked"
)
ValueHashMap
<
Object
>
map
=
(
ValueHashMap
<
Object
>)
groupData
.
getCurrentGroupExprData
(
this
,
true
);
if
(
map
==
null
)
{
if
(
ifExists
)
{
return
null
;
}
map
=
new
ValueHashMap
<>();
groupData
.
setCurrentGroupExprData
(
this
,
map
,
true
);
}
data
=
map
.
get
(
key
);
if
(
data
==
null
)
{
if
(
ifExists
)
{
return
null
;
}
data
=
createAggregateData
();
map
.
put
(
key
,
data
);
}
}
else
{
data
=
groupData
.
getCurrentGroupExprData
(
this
,
over
!=
null
);
if
(
data
==
null
)
{
if
(
ifExists
)
{
return
null
;
}
data
=
createAggregateData
();
groupData
.
setCurrentGroupExprData
(
this
,
data
,
over
!=
null
);
}
}
return
data
;
}
protected
abstract
Object
createAggregateData
();
protected
StringBuilder
appendTailConditions
(
StringBuilder
builder
)
{
if
(
filterCondition
!=
null
)
{
builder
.
append
(
" FILTER (WHERE "
).
append
(
filterCondition
.
getSQL
()).
append
(
')'
);
...
...
h2/src/main/org/h2/expression/aggregate/Aggregate.java
浏览文件 @
afa9a0b5
...
...
@@ -29,7 +29,6 @@ import org.h2.table.Table;
import
org.h2.table.TableFilter
;
import
org.h2.util.StatementBuilder
;
import
org.h2.util.StringUtils
;
import
org.h2.util.ValueHashMap
;
import
org.h2.value.DataType
;
import
org.h2.value.Value
;
import
org.h2.value.ValueArray
;
...
...
@@ -285,8 +284,8 @@ public class Aggregate extends AbstractAggregate {
}
@Override
protected
void
updateAggregate
(
Session
session
,
SelectGroups
group
Data
)
{
AggregateData
data
=
getData
(
session
,
groupData
)
;
protected
void
updateAggregate
(
Session
session
,
Object
aggregate
Data
)
{
AggregateData
data
=
(
AggregateData
)
aggregateData
;
Value
v
=
on
==
null
?
null
:
on
.
getValue
(
session
);
if
(
type
==
AggregateType
.
GROUP_CONCAT
)
{
if
(
v
!=
ValueNull
.
INSTANCE
)
{
...
...
@@ -326,6 +325,11 @@ public class Aggregate extends AbstractAggregate {
return
v
;
}
@Override
protected
Object
createAggregateData
()
{
return
AggregateData
.
create
(
type
);
}
@Override
public
Value
getValue
(
Session
session
)
{
if
(
select
.
isQuickAggregateQuery
())
{
...
...
@@ -364,7 +368,10 @@ public class Aggregate extends AbstractAggregate {
if
(
groupData
==
null
)
{
throw
DbException
.
get
(
ErrorCode
.
INVALID_USE_OF_AGGREGATE_FUNCTION_1
,
getSQL
());
}
AggregateData
data
=
getData
(
session
,
groupData
);
AggregateData
data
=
(
AggregateData
)
getData
(
session
,
groupData
,
true
);
if
(
data
==
null
)
{
data
=
(
AggregateData
)
createAggregateData
();
}
switch
(
type
)
{
case
GROUP_CONCAT:
{
Value
[]
array
=
((
AggregateDataCollecting
)
data
).
getArray
();
...
...
@@ -419,32 +426,6 @@ public class Aggregate extends AbstractAggregate {
}
}
private
AggregateData
getData
(
Session
session
,
SelectGroups
groupData
)
{
AggregateData
data
;
ValueArray
key
;
if
(
over
!=
null
&&
(
key
=
over
.
getCurrentKey
(
session
))
!=
null
)
{
@SuppressWarnings
(
"unchecked"
)
ValueHashMap
<
AggregateData
>
map
=
(
ValueHashMap
<
AggregateData
>)
groupData
.
getCurrentGroupExprData
(
this
,
true
);
if
(
map
==
null
)
{
map
=
new
ValueHashMap
<>();
groupData
.
setCurrentGroupExprData
(
this
,
map
,
true
);
}
data
=
map
.
get
(
key
);
if
(
data
==
null
)
{
data
=
AggregateData
.
create
(
type
);
map
.
put
(
key
,
data
);
}
}
else
{
data
=
(
AggregateData
)
groupData
.
getCurrentGroupExprData
(
this
,
over
!=
null
);
if
(
data
==
null
)
{
data
=
AggregateData
.
create
(
type
);
groupData
.
setCurrentGroupExprData
(
this
,
data
,
over
!=
null
);
}
}
return
data
;
}
@Override
public
int
getType
()
{
return
dataType
;
...
...
h2/src/main/org/h2/expression/aggregate/JavaAggregate.java
浏览文件 @
afa9a0b5
...
...
@@ -20,7 +20,6 @@ import org.h2.message.DbException;
import
org.h2.table.ColumnResolver
;
import
org.h2.table.TableFilter
;
import
org.h2.util.StatementBuilder
;
import
org.h2.util.ValueHashMap
;
import
org.h2.value.DataType
;
import
org.h2.value.Value
;
import
org.h2.value.ValueArray
;
...
...
@@ -148,9 +147,13 @@ public class JavaAggregate extends AbstractAggregate {
super
.
setEvaluatable
(
tableFilter
,
b
);
}
private
Aggregate
getInstance
()
throws
SQLException
{
private
Aggregate
getInstance
()
{
Aggregate
agg
=
userAggregate
.
getInstance
();
agg
.
init
(
userConnection
);
try
{
agg
.
init
(
userConnection
);
}
catch
(
SQLException
ex
)
{
throw
DbException
.
convert
(
ex
);
}
return
agg
;
}
...
...
@@ -164,7 +167,7 @@ public class JavaAggregate extends AbstractAggregate {
Aggregate
agg
;
if
(
distinct
)
{
agg
=
getInstance
();
AggregateDataCollecting
data
=
getDataDistinct
(
session
,
groupData
,
true
);
AggregateDataCollecting
data
=
(
AggregateDataCollecting
)
getData
(
session
,
groupData
,
true
);
if
(
data
!=
null
)
{
for
(
Value
value
:
data
.
values
)
{
if
(
args
.
length
==
1
)
{
...
...
@@ -180,7 +183,7 @@ public class JavaAggregate extends AbstractAggregate {
}
}
}
else
{
agg
=
getData
(
session
,
groupData
,
true
);
agg
=
(
Aggregate
)
getData
(
session
,
groupData
,
true
);
if
(
agg
==
null
)
{
agg
=
getInstance
();
}
...
...
@@ -196,10 +199,10 @@ public class JavaAggregate extends AbstractAggregate {
}
@Override
protected
void
updateAggregate
(
Session
session
,
SelectGroups
group
Data
)
{
protected
void
updateAggregate
(
Session
session
,
Object
aggregate
Data
)
{
try
{
if
(
distinct
)
{
AggregateDataCollecting
data
=
getDataDistinct
(
session
,
groupData
,
false
)
;
AggregateDataCollecting
data
=
(
AggregateDataCollecting
)
aggregateData
;
Value
[]
argValues
=
new
Value
[
args
.
length
];
Value
arg
=
null
;
for
(
int
i
=
0
,
len
=
args
.
length
;
i
<
len
;
i
++)
{
...
...
@@ -209,7 +212,7 @@ public class JavaAggregate extends AbstractAggregate {
}
data
.
add
(
session
.
getDatabase
(),
dataType
,
true
,
args
.
length
==
1
?
arg
:
ValueArray
.
get
(
argValues
));
}
else
{
Aggregate
agg
=
getData
(
session
,
groupData
,
false
)
;
Aggregate
agg
=
(
Aggregate
)
aggregateData
;
Object
[]
argValues
=
new
Object
[
args
.
length
];
Object
arg
=
null
;
for
(
int
i
=
0
,
len
=
args
.
length
;
i
<
len
;
i
++)
{
...
...
@@ -232,73 +235,9 @@ public class JavaAggregate extends AbstractAggregate {
}
}
private
Aggregate
getData
(
Session
session
,
SelectGroups
groupData
,
boolean
ifExists
)
throws
SQLException
{
Aggregate
data
;
ValueArray
key
;
if
(
over
!=
null
&&
(
key
=
over
.
getCurrentKey
(
session
))
!=
null
)
{
@SuppressWarnings
(
"unchecked"
)
ValueHashMap
<
Aggregate
>
map
=
(
ValueHashMap
<
Aggregate
>)
groupData
.
getCurrentGroupExprData
(
this
,
true
);
if
(
map
==
null
)
{
if
(
ifExists
)
{
return
null
;
}
map
=
new
ValueHashMap
<>();
groupData
.
setCurrentGroupExprData
(
this
,
map
,
true
);
}
data
=
map
.
get
(
key
);
if
(
data
==
null
)
{
if
(
ifExists
)
{
return
null
;
}
data
=
getInstance
();
map
.
put
(
key
,
data
);
}
}
else
{
data
=
(
Aggregate
)
groupData
.
getCurrentGroupExprData
(
this
,
over
!=
null
);
if
(
data
==
null
)
{
if
(
ifExists
)
{
return
null
;
}
data
=
getInstance
();
groupData
.
setCurrentGroupExprData
(
this
,
data
,
over
!=
null
);
}
}
return
data
;
}
private
AggregateDataCollecting
getDataDistinct
(
Session
session
,
SelectGroups
groupData
,
boolean
ifExists
)
{
AggregateDataCollecting
data
;
ValueArray
key
;
if
(
over
!=
null
&&
(
key
=
over
.
getCurrentKey
(
session
))
!=
null
)
{
@SuppressWarnings
(
"unchecked"
)
ValueHashMap
<
AggregateDataCollecting
>
map
=
(
ValueHashMap
<
AggregateDataCollecting
>)
groupData
.
getCurrentGroupExprData
(
this
,
true
);
if
(
map
==
null
)
{
if
(
ifExists
)
{
return
null
;
}
map
=
new
ValueHashMap
<>();
groupData
.
setCurrentGroupExprData
(
this
,
map
,
true
);
}
data
=
map
.
get
(
key
);
if
(
data
==
null
)
{
if
(
ifExists
)
{
return
null
;
}
data
=
new
AggregateDataCollecting
();
map
.
put
(
key
,
data
);
}
}
else
{
data
=
(
AggregateDataCollecting
)
groupData
.
getCurrentGroupExprData
(
this
,
over
!=
null
);
if
(
data
==
null
)
{
if
(
ifExists
)
{
return
null
;
}
data
=
new
AggregateDataCollecting
();
groupData
.
setCurrentGroupExprData
(
this
,
data
,
over
!=
null
);
}
}
return
data
;
@Override
protected
Object
createAggregateData
()
{
return
distinct
?
new
AggregateDataCollecting
()
:
getInstance
();
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论