2015-01-29 11:51:52 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <DB/Dictionaries/IDictionarySource.h>
|
2015-11-18 21:35:24 +00:00
|
|
|
#include <DB/Dictionaries/DictionaryStructure.h>
|
2016-04-10 04:00:00 +00:00
|
|
|
#include <DB/Dictionaries/ExternalQueryBuilder.h>
|
2015-01-29 11:51:52 +00:00
|
|
|
#include <DB/Client/ConnectionPool.h>
|
2015-01-30 13:43:16 +00:00
|
|
|
#include <Poco/Util/AbstractConfiguration.h>
|
2016-10-04 14:42:41 +00:00
|
|
|
#include <memory>
|
2015-09-07 17:22:54 +00:00
|
|
|
|
2015-01-29 11:51:52 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2015-02-10 14:50:43 +00:00
|
|
|
/** Allows loading dictionaries from local or remote ClickHouse instance
|
2016-12-08 02:49:04 +00:00
|
|
|
* @todo use ConnectionPoolWithFailover
|
|
|
|
* @todo invent a way to keep track of source modifications
|
|
|
|
*/
|
2015-02-10 14:50:43 +00:00
|
|
|
class ClickHouseDictionarySource final : public IDictionarySource
|
2015-01-29 11:51:52 +00:00
|
|
|
{
|
|
|
|
public:
|
2016-04-10 04:00:00 +00:00
|
|
|
ClickHouseDictionarySource(const DictionaryStructure & dict_struct_,
|
2015-05-26 15:09:53 +00:00
|
|
|
const Poco::Util::AbstractConfiguration & config,
|
2015-02-05 18:48:29 +00:00
|
|
|
const std::string & config_prefix,
|
2016-12-08 02:49:04 +00:00
|
|
|
const Block & sample_block, Context & context);
|
2015-01-29 11:51:52 +00:00
|
|
|
|
2015-02-10 14:50:43 +00:00
|
|
|
/// copy-constructor is provided in order to support cloneability
|
2016-12-08 02:49:04 +00:00
|
|
|
ClickHouseDictionarySource(const ClickHouseDictionarySource & other);
|
2015-01-30 13:43:16 +00:00
|
|
|
|
2016-12-08 02:49:04 +00:00
|
|
|
BlockInputStreamPtr loadAll() override;
|
2015-01-29 11:51:52 +00:00
|
|
|
|
2016-12-08 02:49:04 +00:00
|
|
|
BlockInputStreamPtr loadIds(const std::vector<UInt64> & ids) override;
|
2015-02-19 14:51:39 +00:00
|
|
|
|
2015-11-16 17:27:12 +00:00
|
|
|
BlockInputStreamPtr loadKeys(
|
2016-12-08 02:49:04 +00:00
|
|
|
const ConstColumnPlainPtrs & key_columns, const std::vector<size_t> & requested_rows) override;
|
2015-01-29 11:51:52 +00:00
|
|
|
|
2015-01-29 15:47:21 +00:00
|
|
|
bool isModified() const override { return true; }
|
2015-02-10 14:50:43 +00:00
|
|
|
bool supportsSelectiveLoad() const override { return true; }
|
2015-01-29 15:47:21 +00:00
|
|
|
|
2015-02-10 21:14:11 +00:00
|
|
|
DictionarySourcePtr clone() const override { return std::make_unique<ClickHouseDictionarySource>(*this); }
|
2015-01-29 15:47:21 +00:00
|
|
|
|
2016-12-08 02:49:04 +00:00
|
|
|
std::string toString() const override;
|
2015-03-25 10:09:33 +00:00
|
|
|
|
2015-01-30 13:43:16 +00:00
|
|
|
private:
|
2016-12-08 02:49:04 +00:00
|
|
|
BlockInputStreamPtr createStreamForSelectiveLoad(const std::string query);
|
2016-04-10 04:00:00 +00:00
|
|
|
|
2015-05-26 15:09:53 +00:00
|
|
|
const DictionaryStructure dict_struct;
|
2015-01-29 11:51:52 +00:00
|
|
|
const std::string host;
|
|
|
|
const UInt16 port;
|
2015-01-30 13:43:16 +00:00
|
|
|
const std::string user;
|
|
|
|
const std::string password;
|
|
|
|
const std::string db;
|
|
|
|
const std::string table;
|
2015-05-22 13:25:45 +00:00
|
|
|
const std::string where;
|
2016-04-10 04:00:00 +00:00
|
|
|
ExternalQueryBuilder query_builder;
|
2015-01-29 11:51:52 +00:00
|
|
|
Block sample_block;
|
2015-02-03 17:03:35 +00:00
|
|
|
Context & context;
|
2015-01-30 13:43:16 +00:00
|
|
|
const bool is_local;
|
2016-10-04 14:42:41 +00:00
|
|
|
ConnectionPoolPtr pool;
|
2015-01-29 11:51:52 +00:00
|
|
|
const std::string load_all_query;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|