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 {
...
@@ -192,6 +192,9 @@ public class Aggregate extends AbstractAggregate {
*/
*/
public
Aggregate
(
AggregateType
type
,
Expression
on
,
Select
select
,
boolean
distinct
)
{
public
Aggregate
(
AggregateType
type
,
Expression
on
,
Select
select
,
boolean
distinct
)
{
super
(
select
,
distinct
);
super
(
select
,
distinct
);
if
(
distinct
&&
type
==
AggregateType
.
COUNT_ALL
)
{
throw
DbException
.
throwInternalError
();
}
this
.
type
=
type
;
this
.
type
=
type
;
this
.
on
=
on
;
this
.
on
=
on
;
}
}
...
@@ -303,7 +306,7 @@ public class Aggregate extends AbstractAggregate {
...
@@ -303,7 +306,7 @@ public class Aggregate extends AbstractAggregate {
v
=
updateCollecting
(
session
,
v
,
remembered
);
v
=
updateCollecting
(
session
,
v
,
remembered
);
}
}
}
}
data
.
add
(
session
.
getDatabase
(),
dataType
,
distinct
,
v
);
data
.
add
(
session
.
getDatabase
(),
dataType
,
v
);
}
}
@Override
@Override
...
@@ -437,9 +440,9 @@ public class Aggregate extends AbstractAggregate {
...
@@ -437,9 +440,9 @@ public class Aggregate extends AbstractAggregate {
AggregateDataDefault
d
=
new
AggregateDataDefault
(
type
);
AggregateDataDefault
d
=
new
AggregateDataDefault
(
type
);
Database
db
=
session
.
getDatabase
();
Database
db
=
session
.
getDatabase
();
for
(
Value
v
:
c
)
{
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
;
break
;
case
GROUP_CONCAT:
{
case
GROUP_CONCAT:
{
...
@@ -500,7 +503,7 @@ public class Aggregate extends AbstractAggregate {
...
@@ -500,7 +503,7 @@ public class Aggregate extends AbstractAggregate {
default
:
default
:
// Avoid compiler warning
// Avoid compiler warning
}
}
return
data
.
getValue
(
session
.
getDatabase
(),
dataType
,
distinct
);
return
data
.
getValue
(
session
.
getDatabase
(),
dataType
);
}
}
@Override
@Override
...
...
h2/src/main/org/h2/expression/aggregate/AggregateData.java
浏览文件 @
92596a70
...
@@ -53,9 +53,9 @@ abstract class AggregateData {
...
@@ -53,9 +53,9 @@ abstract class AggregateData {
}
}
break
;
break
;
case
SELECTIVITY:
case
SELECTIVITY:
return
new
AggregateDataSelectivity
();
return
new
AggregateDataSelectivity
(
distinct
);
case
HISTOGRAM:
case
HISTOGRAM:
return
new
AggregateDataHistogram
();
return
new
AggregateDataHistogram
(
distinct
);
case
MODE:
case
MODE:
return
new
AggregateDataMode
();
return
new
AggregateDataMode
();
case
ENVELOPE:
case
ENVELOPE:
...
@@ -63,7 +63,7 @@ abstract class AggregateData {
...
@@ -63,7 +63,7 @@ abstract class AggregateData {
default
:
default
:
throw
DbException
.
throwInternalError
(
"type="
+
aggregateType
);
throw
DbException
.
throwInternalError
(
"type="
+
aggregateType
);
}
}
return
new
AggregateDataCollecting
();
return
new
AggregateDataCollecting
(
distinct
);
}
}
/**
/**
...
@@ -71,18 +71,16 @@ abstract class AggregateData {
...
@@ -71,18 +71,16 @@ abstract class AggregateData {
*
*
* @param database the database
* @param database the database
* @param dataType the datatype of the computed result
* @param dataType the datatype of the computed result
* @param distinct if the calculation should be distinct
* @param v the value
* @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.
* Get the aggregate result.
*
*
* @param database the database
* @param database the database
* @param dataType the datatype of the computed result
* @param dataType the datatype of the computed result
* @param distinct if distinct is used
* @return the value
* @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;
...
@@ -17,20 +17,31 @@ import org.h2.value.ValueNull;
/**
/**
* Data stored while calculating an aggregate that needs collecting of all
* Data stored while calculating an aggregate that needs collecting of all
* values.
* values
or a distinct aggregate
.
*
*
* <p>
* <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
* method returns {@code null}. Use {@link #getArray()} for instances of this
* class instead.
* class instead.
* </p>
* </p>
*/
*/
class
AggregateDataCollecting
extends
AggregateData
implements
Iterable
<
Value
>
{
class
AggregateDataCollecting
extends
AggregateData
implements
Iterable
<
Value
>
{
private
final
boolean
distinct
;
Collection
<
Value
>
values
;
Collection
<
Value
>
values
;
/**
* Creates new instance of data for collecting aggregates.
*
* @param distinct if distinct is used
*/
AggregateDataCollecting
(
boolean
distinct
)
{
this
.
distinct
=
distinct
;
}
@Override
@Override
void
add
(
Database
database
,
int
dataType
,
boolean
distinct
,
Value
v
)
{
void
add
(
Database
database
,
int
dataType
,
Value
v
)
{
if
(
v
==
ValueNull
.
INSTANCE
)
{
if
(
v
==
ValueNull
.
INSTANCE
)
{
return
;
return
;
}
}
...
@@ -42,7 +53,7 @@ class AggregateDataCollecting extends AggregateData implements Iterable<Value> {
...
@@ -42,7 +53,7 @@ class AggregateDataCollecting extends AggregateData implements Iterable<Value> {
}
}
@Override
@Override
Value
getValue
(
Database
database
,
int
dataType
,
boolean
distinct
)
{
Value
getValue
(
Database
database
,
int
dataType
)
{
return
null
;
return
null
;
}
}
...
...
h2/src/main/org/h2/expression/aggregate/AggregateDataCount.java
浏览文件 @
92596a70
...
@@ -17,15 +17,14 @@ class AggregateDataCount extends AggregateData {
...
@@ -17,15 +17,14 @@ class AggregateDataCount extends AggregateData {
private
long
count
;
private
long
count
;
@Override
@Override
void
add
(
Database
database
,
int
dataType
,
boolean
distinct
,
Value
v
)
{
void
add
(
Database
database
,
int
dataType
,
Value
v
)
{
if
(
v
==
ValueNull
.
INSTANCE
)
{
if
(
v
!=
ValueNull
.
INSTANCE
)
{
return
;
}
count
++;
count
++;
}
}
}
@Override
@Override
Value
getValue
(
Database
database
,
int
dataType
,
boolean
distinct
)
{
Value
getValue
(
Database
database
,
int
dataType
)
{
return
ValueLong
.
get
(
count
).
convertTo
(
dataType
);
return
ValueLong
.
get
(
count
).
convertTo
(
dataType
);
}
}
...
...
h2/src/main/org/h2/expression/aggregate/AggregateDataCountAll.java
浏览文件 @
92596a70
...
@@ -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.message.DbException
;
import
org.h2.value.Value
;
import
org.h2.value.Value
;
import
org.h2.value.ValueLong
;
import
org.h2.value.ValueLong
;
...
@@ -14,21 +13,16 @@ import org.h2.value.ValueLong;
...
@@ -14,21 +13,16 @@ import org.h2.value.ValueLong;
* Data stored while calculating a COUNT(*) aggregate.
* Data stored while calculating a COUNT(*) aggregate.
*/
*/
class
AggregateDataCountAll
extends
AggregateData
{
class
AggregateDataCountAll
extends
AggregateData
{
private
long
count
;
private
long
count
;
@Override
@Override
void
add
(
Database
database
,
int
dataType
,
boolean
distinct
,
Value
v
)
{
void
add
(
Database
database
,
int
dataType
,
Value
v
)
{
if
(
distinct
)
{
throw
DbException
.
throwInternalError
();
}
count
++;
count
++;
}
}
@Override
@Override
Value
getValue
(
Database
database
,
int
dataType
,
boolean
distinct
)
{
Value
getValue
(
Database
database
,
int
dataType
)
{
if
(
distinct
)
{
throw
DbException
.
throwInternalError
();
}
return
ValueLong
.
get
(
count
).
convertTo
(
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 {
...
@@ -33,7 +33,7 @@ class AggregateDataDefault extends AggregateData {
}
}
@Override
@Override
void
add
(
Database
database
,
int
dataType
,
boolean
distinct
,
Value
v
)
{
void
add
(
Database
database
,
int
dataType
,
Value
v
)
{
if
(
v
==
ValueNull
.
INSTANCE
)
{
if
(
v
==
ValueNull
.
INSTANCE
)
{
return
;
return
;
}
}
...
@@ -119,7 +119,7 @@ class AggregateDataDefault extends AggregateData {
...
@@ -119,7 +119,7 @@ class AggregateDataDefault extends AggregateData {
}
}
@Override
@Override
Value
getValue
(
Database
database
,
int
dataType
,
boolean
distinct
)
{
Value
getValue
(
Database
database
,
int
dataType
)
{
Value
v
=
null
;
Value
v
=
null
;
switch
(
aggregateType
)
{
switch
(
aggregateType
)
{
case
SUM:
case
SUM:
...
...
h2/src/main/org/h2/expression/aggregate/AggregateDataEnvelope.java
浏览文件 @
92596a70
...
@@ -57,7 +57,7 @@ class AggregateDataEnvelope extends AggregateData {
...
@@ -57,7 +57,7 @@ class AggregateDataEnvelope extends AggregateData {
}
}
@Override
@Override
void
add
(
Database
database
,
int
dataType
,
boolean
distinct
,
Value
v
)
{
void
add
(
Database
database
,
int
dataType
,
Value
v
)
{
if
(
v
==
ValueNull
.
INSTANCE
)
{
if
(
v
==
ValueNull
.
INSTANCE
)
{
return
;
return
;
}
}
...
@@ -65,7 +65,7 @@ class AggregateDataEnvelope extends AggregateData {
...
@@ -65,7 +65,7 @@ class AggregateDataEnvelope extends AggregateData {
}
}
@Override
@Override
Value
getValue
(
Database
database
,
int
dataType
,
boolean
distinct
)
{
Value
getValue
(
Database
database
,
int
dataType
)
{
return
ValueGeometry
.
fromEnvelope
(
envelope
);
return
ValueGeometry
.
fromEnvelope
(
envelope
);
}
}
...
...
h2/src/main/org/h2/expression/aggregate/AggregateDataHistogram.java
浏览文件 @
92596a70
...
@@ -22,10 +22,21 @@ import org.h2.value.ValueLong;
...
@@ -22,10 +22,21 @@ import org.h2.value.ValueLong;
*/
*/
class
AggregateDataHistogram
extends
AggregateData
{
class
AggregateDataHistogram
extends
AggregateData
{
private
final
boolean
distinct
;
private
ValueHashMap
<
LongDataCounter
>
distinctValues
;
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
@Override
void
add
(
Database
database
,
int
dataType
,
boolean
distinct
,
Value
v
)
{
void
add
(
Database
database
,
int
dataType
,
Value
v
)
{
if
(
distinctValues
==
null
)
{
if
(
distinctValues
==
null
)
{
distinctValues
=
ValueHashMap
.
newInstance
();
distinctValues
=
ValueHashMap
.
newInstance
();
}
}
...
@@ -41,7 +52,7 @@ class AggregateDataHistogram extends AggregateData {
...
@@ -41,7 +52,7 @@ class AggregateDataHistogram extends AggregateData {
}
}
@Override
@Override
Value
getValue
(
Database
database
,
int
dataType
,
boolean
distinct
)
{
Value
getValue
(
Database
database
,
int
dataType
)
{
if
(
distinctValues
==
null
)
{
if
(
distinctValues
==
null
)
{
return
ValueArray
.
get
(
new
Value
[
0
]).
convertTo
(
dataType
);
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 {
...
@@ -20,7 +20,7 @@ class AggregateDataMode extends AggregateData {
private
ValueHashMap
<
LongDataCounter
>
distinctValues
;
private
ValueHashMap
<
LongDataCounter
>
distinctValues
;
@Override
@Override
void
add
(
Database
database
,
int
dataType
,
boolean
distinct
,
Value
v
)
{
void
add
(
Database
database
,
int
dataType
,
Value
v
)
{
if
(
v
==
ValueNull
.
INSTANCE
)
{
if
(
v
==
ValueNull
.
INSTANCE
)
{
return
;
return
;
}
}
...
@@ -36,7 +36,7 @@ class AggregateDataMode extends AggregateData {
...
@@ -36,7 +36,7 @@ class AggregateDataMode extends AggregateData {
}
}
@Override
@Override
Value
getValue
(
Database
database
,
int
dataType
,
boolean
distinct
)
{
Value
getValue
(
Database
database
,
int
dataType
)
{
Value
v
=
ValueNull
.
INSTANCE
;
Value
v
=
ValueNull
.
INSTANCE
;
if
(
distinctValues
!=
null
)
{
if
(
distinctValues
!=
null
)
{
long
count
=
0L
;
long
count
=
0L
;
...
...
h2/src/main/org/h2/expression/aggregate/AggregateDataSelectivity.java
浏览文件 @
92596a70
...
@@ -15,12 +15,24 @@ import org.h2.value.ValueInt;
...
@@ -15,12 +15,24 @@ import org.h2.value.ValueInt;
* Data stored while calculating a SELECTIVITY aggregate.
* Data stored while calculating a SELECTIVITY aggregate.
*/
*/
class
AggregateDataSelectivity
extends
AggregateData
{
class
AggregateDataSelectivity
extends
AggregateData
{
private
final
boolean
distinct
;
private
long
count
;
private
long
count
;
private
IntIntHashMap
distinctHashes
;
private
IntIntHashMap
distinctHashes
;
private
double
m2
;
private
double
m2
;
/**
* Creates new instance of data for SELECTIVITY aggregate.
*
* @param distinct if distinct is used
*/
AggregateDataSelectivity
(
boolean
distinct
)
{
this
.
distinct
=
distinct
;
}
@Override
@Override
void
add
(
Database
database
,
int
dataType
,
boolean
distinct
,
Value
v
)
{
void
add
(
Database
database
,
int
dataType
,
Value
v
)
{
count
++;
count
++;
if
(
distinctHashes
==
null
)
{
if
(
distinctHashes
==
null
)
{
distinctHashes
=
new
IntIntHashMap
();
distinctHashes
=
new
IntIntHashMap
();
...
@@ -36,7 +48,7 @@ class AggregateDataSelectivity extends AggregateData {
...
@@ -36,7 +48,7 @@ class AggregateDataSelectivity extends AggregateData {
}
}
@Override
@Override
Value
getValue
(
Database
database
,
int
dataType
,
boolean
distinct
)
{
Value
getValue
(
Database
database
,
int
dataType
)
{
if
(
distinct
)
{
if
(
distinct
)
{
count
=
0
;
count
=
0
;
}
}
...
@@ -53,4 +65,5 @@ class AggregateDataSelectivity extends AggregateData {
...
@@ -53,4 +65,5 @@ class AggregateDataSelectivity extends AggregateData {
v
=
ValueInt
.
get
(
s
);
v
=
ValueInt
.
get
(
s
);
return
v
.
convertTo
(
dataType
);
return
v
.
convertTo
(
dataType
);
}
}
}
}
h2/src/main/org/h2/expression/aggregate/JavaAggregate.java
浏览文件 @
92596a70
...
@@ -209,7 +209,7 @@ public class JavaAggregate extends AbstractAggregate {
...
@@ -209,7 +209,7 @@ public class JavaAggregate extends AbstractAggregate {
arg
=
arg
.
convertTo
(
argTypes
[
i
]);
arg
=
arg
.
convertTo
(
argTypes
[
i
]);
argValues
[
i
]
=
arg
;
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
{
}
else
{
Aggregate
agg
=
(
Aggregate
)
aggregateData
;
Aggregate
agg
=
(
Aggregate
)
aggregateData
;
Object
[]
argValues
=
new
Object
[
args
.
length
];
Object
[]
argValues
=
new
Object
[
args
.
length
];
...
@@ -254,7 +254,7 @@ public class JavaAggregate extends AbstractAggregate {
...
@@ -254,7 +254,7 @@ public class JavaAggregate extends AbstractAggregate {
@Override
@Override
protected
Object
createAggregateData
()
{
protected
Object
createAggregateData
()
{
return
distinct
?
new
AggregateDataCollecting
()
:
getInstance
();
return
distinct
?
new
AggregateDataCollecting
(
true
)
:
getInstance
();
}
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论