Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
f2584f9a
提交
f2584f9a
authored
9月 21, 2018
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use AggregateDataCollecting for DISTINCT COUNT
上级
021c29e1
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
24 行增加
和
19 行删除
+24
-19
Aggregate.java
h2/src/main/org/h2/expression/aggregate/Aggregate.java
+7
-1
AggregateData.java
h2/src/main/org/h2/expression/aggregate/AggregateData.java
+8
-3
AggregateDataCollecting.java
.../org/h2/expression/aggregate/AggregateDataCollecting.java
+9
-0
AggregateDataCount.java
.../main/org/h2/expression/aggregate/AggregateDataCount.java
+0
-15
没有找到文件。
h2/src/main/org/h2/expression/aggregate/Aggregate.java
浏览文件 @
f2584f9a
...
@@ -369,7 +369,7 @@ public class Aggregate extends AbstractAggregate {
...
@@ -369,7 +369,7 @@ public class Aggregate extends AbstractAggregate {
@Override
@Override
protected
Object
createAggregateData
()
{
protected
Object
createAggregateData
()
{
return
AggregateData
.
create
(
type
);
return
AggregateData
.
create
(
type
,
distinct
);
}
}
@Override
@Override
...
@@ -417,6 +417,12 @@ public class Aggregate extends AbstractAggregate {
...
@@ -417,6 +417,12 @@ public class Aggregate extends AbstractAggregate {
data
=
(
AggregateData
)
createAggregateData
();
data
=
(
AggregateData
)
createAggregateData
();
}
}
switch
(
type
)
{
switch
(
type
)
{
case
COUNT:
{
if
(!
distinct
)
{
return
data
.
getValue
(
session
.
getDatabase
(),
dataType
,
distinct
);
}
return
ValueLong
.
get
(((
AggregateDataCollecting
)
data
).
getCount
());
}
case
GROUP_CONCAT:
{
case
GROUP_CONCAT:
{
Value
[]
array
=
((
AggregateDataCollecting
)
data
).
getArray
();
Value
[]
array
=
((
AggregateDataCollecting
)
data
).
getArray
();
if
(
array
==
null
)
{
if
(
array
==
null
)
{
...
...
h2/src/main/org/h2/expression/aggregate/AggregateData.java
浏览文件 @
f2584f9a
...
@@ -18,20 +18,24 @@ abstract class AggregateData {
...
@@ -18,20 +18,24 @@ abstract class AggregateData {
* Create an AggregateData object of the correct sub-type.
* Create an AggregateData object of the correct sub-type.
*
*
* @param aggregateType the type of the aggregate operation
* @param aggregateType the type of the aggregate operation
* @param distinct if the calculation should be distinct
* @return the aggregate data object of the specified type
* @return the aggregate data object of the specified type
*/
*/
static
AggregateData
create
(
AggregateType
aggregateType
)
{
static
AggregateData
create
(
AggregateType
aggregateType
,
boolean
distinct
)
{
switch
(
aggregateType
)
{
switch
(
aggregateType
)
{
case
SELECTIVITY:
case
SELECTIVITY:
return
new
AggregateDataSelectivity
();
return
new
AggregateDataSelectivity
();
case
GROUP_CONCAT:
case
GROUP_CONCAT:
case
ARRAY_AGG:
case
ARRAY_AGG:
case
MEDIAN:
case
MEDIAN:
return
new
AggregateDataCollecting
()
;
break
;
case
COUNT_ALL:
case
COUNT_ALL:
return
new
AggregateDataCountAll
();
return
new
AggregateDataCountAll
();
case
COUNT:
case
COUNT:
return
new
AggregateDataCount
();
if
(!
distinct
)
{
return
new
AggregateDataCount
();
}
break
;
case
HISTOGRAM:
case
HISTOGRAM:
return
new
AggregateDataHistogram
();
return
new
AggregateDataHistogram
();
case
MODE:
case
MODE:
...
@@ -41,6 +45,7 @@ abstract class AggregateData {
...
@@ -41,6 +45,7 @@ abstract class AggregateData {
default
:
default
:
return
new
AggregateDataDefault
(
aggregateType
);
return
new
AggregateDataDefault
(
aggregateType
);
}
}
return
new
AggregateDataCollecting
();
}
}
/**
/**
...
...
h2/src/main/org/h2/expression/aggregate/AggregateDataCollecting.java
浏览文件 @
f2584f9a
...
@@ -43,6 +43,15 @@ class AggregateDataCollecting extends AggregateData {
...
@@ -43,6 +43,15 @@ class AggregateDataCollecting extends AggregateData {
return
null
;
return
null
;
}
}
/**
* Returns the count of values.
*
* @return the count of values
*/
int
getCount
()
{
return
values
!=
null
?
values
.
size
()
:
0
;
}
/**
/**
* Returns array with values or {@code null}.
* Returns array with values or {@code null}.
*
*
...
...
h2/src/main/org/h2/expression/aggregate/AggregateDataCount.java
浏览文件 @
f2584f9a
...
@@ -6,7 +6,6 @@
...
@@ -6,7 +6,6 @@
package
org
.
h2
.
expression
.
aggregate
;
package
org
.
h2
.
expression
.
aggregate
;
import
org.h2.engine.Database
;
import
org.h2.engine.Database
;
import
org.h2.util.ValueHashMap
;
import
org.h2.value.Value
;
import
org.h2.value.Value
;
import
org.h2.value.ValueLong
;
import
org.h2.value.ValueLong
;
import
org.h2.value.ValueNull
;
import
org.h2.value.ValueNull
;
...
@@ -16,7 +15,6 @@ import org.h2.value.ValueNull;
...
@@ -16,7 +15,6 @@ import org.h2.value.ValueNull;
*/
*/
class
AggregateDataCount
extends
AggregateData
{
class
AggregateDataCount
extends
AggregateData
{
private
long
count
;
private
long
count
;
private
ValueHashMap
<
AggregateDataCount
>
distinctValues
;
@Override
@Override
void
add
(
Database
database
,
int
dataType
,
boolean
distinct
,
Value
v
)
{
void
add
(
Database
database
,
int
dataType
,
boolean
distinct
,
Value
v
)
{
...
@@ -24,23 +22,10 @@ class AggregateDataCount extends AggregateData {
...
@@ -24,23 +22,10 @@ class AggregateDataCount extends AggregateData {
return
;
return
;
}
}
count
++;
count
++;
if
(
distinct
)
{
if
(
distinctValues
==
null
)
{
distinctValues
=
ValueHashMap
.
newInstance
();
}
distinctValues
.
put
(
v
,
this
);
}
}
}
@Override
@Override
Value
getValue
(
Database
database
,
int
dataType
,
boolean
distinct
)
{
Value
getValue
(
Database
database
,
int
dataType
,
boolean
distinct
)
{
if
(
distinct
)
{
if
(
distinctValues
!=
null
)
{
count
=
distinctValues
.
size
();
}
else
{
count
=
0
;
}
}
return
ValueLong
.
get
(
count
).
convertTo
(
dataType
);
return
ValueLong
.
get
(
count
).
convertTo
(
dataType
);
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论