2015-01-29 11:51:52 +00:00
|
|
|
#pragma once
|
|
|
|
|
2018-12-10 15:25:45 +00:00
|
|
|
#include <memory>
|
2019-03-04 18:20:35 +00:00
|
|
|
#include <Poco/Logger.h>
|
2018-12-10 15:25:45 +00:00
|
|
|
#include <Client/ConnectionPoolWithFailover.h>
|
2019-01-29 19:05:32 +00:00
|
|
|
#include <Interpreters/Context.h>
|
2018-11-28 11:37:12 +00:00
|
|
|
#include "DictionaryStructure.h"
|
|
|
|
#include "ExternalQueryBuilder.h"
|
2018-12-10 15:25:45 +00:00
|
|
|
#include "IDictionarySource.h"
|
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:
|
2018-12-10 15:25:45 +00:00
|
|
|
ClickHouseDictionarySource(
|
|
|
|
const DictionaryStructure & dict_struct_,
|
2017-04-01 07:20:54 +00:00
|
|
|
const Poco::Util::AbstractConfiguration & config,
|
|
|
|
const std::string & config_prefix,
|
2019-08-03 11:02:40 +00:00
|
|
|
const Block & sample_block_,
|
2019-10-10 20:47:47 +00:00
|
|
|
const 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);
|
2019-07-08 00:51:43 +00:00
|
|
|
ClickHouseDictionarySource & operator=(const ClickHouseDictionarySource &) = delete;
|
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
|
|
|
|
2018-12-10 15:25:45 +00:00
|
|
|
BlockInputStreamPtr loadKeys(const Columns & key_columns, const std::vector<size_t> & requested_rows) override;
|
2015-01-29 11:51:52 +00:00
|
|
|
|
2018-09-11 09:29:02 +00:00
|
|
|
bool isModified() const override;
|
2017-04-01 07:20:54 +00:00
|
|
|
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-09-11 09:29:02 +00:00
|
|
|
std::string doInvalidateQuery(const std::string & request) const;
|
|
|
|
|
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;
|
2018-09-11 09:29:02 +00:00
|
|
|
std::string invalidate_query;
|
|
|
|
mutable std::string invalidate_query_response;
|
2017-04-01 07:20:54 +00:00
|
|
|
ExternalQueryBuilder query_builder;
|
|
|
|
Block sample_block;
|
2019-01-29 19:05:32 +00:00
|
|
|
Context context;
|
2017-04-01 07:20:54 +00:00
|
|
|
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;
|
2019-03-04 18:20:35 +00:00
|
|
|
Poco::Logger * log = &Poco::Logger::get("ClickHouseDictionarySource");
|
2015-01-29 11:51:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|