Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2dot5
ClickHouse
提交
1b4b0d57
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,发现更多精彩内容 >>
提交
1b4b0d57
编写于
1月 26, 2015
作者:
A
Andrey Mironov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
dbms: MysqlDictionarySource with draft MysqlBockInputStream
上级
419d5178
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
140 addition
and
33 deletion
+140
-33
dbms/include/DB/Dictionaries/DictionaryFactory.h
dbms/include/DB/Dictionaries/DictionaryFactory.h
+2
-2
dbms/include/DB/Dictionaries/DictionarySourceFactory.h
dbms/include/DB/Dictionaries/DictionarySourceFactory.h
+4
-8
dbms/include/DB/Dictionaries/DictionaryStructure.h
dbms/include/DB/Dictionaries/DictionaryStructure.h
+2
-2
dbms/include/DB/Dictionaries/FileDictionarySource.h
dbms/include/DB/Dictionaries/FileDictionarySource.h
+2
-2
dbms/include/DB/Dictionaries/FlatDictionary.h
dbms/include/DB/Dictionaries/FlatDictionary.h
+2
-2
dbms/include/DB/Dictionaries/MysqlDictionarySource.h
dbms/include/DB/Dictionaries/MysqlDictionarySource.h
+112
-0
dbms/include/DB/Dictionaries/config_ptr_t.h
dbms/include/DB/Dictionaries/config_ptr_t.h
+15
-0
dbms/include/DB/Interpreters/Dictionaries.h
dbms/include/DB/Interpreters/Dictionaries.h
+0
-7
dbms/src/Interpreters/Dictionaries.cpp
dbms/src/Interpreters/Dictionaries.cpp
+1
-10
未找到文件。
dbms/include/DB/Dictionaries/DictionaryFactory.h
浏览文件 @
1b4b0d57
...
...
@@ -13,10 +13,10 @@ namespace DB
class
DictionaryFactory
:
public
Singleton
<
DictionaryFactory
>
{
public:
DictionaryPtr
create
(
const
Poco
::
Util
::
XML
Configuration
&
config
,
const
std
::
string
&
config_prefix
,
DictionaryPtr
create
(
Poco
::
Util
::
Abstract
Configuration
&
config
,
const
std
::
string
&
config_prefix
,
const
Context
&
context
)
const
{
auto
dict_struct
=
DictionaryStructure
::
from
XML
(
config
,
config_prefix
+
"structure"
);
auto
dict_struct
=
DictionaryStructure
::
from
Config
(
config
,
config_prefix
+
"structure"
);
auto
source_ptr
=
DictionarySourceFactory
::
instance
().
create
(
config
,
config_prefix
+
"source."
,
dict_struct
,
context
);
...
...
dbms/include/DB/Dictionaries/DictionarySourceFactory.h
浏览文件 @
1b4b0d57
...
...
@@ -3,6 +3,7 @@
#include <DB/Core/Block.h>
#include <DB/Dictionaries/DictionaryStructure.h>
#include <DB/Dictionaries/FileDictionarySource.h>
#include <DB/Dictionaries/MysqlDictionarySource.h>
#include <DB/DataTypes/DataTypesNumberFixed.h>
#include <Yandex/singleton.h>
#include <statdaemons/ext/memory.hpp>
...
...
@@ -39,7 +40,7 @@ Block createSampleBlock(const DictionaryStructure & dict_struct, const Context &
class
DictionarySourceFactory
:
public
Singleton
<
DictionarySourceFactory
>
{
public:
DictionarySourcePtr
create
(
const
Poco
::
Util
::
AbstractConfiguration
&
config
,
DictionarySourcePtr
create
(
Poco
::
Util
::
AbstractConfiguration
&
config
,
const
std
::
string
&
config_prefix
,
const
DictionaryStructure
&
dict_struct
,
const
Context
&
context
)
const
...
...
@@ -54,15 +55,10 @@ public:
}
else
if
(
config
.
has
(
config_prefix
+
"mysql"
))
{
throw
Exception
{
"source.mysql not yet implemented"
,
ErrorCodes
::
NOT_IMPLEMENTED
};
return
ext
::
make_unique
<
MysqlDictionarySource
>
(
config
,
config_prefix
+
"mysql."
,
sample_block
,
context
);
}
throw
Exception
{
"unsupported source type"
};
throw
Exception
{
"unsupported source type"
};
}
};
...
...
dbms/include/DB/Dictionaries/DictionaryStructure.h
浏览文件 @
1b4b0d57
#pragma once
#include <DB/Core/ErrorCodes.h>
#include <Poco/Util/
XML
Configuration.h>
#include <Poco/Util/
Abstract
Configuration.h>
#include <vector>
#include <string>
...
...
@@ -22,7 +22,7 @@ struct DictionaryStructure
std
::
string
id_name
;
std
::
vector
<
DictionaryAttribute
>
attributes
;
static
DictionaryStructure
from
XML
(
const
Poco
::
Util
::
XML
Configuration
&
config
,
const
std
::
string
&
config_prefix
)
static
DictionaryStructure
from
Config
(
const
Poco
::
Util
::
Abstract
Configuration
&
config
,
const
std
::
string
&
config_prefix
)
{
const
auto
&
id_name
=
config
.
getString
(
config_prefix
+
".id.name"
);
if
(
id_name
.
empty
())
...
...
dbms/include/DB/Dictionaries/FileDictionarySource.h
浏览文件 @
1b4b0d57
...
...
@@ -7,10 +7,10 @@
namespace
DB
{
const
auto
max_block_size
=
8192
;
class
FileDictionarySource
final
:
public
IDictionarySource
{
static
const
auto
max_block_size
=
8192
;
public:
FileDictionarySource
(
const
std
::
string
&
filename
,
const
std
::
string
&
format
,
Block
&
sample_block
,
const
Context
&
context
)
...
...
dbms/include/DB/Dictionaries/FlatDictionary.h
浏览文件 @
1b4b0d57
...
...
@@ -3,7 +3,7 @@
#include <DB/Dictionaries/IDictionarySource.h>
#include <DB/Dictionaries/IDictionary.h>
#include <statdaemons/ext/range.hpp>
#include <Poco/Util/
XML
Configuration.h>
#include <Poco/Util/
Abstract
Configuration.h>
#include <map>
#include <vector>
...
...
@@ -17,7 +17,7 @@ const auto max_array_size = 500000;
class
FlatDictionary
final
:
public
IDictionary
{
public:
FlatDictionary
(
const
DictionaryStructure
&
dict_struct
,
const
Poco
::
Util
::
XML
Configuration
&
config
,
FlatDictionary
(
const
DictionaryStructure
&
dict_struct
,
const
Poco
::
Util
::
Abstract
Configuration
&
config
,
const
std
::
string
&
config_prefix
,
DictionarySourcePtr
source_ptr
)
:
source_ptr
{
std
::
move
(
source_ptr
)}
{
...
...
dbms/include/DB/Dictionaries/MysqlDictionarySource.h
0 → 100644
浏览文件 @
1b4b0d57
#pragma once
#include <DB/Interpreters/Context.h>
#include <DB/Dictionaries/DictionaryStructure.h>
#include <DB/Dictionaries/IDictionarySource.h>
#include <DB/Dictionaries/config_ptr_t.h>
#include <DB/DataStreams/IProfilingBlockInputStream.h>
#include <statdaemons/ext/range.hpp>
#include <mysqlxx/Pool.h>
#include <Poco/Util/AbstractConfiguration.h>
#include <Poco/Util/LayeredConfiguration.h>
namespace
DB
{
class
MysqlBlockInputStream
final
:
public
IProfilingBlockInputStream
{
public:
MysqlBlockInputStream
(
mysqlxx
::
Query
query
,
const
Block
&
sample_block
,
const
std
::
size_t
max_block_size
)
:
query
{
std
::
move
(
query
)},
result
{
query
.
use
()},
sample_block
{
sample_block
},
max_block_size
{
max_block_size
}
{
}
String
getName
()
const
override
{
return
"MysqlBlockInputStream"
;
}
String
getID
()
const
override
{
return
"Mysql("
+
query
.
str
()
+
")"
;
}
private:
Block
readImpl
()
override
{
auto
block
=
sample_block
.
cloneEmpty
();
std
::
size_t
rows
=
0
;
while
(
auto
row
=
result
.
fetch
())
{
for
(
const
auto
idx
:
ext
::
range
(
0
,
row
.
size
()))
/// @todo type switch to get the real value from row[idx]
block
.
getByPosition
(
idx
).
column
->
insert
(
Field
{});
++
rows
;
if
(
rows
==
max_block_size
)
break
;
}
return
block
;
}
mysqlxx
::
Query
query
;
mysqlxx
::
UseQueryResult
result
;
Block
sample_block
;
std
::
size_t
max_block_size
;
};
class
MysqlDictionarySource
final
:
public
IDictionarySource
{
static
const
auto
max_block_size
=
8192
;
public:
MysqlDictionarySource
(
Poco
::
Util
::
AbstractConfiguration
&
config
,
const
std
::
string
&
config_prefix
,
Block
&
sample_block
,
const
Context
&
context
)
:
layered_config_ptr
{
getLayeredConfig
(
config
)},
pool
{
*
layered_config_ptr
,
config_prefix
},
sample_block
{
sample_block
},
context
(
context
)
{}
private:
BlockInputStreamPtr
loadAll
()
override
{
auto
connection
=
pool
.
Get
();
auto
query
=
connection
->
query
(
"SELECT 1+1;"
);
auto
result
=
query
.
use
();
while
(
auto
row
=
result
.
fetch
())
{
for
(
const
auto
idx
:
ext
::
range
(
0
,
row
.
size
()))
std
::
cout
<<
row
[
idx
].
getString
()
<<
' '
;
std
::
cout
<<
std
::
endl
;
}
return
new
MysqlBlockInputStream
{
pool
.
Get
()
->
query
(
""
),
sample_block
,
max_block_size
};
}
BlockInputStreamPtr
loadId
(
const
std
::
uint64_t
id
)
override
{
throw
Exception
{
"Method unsupported"
,
ErrorCodes
::
NOT_IMPLEMENTED
};
}
BlockInputStreamPtr
loadIds
(
const
std
::
vector
<
std
::
uint64_t
>
ids
)
override
{
throw
Exception
{
"Method unsupported"
,
ErrorCodes
::
NOT_IMPLEMENTED
};
}
static
config_ptr_t
<
Poco
::
Util
::
LayeredConfiguration
>
getLayeredConfig
(
Poco
::
Util
::
AbstractConfiguration
&
config
)
{
config_ptr_t
<
Poco
::
Util
::
LayeredConfiguration
>
layered_config
{
new
Poco
::
Util
::
LayeredConfiguration
};
layered_config
->
add
(
&
config
);
return
layered_config
;
}
const
config_ptr_t
<
Poco
::
Util
::
LayeredConfiguration
>
layered_config_ptr
;
mysqlxx
::
Pool
pool
;
Block
sample_block
;
const
Context
&
context
;
};
}
dbms/include/DB/Dictionaries/config_ptr_t.h
0 → 100644
浏览文件 @
1b4b0d57
#pragma once
#include <memory>
namespace
DB
{
template
<
typename
T
>
struct
release
{
void
operator
()(
const
T
*
const
ptr
)
{
ptr
->
release
();
}
};
template
<
typename
T
>
using
config_ptr_t
=
std
::
unique_ptr
<
T
,
release
<
T
>>
;
}
dbms/include/DB/Interpreters/Dictionaries.h
浏览文件 @
1b4b0d57
...
...
@@ -200,13 +200,6 @@ public:
MultiVersion
<
IDictionary
>::
Version
getExternalDictionary
(
const
std
::
string
&
name
)
const
{
std
::
cout
<<
"there are dictionaries: "
;
std
::
transform
(
std
::
begin
(
external_dictionaries
),
std
::
end
(
external_dictionaries
),
std
::
ostream_iterator
<
std
::
string
>
{
std
::
cout
,
", "
},
[]
(
const
std
::
pair
<
const
std
::
string
,
std
::
shared_ptr
<
MultiVersion
<
IDictionary
>>>
&
pair
)
{
return
pair
.
first
;
});
std
::
cout
<<
std
::
endl
;
const
auto
it
=
external_dictionaries
.
find
(
name
);
if
(
it
==
std
::
end
(
external_dictionaries
))
throw
Exception
{
...
...
dbms/src/Interpreters/Dictionaries.cpp
浏览文件 @
1b4b0d57
#include <DB/Interpreters/Dictionaries.h>
#include <DB/Dictionaries/DictionaryFactory.h>
#include <
Poco/Util/XMLConfiguration
.h>
#include <
DB/Dictionaries/config_ptr_t
.h>
namespace
DB
{
namespace
{
template
<
typename
T
>
struct
release
{
void
operator
()(
const
T
*
const
ptr
)
{
ptr
->
release
();
}
};
template
<
typename
T
>
using
config_ptr_t
=
std
::
unique_ptr
<
T
,
release
<
T
>>
;
};
void
Dictionaries
::
reloadExternals
()
{
const
std
::
lock_guard
<
std
::
mutex
>
lock
{
externals_mutex
};
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录