ClickHouse/dbms/include/DB/Dictionaries/ClickHouseDictionarySource.h

63 lines
1.8 KiB
C++
Raw Normal View History

#pragma once
#include <DB/Dictionaries/IDictionarySource.h>
#include <DB/Dictionaries/DictionaryStructure.h>
#include <DB/Dictionaries/ExternalQueryBuilder.h>
#include <DB/Client/ConnectionPool.h>
#include <Poco/Util/AbstractConfiguration.h>
#include <memory>
namespace DB
{
/** 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
*/
class ClickHouseDictionarySource final : public IDictionarySource
{
public:
ClickHouseDictionarySource(const DictionaryStructure & dict_struct_,
const Poco::Util::AbstractConfiguration & config,
const std::string & config_prefix,
2016-12-08 02:49:04 +00:00
const Block & sample_block, Context & context);
/// copy-constructor is provided in order to support cloneability
2016-12-08 02:49:04 +00:00
ClickHouseDictionarySource(const ClickHouseDictionarySource & other);
2016-12-08 02:49:04 +00:00
BlockInputStreamPtr loadAll() override;
2016-12-08 02:49:04 +00:00
BlockInputStreamPtr loadIds(const std::vector<UInt64> & ids) override;
BlockInputStreamPtr loadKeys(
2016-12-08 02:49:04 +00:00
const ConstColumnPlainPtrs & key_columns, const std::vector<size_t> & requested_rows) override;
bool isModified() const override { return true; }
bool supportsSelectiveLoad() const override { return true; }
DictionarySourcePtr clone() const override { return std::make_unique<ClickHouseDictionarySource>(*this); }
2016-12-08 02:49:04 +00:00
std::string toString() const override;
private:
2016-12-08 02:49:04 +00:00
BlockInputStreamPtr createStreamForSelectiveLoad(const std::string query);
const DictionaryStructure dict_struct;
const std::string host;
const UInt16 port;
const std::string user;
const std::string password;
const std::string db;
const std::string table;
const std::string where;
ExternalQueryBuilder query_builder;
Block sample_block;
2015-02-03 17:03:35 +00:00
Context & context;
const bool is_local;
ConnectionPoolPtr pool;
const std::string load_all_query;
};
}