2015-01-29 11:51:52 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Dictionaries/IDictionarySource.h>
|
|
|
|
#include <Dictionaries/DictionaryStructure.h>
|
|
|
|
#include <Dictionaries/ExternalQueryBuilder.h>
|
2017-04-19 17:40:55 +00:00
|
|
|
#include <Client/ConnectionPoolWithFailover.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
|
2017-04-01 07:20:54 +00:00
|
|
|
* @todo use ConnectionPoolWithFailover
|
|
|
|
* @todo invent a way to keep track of source modifications
|
2016-12-08 02:49:04 +00:00
|
|
|
*/
|
2015-02-10 14:50:43 +00:00
|
|
|
class ClickHouseDictionarySource final : public IDictionarySource
|
2015-01-29 11:51:52 +00:00
|
|
|
{
|
|
|
|
public:
|
2017-04-01 07:20:54 +00:00
|
|
|
ClickHouseDictionarySource(const DictionaryStructure & dict_struct_,
|
|
|
|
const Poco::Util::AbstractConfiguration & config,
|
|
|
|
const std::string & config_prefix,
|
|
|
|
const Block & sample_block, Context & context);
|
2015-01-29 11:51:52 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
/// copy-constructor is provided in order to support cloneability
|
|
|
|
ClickHouseDictionarySource(const ClickHouseDictionarySource & other);
|
2015-01-30 13:43:16 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
BlockInputStreamPtr loadAll() override;
|
2015-01-29 11:51:52 +00:00
|
|
|
|
2018-02-15 13:08:23 +00:00
|
|
|
BlockInputStreamPtr loadUpdatedAll() override;
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
BlockInputStreamPtr loadIds(const std::vector<UInt64> & ids) override;
|
2015-02-19 14:51:39 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
BlockInputStreamPtr loadKeys(
|
2017-05-25 19:52:05 +00:00
|
|
|
const Columns & key_columns, const std::vector<size_t> & requested_rows) override;
|
2015-01-29 11:51:52 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
bool isModified() const override { return true; }
|
|
|
|
bool supportsSelectiveLoad() const override { return true; }
|
2015-01-29 15:47:21 +00:00
|
|
|
|
2018-02-15 13:08:23 +00:00
|
|
|
bool hasUpdateField() const override;
|
2018-01-15 12:44:39 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
DictionarySourcePtr clone() const override { return std::make_unique<ClickHouseDictionarySource>(*this); }
|
2015-01-29 15:47:21 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
std::string toString() const override;
|
2015-03-25 10:09:33 +00:00
|
|
|
|
2015-01-30 13:43:16 +00:00
|
|
|
private:
|
2018-02-15 13:08:23 +00:00
|
|
|
std::string getUpdateFieldAndDate();
|
|
|
|
|
2017-07-28 18:43:40 +00:00
|
|
|
BlockInputStreamPtr createStreamForSelectiveLoad(const std::string & query);
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2018-02-15 13:08:23 +00:00
|
|
|
std::chrono::time_point<std::chrono::system_clock> update_time;
|
2017-04-01 07:20:54 +00:00
|
|
|
const DictionaryStructure dict_struct;
|
|
|
|
const std::string host;
|
|
|
|
const UInt16 port;
|
2018-03-29 01:41:06 +00:00
|
|
|
const bool secure;
|
2017-04-01 07:20:54 +00:00
|
|
|
const std::string user;
|
|
|
|
const std::string password;
|
|
|
|
const std::string db;
|
|
|
|
const std::string table;
|
|
|
|
const std::string where;
|
2018-02-15 13:08:23 +00:00
|
|
|
const std::string update_field;
|
2017-04-01 07:20:54 +00:00
|
|
|
ExternalQueryBuilder query_builder;
|
|
|
|
Block sample_block;
|
|
|
|
Context & context;
|
|
|
|
const bool is_local;
|
2017-04-19 17:40:55 +00:00
|
|
|
ConnectionPoolWithFailoverPtr pool;
|
2017-04-01 07:20:54 +00:00
|
|
|
const std::string load_all_query;
|
2015-01-29 11:51:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|