Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
92596a70
提交
92596a70
authored
9月 21, 2018
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Do not pass distinct flag to methods of AggregateData
上级
c5cb7339
隐藏空白字符变更
内嵌
并排
正在显示
11 个修改的文件
包含
70 行增加
和
41 行删除
+70
-41
Aggregate.java
h2/src/main/org/h2/expression/aggregate/Aggregate.java
+7
-4
AggregateData.java
h2/src/main/org/h2/expression/aggregate/AggregateData.java
+5
-7
AggregateDataCollecting.java
.../org/h2/expression/aggregate/AggregateDataCollecting.java
+15
-4
AggregateDataCount.java
.../main/org/h2/expression/aggregate/AggregateDataCount.java
+4
-5
AggregateDataCountAll.java
...in/org/h2/expression/aggregate/AggregateDataCountAll.java
+3
-9
AggregateDataDefault.java
...ain/org/h2/expression/aggregate/AggregateDataDefault.java
+2
-2
AggregateDataEnvelope.java
...in/org/h2/expression/aggregate/AggregateDataEnvelope.java
+2
-2
AggregateDataHistogram.java
...n/org/h2/expression/aggregate/AggregateDataHistogram.java
+13
-2
AggregateDataMode.java
...c/main/org/h2/expression/aggregate/AggregateDataMode.java
+2
-2
AggregateDataSelectivity.java
...org/h2/expression/aggregate/AggregateDataSelectivity.java
+15
-2
JavaAggregate.java
h2/src/main/org/h2/expression/aggregate/JavaAggregate.java
+2
-2
没有找到文件。
h2/src/main/org/h2/expression/aggregate/Aggregate.java
浏览文件 @
92596a70
...
...
@@ -192,6 +192,9 @@ public class Aggregate extends AbstractAggregate {
*/
public
Aggregate
(
AggregateType
type
,
Expression
on
,
Select
select
,
boolean
distinct
)
{
super
(
select
,
distinct
);
if
(
distinct
&&
type
==
AggregateType
.
COUNT_ALL
)
{
throw
DbException
.
throwInternalError
();
}
this
.
type
=
type
;
this
.
on
=
on
;
}
...
...
@@ -303,7 +306,7 @@ public class Aggregate extends AbstractAggregate {
v
=
updateCollecting
(
session
,
v
,
remembered
);
}
}
data
.
add
(
session
.
getDatabase
(),
dataType
,
distinct
,
v
);
data
.
add
(
session
.
getDatabase
(),
dataType
,
v
);
}
@Override
...
...
@@ -437,9 +440,9 @@ public class Aggregate extends AbstractAggregate {
AggregateDataDefault
d
=
new
AggregateDataDefault
(
type
);
Database
db
=
session
.
getDatabase
();
for
(
Value
v
:
c
)
{
d
.
add
(
db
,
dataType
,
false
,
v
);
d
.
add
(
db
,
dataType
,
v
);
}
return
d
.
getValue
(
db
,
dataType
,
false
);
return
d
.
getValue
(
db
,
dataType
);
}
break
;
case
GROUP_CONCAT:
{
...
...
@@ -500,7 +503,7 @@ public class Aggregate extends AbstractAggregate {
default
:
// Avoid compiler warning
}
return
data
.
getValue
(
session
.
getDatabase
(),
dataType
,
distinct
);
return
data
.
getValue
(
session
.
getDatabase
(),
dataType
);
}
@Override
...
...
h2/src/main/org/h2/expression/aggregate/AggregateData.java
浏览文件 @
92596a70
...
...
@@ -53,9 +53,9 @@ abstract class AggregateData {
}
break
;
case
SELECTIVITY:
return
new
AggregateDataSelectivity
();
return
new
AggregateDataSelectivity
(
distinct
);
case
HISTOGRAM:
return
new
AggregateDataHistogram
();
return
new
AggregateDataHistogram
(
distinct
);
case
MODE:
return
new
AggregateDataMode
();
case
ENVELOPE:
...
...
@@ -63,7 +63,7 @@ abstract class AggregateData {
default
:
throw
DbException
.
throwInternalError
(
"type="
+
aggregateType
);
}
return
new
AggregateDataCollecting
();
return
new
AggregateDataCollecting
(
distinct
);
}
/**
...
...
@@ -71,18 +71,16 @@ abstract class AggregateData {
*
* @param database the database
* @param dataType the datatype of the computed result
* @param distinct if the calculation should be distinct
* @param v the value
*/
abstract
void
add
(
Database
database
,
int
dataType
,
boolean
distinct
,
Value
v
);
abstract
void
add
(
Database
database
,
int
dataType
,
Value
v
);
/**
* Get the aggregate result.
*
* @param database the database
* @param dataType the datatype of the computed result
* @param distinct if distinct is used
* @return the value
*/
abstract
Value
getValue
(
Database
database
,
int
dataType
,
boolean
distinct
);
abstract
Value
getValue
(
Database
database
,
int
dataType
);
}
h2/src/main/org/h2/expression/aggregate/AggregateDataCollecting.java
浏览文件 @
92596a70
...
...
@@ -17,20 +17,31 @@ import org.h2.value.ValueNull;
/**
* Data stored while calculating an aggregate that needs collecting of all
* values.
* values
or a distinct aggregate
.
*
* <p>
* NULL values are not collected. {@link #getValue(Database, int
, boolean
)}
* NULL values are not collected. {@link #getValue(Database, int)}
* method returns {@code null}. Use {@link #getArray()} for instances of this
* class instead.
* </p>
*/
class
AggregateDataCollecting
extends
AggregateData
implements
Iterable
<
Value
>
{
private
final
boolean
distinct
;
Collection
<
Value
>
values
;
/**
* Creates new instance of data for collecting aggregates.
*
* @param distinct if distinct is used
*/
AggregateDataCollecting
(
boolean
distinct
)
{
this
.
distinct
=
distinct
;
}
@Override
void
add
(
Database
database
,
int
dataType
,
boolean
distinct
,
Value
v
)
{
void
add
(
Database
database
,
int
dataType
,
Value
v
)
{
if
(
v
==
ValueNull
.
INSTANCE
)
{
return
;
}
...
...
@@ -42,7 +53,7 @@ class AggregateDataCollecting extends AggregateData implements Iterable<Value> {
}
@Override
Value
getValue
(
Database
database
,
int
dataType
,
boolean
distinct
)
{
Value
getValue
(
Database
database
,
int
dataType
)
{
return
null
;
}
...
...
h2/src/main/org/h2/expression/aggregate/AggregateDataCount.java
浏览文件 @
92596a70
...
...
@@ -17,15 +17,14 @@ class AggregateDataCount extends AggregateData {
private
long
count
;
@Override
void
add
(
Database
database
,
int
dataType
,
boolean
distinct
,
Value
v
)
{
if
(
v
=
=
ValueNull
.
INSTANCE
)
{
return
;
void
add
(
Database
database
,
int
dataType
,
Value
v
)
{
if
(
v
!
=
ValueNull
.
INSTANCE
)
{
count
++
;
}
count
++;
}
@Override
Value
getValue
(
Database
database
,
int
dataType
,
boolean
distinct
)
{
Value
getValue
(
Database
database
,
int
dataType
)
{
return
ValueLong
.
get
(
count
).
convertTo
(
dataType
);
}
...
...
h2/src/main/org/h2/expression/aggregate/AggregateDataCountAll.java
浏览文件 @
92596a70
...
...
@@ -6,7 +6,6 @@
package
org
.
h2
.
expression
.
aggregate
;
import
org.h2.engine.Database
;
import
org.h2.message.DbException
;
import
org.h2.value.Value
;
import
org.h2.value.ValueLong
;
...
...
@@ -14,21 +13,16 @@ import org.h2.value.ValueLong;
* Data stored while calculating a COUNT(*) aggregate.
*/
class
AggregateDataCountAll
extends
AggregateData
{
private
long
count
;
@Override
void
add
(
Database
database
,
int
dataType
,
boolean
distinct
,
Value
v
)
{
if
(
distinct
)
{
throw
DbException
.
throwInternalError
();
}
void
add
(
Database
database
,
int
dataType
,
Value
v
)
{
count
++;
}
@Override
Value
getValue
(
Database
database
,
int
dataType
,
boolean
distinct
)
{
if
(
distinct
)
{
throw
DbException
.
throwInternalError
();
}
Value
getValue
(
Database
database
,
int
dataType
)
{
return
ValueLong
.
get
(
count
).
convertTo
(
dataType
);
}
...
...
h2/src/main/org/h2/expression/aggregate/AggregateDataDefault.java
浏览文件 @
92596a70
...
...
@@ -33,7 +33,7 @@ class AggregateDataDefault extends AggregateData {
}
@Override
void
add
(
Database
database
,
int
dataType
,
boolean
distinct
,
Value
v
)
{
void
add
(
Database
database
,
int
dataType
,
Value
v
)
{
if
(
v
==
ValueNull
.
INSTANCE
)
{
return
;
}
...
...
@@ -119,7 +119,7 @@ class AggregateDataDefault extends AggregateData {
}
@Override
Value
getValue
(
Database
database
,
int
dataType
,
boolean
distinct
)
{
Value
getValue
(
Database
database
,
int
dataType
)
{
Value
v
=
null
;
switch
(
aggregateType
)
{
case
SUM:
...
...
h2/src/main/org/h2/expression/aggregate/AggregateDataEnvelope.java
浏览文件 @
92596a70
...
...
@@ -57,7 +57,7 @@ class AggregateDataEnvelope extends AggregateData {
}
@Override
void
add
(
Database
database
,
int
dataType
,
boolean
distinct
,
Value
v
)
{
void
add
(
Database
database
,
int
dataType
,
Value
v
)
{
if
(
v
==
ValueNull
.
INSTANCE
)
{
return
;
}
...
...
@@ -65,7 +65,7 @@ class AggregateDataEnvelope extends AggregateData {
}
@Override
Value
getValue
(
Database
database
,
int
dataType
,
boolean
distinct
)
{
Value
getValue
(
Database
database
,
int
dataType
)
{
return
ValueGeometry
.
fromEnvelope
(
envelope
);
}
...
...
h2/src/main/org/h2/expression/aggregate/AggregateDataHistogram.java
浏览文件 @
92596a70
...
...
@@ -22,10 +22,21 @@ import org.h2.value.ValueLong;
*/
class
AggregateDataHistogram
extends
AggregateData
{
private
final
boolean
distinct
;
private
ValueHashMap
<
LongDataCounter
>
distinctValues
;
/**
* Creates new instance of data for HISTOGRAM aggregate.
*
* @param distinct if distinct is used
*/
AggregateDataHistogram
(
boolean
distinct
)
{
this
.
distinct
=
distinct
;
}
@Override
void
add
(
Database
database
,
int
dataType
,
boolean
distinct
,
Value
v
)
{
void
add
(
Database
database
,
int
dataType
,
Value
v
)
{
if
(
distinctValues
==
null
)
{
distinctValues
=
ValueHashMap
.
newInstance
();
}
...
...
@@ -41,7 +52,7 @@ class AggregateDataHistogram extends AggregateData {
}
@Override
Value
getValue
(
Database
database
,
int
dataType
,
boolean
distinct
)
{
Value
getValue
(
Database
database
,
int
dataType
)
{
if
(
distinctValues
==
null
)
{
return
ValueArray
.
get
(
new
Value
[
0
]).
convertTo
(
dataType
);
}
...
...
h2/src/main/org/h2/expression/aggregate/AggregateDataMode.java
浏览文件 @
92596a70
...
...
@@ -20,7 +20,7 @@ class AggregateDataMode extends AggregateData {
private
ValueHashMap
<
LongDataCounter
>
distinctValues
;
@Override
void
add
(
Database
database
,
int
dataType
,
boolean
distinct
,
Value
v
)
{
void
add
(
Database
database
,
int
dataType
,
Value
v
)
{
if
(
v
==
ValueNull
.
INSTANCE
)
{
return
;
}
...
...
@@ -36,7 +36,7 @@ class AggregateDataMode extends AggregateData {
}
@Override
Value
getValue
(
Database
database
,
int
dataType
,
boolean
distinct
)
{
Value
getValue
(
Database
database
,
int
dataType
)
{
Value
v
=
ValueNull
.
INSTANCE
;
if
(
distinctValues
!=
null
)
{
long
count
=
0L
;
...
...
h2/src/main/org/h2/expression/aggregate/AggregateDataSelectivity.java
浏览文件 @
92596a70
...
...
@@ -15,12 +15,24 @@ import org.h2.value.ValueInt;
* Data stored while calculating a SELECTIVITY aggregate.
*/
class
AggregateDataSelectivity
extends
AggregateData
{
private
final
boolean
distinct
;
private
long
count
;
private
IntIntHashMap
distinctHashes
;
private
double
m2
;
/**
* Creates new instance of data for SELECTIVITY aggregate.
*
* @param distinct if distinct is used
*/
AggregateDataSelectivity
(
boolean
distinct
)
{
this
.
distinct
=
distinct
;
}
@Override
void
add
(
Database
database
,
int
dataType
,
boolean
distinct
,
Value
v
)
{
void
add
(
Database
database
,
int
dataType
,
Value
v
)
{
count
++;
if
(
distinctHashes
==
null
)
{
distinctHashes
=
new
IntIntHashMap
();
...
...
@@ -36,7 +48,7 @@ class AggregateDataSelectivity extends AggregateData {
}
@Override
Value
getValue
(
Database
database
,
int
dataType
,
boolean
distinct
)
{
Value
getValue
(
Database
database
,
int
dataType
)
{
if
(
distinct
)
{
count
=
0
;
}
...
...
@@ -53,4 +65,5 @@ class AggregateDataSelectivity extends AggregateData {
v
=
ValueInt
.
get
(
s
);
return
v
.
convertTo
(
dataType
);
}
}
h2/src/main/org/h2/expression/aggregate/JavaAggregate.java
浏览文件 @
92596a70
...
...
@@ -209,7 +209,7 @@ public class JavaAggregate extends AbstractAggregate {
arg
=
arg
.
convertTo
(
argTypes
[
i
]);
argValues
[
i
]
=
arg
;
}
data
.
add
(
session
.
getDatabase
(),
dataType
,
true
,
args
.
length
==
1
?
arg
:
ValueArray
.
get
(
argValues
));
data
.
add
(
session
.
getDatabase
(),
dataType
,
args
.
length
==
1
?
arg
:
ValueArray
.
get
(
argValues
));
}
else
{
Aggregate
agg
=
(
Aggregate
)
aggregateData
;
Object
[]
argValues
=
new
Object
[
args
.
length
];
...
...
@@ -254,7 +254,7 @@ public class JavaAggregate extends AbstractAggregate {
@Override
protected
Object
createAggregateData
()
{
return
distinct
?
new
AggregateDataCollecting
()
:
getInstance
();
return
distinct
?
new
AggregateDataCollecting
(
true
)
:
getInstance
();
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论