2015-01-26 16:53:44 +00:00
|
|
|
#pragma once
|
|
|
|
|
2019-05-17 14:34:25 +00:00
|
|
|
#include <Core/Block.h>
|
2019-06-24 11:17:15 +00:00
|
|
|
|
|
|
|
#include "config_core.h"
|
2018-11-28 11:37:12 +00:00
|
|
|
#if USE_MYSQL
|
|
|
|
|
2018-12-10 15:25:45 +00:00
|
|
|
# include <common/LocalDateTime.h>
|
|
|
|
# include <mysqlxx/PoolWithFailover.h>
|
|
|
|
# include "DictionaryStructure.h"
|
|
|
|
# include "ExternalQueryBuilder.h"
|
|
|
|
# include "IDictionarySource.h"
|
2015-09-07 17:22:54 +00:00
|
|
|
|
2015-01-26 16:53:44 +00:00
|
|
|
|
2017-12-09 06:32:22 +00:00
|
|
|
namespace Poco
|
|
|
|
{
|
2018-12-10 15:25:45 +00:00
|
|
|
class Logger;
|
2017-12-09 06:32:22 +00:00
|
|
|
|
2018-12-10 15:25:45 +00:00
|
|
|
namespace Util
|
|
|
|
{
|
|
|
|
class AbstractConfiguration;
|
|
|
|
}
|
2017-12-09 06:32:22 +00:00
|
|
|
}
|
2017-01-21 04:24:28 +00:00
|
|
|
|
|
|
|
|
2015-01-26 16:53:44 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
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:
|
2018-12-10 15:25:45 +00:00
|
|
|
MySQLDictionarySource(
|
|
|
|
const DictionaryStructure & dict_struct_,
|
|
|
|
const Poco::Util::AbstractConfiguration & config,
|
|
|
|
const std::string & config_prefix,
|
2019-08-03 11:02:40 +00:00
|
|
|
const Block & sample_block_);
|
2015-01-26 16:53:44 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
/// copy-constructor is provided in order to support cloneability
|
|
|
|
MySQLDictionarySource(const MySQLDictionarySource & other);
|
2019-07-08 00:51:43 +00:00
|
|
|
MySQLDictionarySource & operator=(const MySQLDictionarySource &) = delete;
|
2016-12-08 02:49:04 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
BlockInputStreamPtr loadAll() override;
|
2015-01-26 16:53:44 +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-11-16 17:27:12 +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-08-12 03:57:32 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
bool isModified() const override;
|
2015-08-12 03:57:32 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
bool supportsSelectiveLoad() const override;
|
2015-01-30 11:51:59 +00:00
|
|
|
|
2018-01-15 12:44:39 +00:00
|
|
|
bool hasUpdateField() const override;
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
DictionarySourcePtr clone() const override;
|
2015-01-30 13:43:16 +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-04-01 07:20:54 +00:00
|
|
|
static std::string quoteForLike(const std::string s);
|
|
|
|
|
2020-02-27 09:34:06 +00:00
|
|
|
LocalDateTime getLastModification(mysqlxx::Pool::Entry & connection, bool allow_connection_closure) const;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2017-05-22 16:38:24 +00:00
|
|
|
// execute invalidate_query. expects single cell in result
|
|
|
|
std::string doInvalidateQuery(const std::string & request) const;
|
2017-05-15 14:16:10 +00:00
|
|
|
|
|
|
|
Poco::Logger * log;
|
2018-01-15 12:44:39 +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 db;
|
|
|
|
const std::string table;
|
|
|
|
const std::string where;
|
2018-01-15 12:44:39 +00:00
|
|
|
const std::string update_field;
|
2017-04-01 07:20:54 +00:00
|
|
|
const bool dont_check_update_time;
|
|
|
|
Block sample_block;
|
|
|
|
mutable mysqlxx::PoolWithFailover pool;
|
|
|
|
ExternalQueryBuilder query_builder;
|
|
|
|
const std::string load_all_query;
|
|
|
|
LocalDateTime last_modification;
|
2017-05-15 14:16:10 +00:00
|
|
|
std::string invalidate_query;
|
|
|
|
mutable std::string invalidate_query_response;
|
2019-05-23 13:55:00 +00:00
|
|
|
const bool close_connection;
|
2015-01-26 16:53:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
2018-11-28 11:37:12 +00:00
|
|
|
|
|
|
|
#endif
|