Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
674102df
提交
674102df
authored
1月 19, 2019
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Do not use hash-based collections in aggregates
上级
6ae17fc2
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
36 行增加
和
12 行删除
+36
-12
Aggregate.java
h2/src/main/org/h2/expression/aggregate/Aggregate.java
+6
-6
AggregateDataCollecting.java
.../org/h2/expression/aggregate/AggregateDataCollecting.java
+2
-2
AggregateDataDistinctWithCounts.java
...expression/aggregate/AggregateDataDistinctWithCounts.java
+4
-4
count.sql
...rc/test/org/h2/test/scripts/functions/aggregate/count.sql
+15
-0
mode.sql
h2/src/test/org/h2/test/scripts/functions/aggregate/mode.sql
+9
-0
没有找到文件。
h2/src/main/org/h2/expression/aggregate/Aggregate.java
浏览文件 @
674102df
...
...
@@ -10,6 +10,7 @@ import java.util.Arrays;
import
java.util.Comparator
;
import
java.util.HashMap
;
import
java.util.Map.Entry
;
import
java.util.TreeMap
;
import
org.h2.api.ErrorCode
;
import
org.h2.command.dml.Select
;
import
org.h2.command.dml.SelectOrderBy
;
...
...
@@ -32,7 +33,6 @@ import org.h2.table.ColumnResolver;
import
org.h2.table.Table
;
import
org.h2.table.TableFilter
;
import
org.h2.util.StatementBuilder
;
import
org.h2.util.ValueHashMap
;
import
org.h2.value.CompareMode
;
import
org.h2.value.DataType
;
import
org.h2.value.TypeInfo
;
...
...
@@ -512,13 +512,13 @@ public class Aggregate extends AbstractAggregate {
}
private
Value
getHistogram
(
Session
session
,
AggregateData
data
)
{
ValueHashMap
<
LongDataCounter
>
distinctValues
=
((
AggregateDataDistinctWithCounts
)
data
).
getValues
();
TreeMap
<
Value
,
LongDataCounter
>
distinctValues
=
((
AggregateDataDistinctWithCounts
)
data
).
getValues
();
if
(
distinctValues
==
null
)
{
return
ValueArray
.
getEmpty
();
}
ValueArray
[]
values
=
new
ValueArray
[
distinctValues
.
size
()];
int
i
=
0
;
for
(
Entry
<
Value
,
LongDataCounter
>
entry
:
distinctValues
.
entr
ies
())
{
for
(
Entry
<
Value
,
LongDataCounter
>
entry
:
distinctValues
.
entr
ySet
())
{
LongDataCounter
d
=
entry
.
getValue
();
values
[
i
]
=
ValueArray
.
get
(
new
Value
[]
{
entry
.
getKey
(),
ValueLong
.
get
(
distinct
?
1L
:
d
.
count
)
});
i
++;
...
...
@@ -539,14 +539,14 @@ public class Aggregate extends AbstractAggregate {
private
Value
getMode
(
Session
session
,
AggregateData
data
)
{
Value
v
=
ValueNull
.
INSTANCE
;
ValueHashMap
<
LongDataCounter
>
distinctValues
=
((
AggregateDataDistinctWithCounts
)
data
).
getValues
();
TreeMap
<
Value
,
LongDataCounter
>
distinctValues
=
((
AggregateDataDistinctWithCounts
)
data
).
getValues
();
if
(
distinctValues
==
null
)
{
return
v
;
}
long
count
=
0L
;
if
(
orderByList
!=
null
)
{
boolean
desc
=
(
orderByList
.
get
(
0
).
sortType
&
SortOrder
.
DESCENDING
)
!=
0
;
for
(
Entry
<
Value
,
LongDataCounter
>
entry
:
distinctValues
.
entr
ies
())
{
for
(
Entry
<
Value
,
LongDataCounter
>
entry
:
distinctValues
.
entr
ySet
())
{
long
c
=
entry
.
getValue
().
count
;
if
(
c
>
count
)
{
v
=
entry
.
getKey
();
...
...
@@ -565,7 +565,7 @@ public class Aggregate extends AbstractAggregate {
}
}
}
else
{
for
(
Entry
<
Value
,
LongDataCounter
>
entry
:
distinctValues
.
entr
ies
())
{
for
(
Entry
<
Value
,
LongDataCounter
>
entry
:
distinctValues
.
entr
ySet
())
{
long
c
=
entry
.
getValue
().
count
;
if
(
c
>
count
)
{
v
=
entry
.
getKey
();
...
...
h2/src/main/org/h2/expression/aggregate/AggregateDataCollecting.java
浏览文件 @
674102df
...
...
@@ -8,8 +8,8 @@ package org.h2.expression.aggregate;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.HashSet
;
import
java.util.Iterator
;
import
java.util.TreeSet
;
import
org.h2.engine.Database
;
import
org.h2.value.Value
;
...
...
@@ -47,7 +47,7 @@ class AggregateDataCollecting extends AggregateData implements Iterable<Value> {
}
Collection
<
Value
>
c
=
values
;
if
(
c
==
null
)
{
values
=
c
=
distinct
?
new
HashSet
<
Value
>(
)
:
new
ArrayList
<
Value
>();
values
=
c
=
distinct
?
new
TreeSet
<>(
database
.
getCompareMode
()
)
:
new
ArrayList
<
Value
>();
}
c
.
add
(
v
);
}
...
...
h2/src/main/org/h2/expression/aggregate/AggregateDataDistinctWithCounts.java
浏览文件 @
674102df
...
...
@@ -5,8 +5,8 @@
*/
package
org
.
h2
.
expression
.
aggregate
;
import
java.util.TreeMap
;
import
org.h2.engine.Database
;
import
org.h2.util.ValueHashMap
;
import
org.h2.value.Value
;
import
org.h2.value.ValueNull
;
...
...
@@ -20,7 +20,7 @@ class AggregateDataDistinctWithCounts extends AggregateData {
private
final
int
maxDistinctCount
;
private
ValueHashMap
<
LongDataCounter
>
values
;
private
TreeMap
<
Value
,
LongDataCounter
>
values
;
/**
* Creates new instance of data for aggregate that needs distinct values
...
...
@@ -42,7 +42,7 @@ class AggregateDataDistinctWithCounts extends AggregateData {
return
;
}
if
(
values
==
null
)
{
values
=
new
ValueHashMap
<>(
);
values
=
new
TreeMap
<>(
database
.
getCompareMode
()
);
}
LongDataCounter
a
=
values
.
get
(
v
);
if
(
a
==
null
)
{
...
...
@@ -65,7 +65,7 @@ class AggregateDataDistinctWithCounts extends AggregateData {
*
* @return map with values and their counts
*/
ValueHashMap
<
LongDataCounter
>
getValues
()
{
TreeMap
<
Value
,
LongDataCounter
>
getValues
()
{
return
values
;
}
...
...
h2/src/test/org/h2/test/scripts/functions/aggregate/count.sql
浏览文件 @
674102df
...
...
@@ -104,3 +104,18 @@ SELECT X, COUNT(*) OVER (ORDER BY X) C FROM VALUES (1), (1), (2), (2), (3) V(X);
>
2
4
>
3
5
>
rows
:
5
CREATE
TABLE
TEST
(
N
NUMERIC
)
AS
VALUES
(
0
),
(
0
.
0
),
(
NULL
);
>
ok
SELECT
COUNT
(
*
)
FROM
TEST
;
>>
3
SELECT
COUNT
(
N
)
FROM
TEST
;
>>
2
SELECT
COUNT
(
DISTINCT
N
)
FROM
TEST
;
>>
1
DROP
TABLE
TEST
;
>
ok
h2/src/test/org/h2/test/scripts/functions/aggregate/mode.sql
浏览文件 @
674102df
...
...
@@ -57,3 +57,12 @@ SELECT MODE() WITHIN GROUP(ORDER BY V DESC) FROM TEST;
DROP
TABLE
TEST
;
>
ok
CREATE
TABLE
TEST
(
N
NUMERIC
)
AS
VALUES
(
0
),
(
0
.
0
),
(
NULL
);
>
ok
SELECT
MODE
(
N
)
FROM
TEST
;
>>
0
DROP
TABLE
TEST
;
>
ok
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论