2015-01-26 16:53:44 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <DB/Dictionaries/IDictionarySource.h>
|
2015-02-10 14:50:43 +00:00
|
|
|
#include <DB/Dictionaries/MySQLBlockInputStream.h>
|
2016-04-10 02:47:29 +00:00
|
|
|
#include <DB/Dictionaries/ExternalQueryBuilder.h>
|
2016-12-08 02:49:04 +00:00
|
|
|
#include <DB/Dictionaries/DictionaryStructure.h>
|
2015-10-05 00:33:43 +00:00
|
|
|
#include <ext/range.hpp>
|
2015-01-26 16:53:44 +00:00
|
|
|
#include <mysqlxx/Pool.h>
|
2015-01-30 13:43:16 +00:00
|
|
|
#include <Poco/Util/AbstractConfiguration.h>
|
2015-09-07 17:22:54 +00:00
|
|
|
|
2015-01-26 16:53:44 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2016-01-12 02:21:15 +00:00
|
|
|
|
2015-02-10 14:50:43 +00:00
|
|
|
/// Allows loading dictionaries from a MySQL database
|
|
|
|
class MySQLDictionarySource final : public IDictionarySource
|
2015-01-26 16:53:44 +00:00
|
|
|
{
|
|
|
|
public:
|
2016-04-10 02:47:29 +00:00
|
|
|
MySQLDictionarySource(const DictionaryStructure & dict_struct_,
|
2015-05-26 15:09:53 +00:00
|
|
|
const Poco::Util::AbstractConfiguration & config, const std::string & config_prefix,
|
2016-06-05 15:21:35 +00:00
|
|
|
const Block & sample_block);
|
2015-01-26 16:53:44 +00:00
|
|
|
|
2015-02-10 14:50:43 +00:00
|
|
|
/// copy-constructor is provided in order to support cloneability
|
2016-06-05 15:21:35 +00:00
|
|
|
MySQLDictionarySource(const MySQLDictionarySource & other);
|
2016-12-08 02:49:04 +00:00
|
|
|
|
2016-06-05 15:21:35 +00:00
|
|
|
BlockInputStreamPtr loadAll() override;
|
2015-01-26 16:53:44 +00:00
|
|
|
|
2016-10-26 22:27:38 +00:00
|
|
|
BlockInputStreamPtr loadIds(const std::vector<UInt64> & ids) override;
|
2015-11-16 17:27:12 +00:00
|
|
|
|
2016-06-05 15:21:35 +00:00
|
|
|
BlockInputStreamPtr loadKeys(
|
|
|
|
const ConstColumnPlainPtrs & key_columns, const std::vector<std::size_t> & requested_rows) override;
|
2015-08-12 03:57:32 +00:00
|
|
|
|
2016-06-05 15:21:35 +00:00
|
|
|
bool isModified() const override;
|
2015-08-12 03:57:32 +00:00
|
|
|
|
2016-06-05 15:21:35 +00:00
|
|
|
bool supportsSelectiveLoad() const override;
|
2015-01-30 11:51:59 +00:00
|
|
|
|
2016-06-05 15:21:35 +00:00
|
|
|
DictionarySourcePtr clone() const override;
|
2015-01-30 13:43:16 +00:00
|
|
|
|
2016-06-05 15:21:35 +00:00
|
|
|
std::string toString() const override;
|
2015-03-25 10:09:33 +00:00
|
|
|
|
2015-01-30 13:43:16 +00:00
|
|
|
private:
|
2015-08-11 21:29:44 +00:00
|
|
|
Logger * log = &Logger::get("MySQLDictionarySource");
|
|
|
|
|
2016-06-05 15:21:35 +00:00
|
|
|
static std::string quoteForLike(const std::string s);
|
2015-01-29 15:47:21 +00:00
|
|
|
|
2016-06-05 15:21:35 +00:00
|
|
|
LocalDateTime getLastModification() const;
|
2015-11-16 17:27:12 +00:00
|
|
|
|
2015-05-26 15:09:53 +00:00
|
|
|
const DictionaryStructure dict_struct;
|
2015-03-25 10:09:33 +00:00
|
|
|
const std::string db;
|
2015-01-30 13:43:16 +00:00
|
|
|
const std::string table;
|
2015-05-22 13:25:45 +00:00
|
|
|
const std::string where;
|
2015-08-12 03:57:32 +00:00
|
|
|
const bool dont_check_update_time;
|
2015-01-26 16:53:44 +00:00
|
|
|
Block sample_block;
|
2015-02-05 18:48:29 +00:00
|
|
|
mutable mysqlxx::PoolWithFailover pool;
|
2016-04-10 02:47:29 +00:00
|
|
|
ExternalQueryBuilder query_builder;
|
2015-01-27 13:00:20 +00:00
|
|
|
const std::string load_all_query;
|
2016-02-03 01:17:58 +00:00
|
|
|
LocalDateTime last_modification;
|
2015-01-26 16:53:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|