Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2dot5
ClickHouse
提交
93143369
C
ClickHouse
项目概览
2dot5
/
ClickHouse
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
ClickHouse
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
93143369
编写于
12月 13, 2012
作者:
M
Michael Kolupaev
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
clickhouse: added support for non-UInt32 sampling columns [#6201].
上级
17612f45
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
38 addition
and
35 deletion
+38
-35
dbms/src/Storages/StorageMergeTree.cpp
dbms/src/Storages/StorageMergeTree.cpp
+38
-35
未找到文件。
dbms/src/Storages/StorageMergeTree.cpp
浏览文件 @
93143369
...
...
@@ -825,9 +825,7 @@ BlockInputStreams StorageMergeTree::read(
/// Семплирование.
Names
column_names_to_read
=
column_names_to_return
;
size_t
count_limit
=
std
::
numeric_limits
<
size_t
>::
max
();
bool
sample_by_value
=
false
;
UInt64
sample_column_value_limit
=
0
;
UInt64
sampling_column_value_limit
=
0
;
typedef
Poco
::
SharedPtr
<
ASTFunction
>
ASTFunctionPtr
;
ASTFunctionPtr
filter_function
;
ExpressionPtr
filter_expression
;
...
...
@@ -835,30 +833,50 @@ BlockInputStreams StorageMergeTree::read(
ASTSelectQuery
&
select
=
*
dynamic_cast
<
ASTSelectQuery
*>
(
&*
query
);
if
(
select
.
sample_size
)
{
double
size
=
boost
::
apply_visitor
(
FieldVisitorConvertToNumber
<
double
>
(),
dynamic_cast
<
ASTLiteral
*>
(
&*
select
.
sample_size
)
->
value
);
double
size
=
boost
::
apply_visitor
(
FieldVisitorConvertToNumber
<
double
>
(),
dynamic_cast
<
ASTLiteral
&>
(
*
select
.
sample_size
).
value
);
if
(
size
<
0
)
throw
Exception
(
"Negative sample size"
,
ErrorCodes
::
ARGUMENT_OUT_OF_BOUND
);
if
(
size
>
1
)
{
count_limit
=
boost
::
apply_visitor
(
FieldVisitorConvertToNumber
<
UInt64
>
(),
dynamic_cast
<
ASTLiteral
*>
(
&*
select
.
sample_size
)
->
value
);
}
else
size_t
requested_count
=
boost
::
apply_visitor
(
FieldVisitorConvertToNumber
<
UInt64
>
(),
dynamic_cast
<
ASTLiteral
&>
(
*
select
.
sample_size
).
value
);
/// Узнаем количество строк в таблице.
size_t
total_count
=
0
;
{
sample_by_value
=
true
;
sample_column_value_limit
=
static_cast
<
UInt64
>
(
size
*
std
::
numeric_limits
<
UInt32
>::
max
());
if
(
!
key_condition
.
addCondition
(
sampling_expression
->
getColumnName
(),
Range
::
RightBounded
(
sample_column_value_limit
,
true
)))
throw
Exception
(
"Invalid sampling column in storage parameters"
,
ErrorCodes
::
ILLEGAL_COLUMN
);
Poco
::
ScopedLock
<
Poco
::
FastMutex
>
lock
(
data_parts_mutex
);
for
(
DataParts
::
iterator
it
=
data_parts
.
begin
();
it
!=
data_parts
.
end
();
++
it
)
total_count
+=
(
*
it
)
->
size
;
}
total_count
*=
index_granularity
;
size
=
std
::
min
(
1.
,
static_cast
<
double
>
(
requested_count
)
/
total_count
);
}
if
(
sample_by_value
)
{
/// Выражение для фильтрации: sampling_column_name <= sample_column_value_limit
UInt64
sampling_column_max
=
0
;
DataTypePtr
type
=
Expression
(
sampling_expression
,
context
).
getReturnTypes
()[
0
];
if
(
type
->
getName
()
==
"UInt64"
)
sampling_column_max
=
std
::
numeric_limits
<
UInt64
>::
max
();
else
if
(
type
->
getName
()
==
"UInt32"
)
sampling_column_max
=
std
::
numeric_limits
<
UInt32
>::
max
();
else
if
(
type
->
getName
()
==
"UInt16"
)
sampling_column_max
=
std
::
numeric_limits
<
UInt16
>::
max
();
else
if
(
type
->
getName
()
==
"UInt8"
)
sampling_column_max
=
std
::
numeric_limits
<
UInt8
>::
max
();
else
throw
Exception
(
"Invalid sampling column type in storage parameters: "
+
type
->
getName
()
+
". Must be unsigned integer type."
,
ErrorCodes
::
ILLEGAL_TYPE_OF_COLUMN_FOR_FILTER
);
sampling_column_value_limit
=
static_cast
<
UInt64
>
(
size
*
sampling_column_max
);
if
(
!
key_condition
.
addCondition
(
sampling_expression
->
getColumnName
(),
Range
::
RightBounded
(
sampling_column_value_limit
,
true
)))
throw
Exception
(
"Sampling column not in primary key"
,
ErrorCodes
::
ILLEGAL_COLUMN
);
/// Выражение для фильтрации: sampling_expression <= sampling_column_value_limit
ASTPtr
filter_function_args
=
new
ASTExpressionList
;
filter_function_args
->
children
.
push_back
(
sampling_expression
);
filter_function_args
->
children
.
push_back
(
new
ASTLiteral
(
StringRange
(),
sampl
e
_column_value_limit
));
filter_function_args
->
children
.
push_back
(
new
ASTLiteral
(
StringRange
(),
sampl
ing
_column_value_limit
));
filter_function
=
new
ASTFunction
;
filter_function
->
name
=
"lessOrEquals"
;
...
...
@@ -891,7 +909,6 @@ BlockInputStreams StorageMergeTree::read(
RangesInDataParts
parts_with_ranges
;
/// Найдем, какой диапазон читать из каждого куска.
size_t
mark_count_limit
=
(
count_limit
-
1
)
/
index_granularity
+
1
;
size_t
sum_marks
=
0
;
size_t
sum_ranges
=
0
;
for
(
size_t
i
=
0
;
i
<
parts
.
size
();
++
i
)
...
...
@@ -910,22 +927,8 @@ BlockInputStreams StorageMergeTree::read(
for
(
size_t
j
=
0
;
j
<
ranges
.
ranges
.
size
();
++
j
)
{
sum_marks
+=
ranges
.
ranges
[
j
].
end
-
ranges
.
ranges
[
j
].
begin
;
/// Если нашли достаточно строк.
if
(
sum_marks
>=
mark_count_limit
)
{
MarkRanges
&
new_ranges
=
parts_with_ranges
.
back
().
ranges
;
/// Обрежем этот отрезок.
new_ranges
[
j
].
end
-=
mark_count_limit
-
sum_marks
;
/// Удалим вссе последующие отрезки.
new_ranges
.
erase
(
new_ranges
.
begin
()
+
j
+
1
,
new_ranges
.
end
());
}
}
/// Если нашли достаточно строк, дальше можено не смотреть.
if
(
sum_marks
*
index_granularity
>=
count_limit
)
break
;
}
}
LOG_DEBUG
(
log
,
"Selected "
<<
parts
.
size
()
<<
" parts by date, "
<<
parts_with_ranges
.
size
()
<<
" parts by key, "
...
...
@@ -933,7 +936,7 @@ BlockInputStreams StorageMergeTree::read(
BlockInputStreams
res
=
spreadMarkRangesAmongThreads
(
parts_with_ranges
,
threads
,
column_names_to_read
,
max_block_size
);
if
(
s
ample_by_valu
e
)
if
(
s
elect
.
sample_siz
e
)
{
for
(
size_t
i
=
0
;
i
<
res
.
size
();
++
i
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录