ClickHouse/src/Dictionaries/ClickHouseDictionarySource.h

81 lines
2.6 KiB
C++
Raw Normal View History

#pragma once
#include <memory>
2019-03-04 18:20:35 +00:00
#include <Poco/Logger.h>
#include <Client/ConnectionPoolWithFailover.h>
#include <Interpreters/Context.h>
#include "DictionaryStructure.h"
#include "ExternalQueryBuilder.h"
#include "IDictionarySource.h"
namespace DB
{
/** Allows loading dictionaries from local or remote ClickHouse instance
* @todo use ConnectionPoolWithFailover
* @todo invent a way to keep track of source modifications
2016-12-08 02:49:04 +00:00
*/
class ClickHouseDictionarySource final : public IDictionarySource
{
public:
ClickHouseDictionarySource(
const DictionaryStructure & dict_struct_,
const Poco::Util::AbstractConfiguration & config,
2020-04-17 19:54:53 +00:00
const std::string & path_to_settings,
const std::string & config_prefix,
2019-08-03 11:02:40 +00:00
const Block & sample_block_,
2020-08-15 03:10:57 +00:00
const Context & context,
const std::string & default_database);
/// 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;
BlockInputStreamPtr loadAll() override;
BlockInputStreamPtr loadUpdatedAll() override;
BlockInputStreamPtr loadIds(const std::vector<UInt64> & ids) override;
BlockInputStreamPtr loadKeys(const Columns & key_columns, const std::vector<size_t> & requested_rows) override;
2018-09-11 09:29:02 +00:00
bool isModified() const override;
bool supportsSelectiveLoad() const override { return true; }
bool hasUpdateField() const override;
DictionarySourcePtr clone() const override { return std::make_unique<ClickHouseDictionarySource>(*this); }
std::string toString() const override;
private:
std::string getUpdateFieldAndDate();
BlockInputStreamPtr createStreamForSelectiveLoad(const std::string & query);
2018-09-11 09:29:02 +00:00
std::string doInvalidateQuery(const std::string & request) const;
std::chrono::time_point<std::chrono::system_clock> update_time;
const DictionaryStructure dict_struct;
const std::string host;
const UInt16 port;
const bool secure;
const std::string user;
const std::string password;
const std::string db;
const std::string table;
const std::string where;
const std::string update_field;
2018-09-11 09:29:02 +00:00
std::string invalidate_query;
mutable std::string invalidate_query_response;
ExternalQueryBuilder query_builder;
Block sample_block;
Context context;
const bool is_local;
ConnectionPoolWithFailoverPtr pool;
const std::string load_all_query;
2019-03-04 18:20:35 +00:00
Poco::Logger * log = &Poco::Logger::get("ClickHouseDictionarySource");
};
}