Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
bd864e33
提交
bd864e33
authored
6 年前
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move more code to AbstractAggregate
上级
31034342
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
98 行增加
和
81 行删除
+98
-81
AbstractAggregate.java
...c/main/org/h2/expression/aggregate/AbstractAggregate.java
+75
-0
Aggregate.java
h2/src/main/org/h2/expression/aggregate/Aggregate.java
+14
-50
JavaAggregate.java
h2/src/main/org/h2/expression/aggregate/JavaAggregate.java
+9
-31
没有找到文件。
h2/src/main/org/h2/expression/aggregate/AbstractAggregate.java
浏览文件 @
bd864e33
...
...
@@ -5,6 +5,9 @@
*/
package
org
.
h2
.
expression
.
aggregate
;
import
org.h2.command.dml.Select
;
import
org.h2.command.dml.SelectGroups
;
import
org.h2.engine.Session
;
import
org.h2.expression.Expression
;
import
org.h2.table.ColumnResolver
;
import
org.h2.table.TableFilter
;
...
...
@@ -14,10 +17,21 @@ import org.h2.table.TableFilter;
*/
public
abstract
class
AbstractAggregate
extends
Expression
{
protected
final
Select
select
;
protected
final
boolean
distinct
;
protected
Expression
filterCondition
;
protected
Window
over
;
private
int
lastGroupRowId
;
AbstractAggregate
(
Select
select
,
boolean
distinct
)
{
this
.
select
=
select
;
this
.
distinct
=
distinct
;
}
/**
* Sets the FILTER condition.
*
...
...
@@ -58,6 +72,67 @@ public abstract class AbstractAggregate extends Expression {
}
}
@Override
public
void
updateAggregate
(
Session
session
,
boolean
window
)
{
if
(
window
!=
(
over
!=
null
))
{
if
(!
window
&&
select
.
isWindowQuery
())
{
updateGroupAggregates
(
session
);
if
(
filterCondition
!=
null
)
{
filterCondition
.
updateAggregate
(
session
,
false
);
}
over
.
updateAggregate
(
session
,
false
);
}
return
;
}
// TODO aggregates: check nested MIN(MAX(ID)) and so on
// if (on != null) {
// on.updateAggregate();
// }
SelectGroups
groupData
=
select
.
getGroupDataIfCurrent
(
window
);
if
(
groupData
==
null
)
{
// this is a different level (the enclosing query)
return
;
}
int
groupRowId
=
groupData
.
getCurrentGroupRowId
();
if
(
lastGroupRowId
==
groupRowId
)
{
// already visited
return
;
}
lastGroupRowId
=
groupRowId
;
if
(
over
!=
null
)
{
if
(!
select
.
isGroupQuery
())
{
over
.
updateAggregate
(
session
,
true
);
}
}
if
(
filterCondition
!=
null
)
{
if
(!
filterCondition
.
getBooleanValue
(
session
))
{
return
;
}
}
updateAggregate
(
session
,
groupData
);
}
/**
* Updates an aggregate value.
*
* @param session
* the session
* @param groupData
* group data from the select
*/
protected
abstract
void
updateAggregate
(
Session
session
,
SelectGroups
groupData
);
/**
* Invoked when processing group stage of grouped window queries to update
* arguments of this aggregate.
*
* @param session
* the session
*/
protected
abstract
void
updateGroupAggregates
(
Session
session
);
protected
StringBuilder
appendTailConditions
(
StringBuilder
builder
)
{
if
(
filterCondition
!=
null
)
{
builder
.
append
(
" FILTER (WHERE "
).
append
(
filterCondition
.
getSQL
()).
append
(
')'
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/expression/aggregate/Aggregate.java
浏览文件 @
bd864e33
...
...
@@ -155,8 +155,6 @@ public class Aggregate extends AbstractAggregate {
private
static
final
HashMap
<
String
,
AggregateType
>
AGGREGATES
=
new
HashMap
<>(
64
);
private
final
AggregateType
type
;
private
final
Select
select
;
private
final
boolean
distinct
;
private
Expression
on
;
private
Expression
groupConcatSeparator
;
...
...
@@ -165,7 +163,6 @@ public class Aggregate extends AbstractAggregate {
private
int
dataType
,
scale
;
private
long
precision
;
private
int
displaySize
;
private
int
lastGroupRowId
;
/**
* Create a new aggregate object.
...
...
@@ -180,10 +177,9 @@ public class Aggregate extends AbstractAggregate {
* if distinct is used
*/
public
Aggregate
(
AggregateType
type
,
Expression
on
,
Select
select
,
boolean
distinct
)
{
super
(
select
,
distinct
);
this
.
type
=
type
;
this
.
on
=
on
;
this
.
select
=
select
;
this
.
distinct
=
distinct
;
}
static
{
...
...
@@ -289,51 +285,7 @@ public class Aggregate extends AbstractAggregate {
}
@Override
public
void
updateAggregate
(
Session
session
,
boolean
window
)
{
if
(
window
!=
(
over
!=
null
))
{
if
(!
window
&&
select
.
isWindowQuery
())
{
if
(
on
!=
null
)
{
on
.
updateAggregate
(
session
,
false
);
}
if
(
orderByList
!=
null
)
{
for
(
SelectOrderBy
orderBy
:
orderByList
)
{
orderBy
.
expression
.
updateAggregate
(
session
,
false
);
}
}
if
(
filterCondition
!=
null
)
{
filterCondition
.
updateAggregate
(
session
,
false
);
}
over
.
updateAggregate
(
session
,
false
);
}
return
;
}
// TODO aggregates: check nested MIN(MAX(ID)) and so on
// if (on != null) {
// on.updateAggregate();
// }
SelectGroups
groupData
=
select
.
getGroupDataIfCurrent
(
window
);
if
(
groupData
==
null
)
{
// this is a different level (the enclosing query)
return
;
}
int
groupRowId
=
groupData
.
getCurrentGroupRowId
();
if
(
lastGroupRowId
==
groupRowId
)
{
// already visited
return
;
}
lastGroupRowId
=
groupRowId
;
if
(
over
!=
null
)
{
if
(!
select
.
isGroupQuery
())
{
over
.
updateAggregate
(
session
,
true
);
}
}
if
(
filterCondition
!=
null
)
{
if
(!
filterCondition
.
getBooleanValue
(
session
))
{
return
;
}
}
protected
void
updateAggregate
(
Session
session
,
SelectGroups
groupData
)
{
AggregateData
data
=
getData
(
session
,
groupData
);
Value
v
=
on
==
null
?
null
:
on
.
getValue
(
session
);
if
(
type
==
AggregateType
.
GROUP_CONCAT
)
{
...
...
@@ -348,6 +300,18 @@ public class Aggregate extends AbstractAggregate {
data
.
add
(
session
.
getDatabase
(),
dataType
,
distinct
,
v
);
}
@Override
protected
void
updateGroupAggregates
(
Session
session
)
{
if
(
on
!=
null
)
{
on
.
updateAggregate
(
session
,
false
);
}
if
(
orderByList
!=
null
)
{
for
(
SelectOrderBy
orderBy
:
orderByList
)
{
orderBy
.
expression
.
updateAggregate
(
session
,
false
);
}
}
}
private
Value
updateCollecting
(
Session
session
,
Value
v
)
{
if
(
orderByList
!=
null
)
{
int
size
=
orderByList
.
size
();
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/expression/aggregate/JavaAggregate.java
浏览文件 @
bd864e33
...
...
@@ -32,19 +32,15 @@ import org.h2.value.ValueNull;
public
class
JavaAggregate
extends
AbstractAggregate
{
private
final
UserAggregate
userAggregate
;
private
final
Select
select
;
private
final
Expression
[]
args
;
private
int
[]
argTypes
;
private
final
boolean
distinct
;
private
int
dataType
;
private
Connection
userConnection
;
private
int
lastGroupRowId
;
public
JavaAggregate
(
UserAggregate
userAggregate
,
Expression
[]
args
,
Select
select
,
boolean
distinct
)
{
super
(
select
,
distinct
);
this
.
userAggregate
=
userAggregate
;
this
.
args
=
args
;
this
.
select
=
select
;
this
.
distinct
=
distinct
;
}
@Override
...
...
@@ -200,32 +196,7 @@ public class JavaAggregate extends AbstractAggregate {
}
@Override
public
void
updateAggregate
(
Session
session
,
boolean
window
)
{
if
(
window
!=
(
over
!=
null
))
{
return
;
}
SelectGroups
groupData
=
select
.
getGroupDataIfCurrent
(
window
);
if
(
groupData
==
null
)
{
// this is a different level (the enclosing query)
return
;
}
int
groupRowId
=
groupData
.
getCurrentGroupRowId
();
if
(
lastGroupRowId
==
groupRowId
)
{
// already visited
return
;
}
lastGroupRowId
=
groupRowId
;
if
(
over
!=
null
)
{
over
.
updateAggregate
(
session
,
true
);
}
if
(
filterCondition
!=
null
)
{
if
(!
filterCondition
.
getBooleanValue
(
session
))
{
return
;
}
}
protected
void
updateAggregate
(
Session
session
,
SelectGroups
groupData
)
{
try
{
if
(
distinct
)
{
AggregateDataCollecting
data
=
getDataDistinct
(
session
,
groupData
,
false
);
...
...
@@ -254,6 +225,13 @@ public class JavaAggregate extends AbstractAggregate {
}
}
@Override
protected
void
updateGroupAggregates
(
Session
session
)
{
for
(
Expression
expr
:
args
)
{
expr
.
updateAggregate
(
session
,
false
);
}
}
private
Aggregate
getData
(
Session
session
,
SelectGroups
groupData
,
boolean
ifExists
)
throws
SQLException
{
Aggregate
data
;
ValueArray
key
;
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论