2020-12-09 21:14:16 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#if !defined(ARCADIA_BUILD)
|
|
|
|
#include "config_core.h"
|
|
|
|
#endif
|
2020-12-13 22:48:40 +00:00
|
|
|
#include "DictionaryStructure.h"
|
|
|
|
#include "IDictionarySource.h"
|
2020-12-09 21:14:16 +00:00
|
|
|
|
|
|
|
#if USE_LIBPQXX
|
2020-12-13 22:48:40 +00:00
|
|
|
#include "ExternalQueryBuilder.h"
|
2020-12-09 21:14:16 +00:00
|
|
|
#include <Core/Block.h>
|
2020-12-13 22:48:40 +00:00
|
|
|
#include <common/LocalDateTime.h>
|
2020-12-09 21:14:16 +00:00
|
|
|
#include <common/logger_useful.h>
|
2021-05-05 22:46:52 +00:00
|
|
|
#include <Storages/PostgreSQL/PoolWithFailover.h>
|
2020-12-09 21:14:16 +00:00
|
|
|
#include <pqxx/pqxx>
|
|
|
|
|
2021-01-11 10:23:44 +00:00
|
|
|
|
2020-12-09 21:14:16 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
/// Allows loading dictionaries from a PostgreSQL database
|
|
|
|
class PostgreSQLDictionarySource final : public IDictionarySource
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PostgreSQLDictionarySource(
|
|
|
|
const DictionaryStructure & dict_struct_,
|
2021-05-05 22:46:52 +00:00
|
|
|
postgres::PoolWithFailoverPtr entry_,
|
2020-12-09 21:14:16 +00:00
|
|
|
const Poco::Util::AbstractConfiguration & config_,
|
|
|
|
const std::string & config_prefix,
|
|
|
|
const Block & sample_block_);
|
|
|
|
|
|
|
|
/// copy-constructor is provided in order to support cloneability
|
|
|
|
PostgreSQLDictionarySource(const PostgreSQLDictionarySource & other);
|
|
|
|
PostgreSQLDictionarySource & operator=(const PostgreSQLDictionarySource &) = 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;
|
|
|
|
|
|
|
|
bool isModified() const override;
|
|
|
|
bool supportsSelectiveLoad() const override;
|
|
|
|
bool hasUpdateField() const override;
|
|
|
|
|
|
|
|
DictionarySourcePtr clone() const override;
|
|
|
|
std::string toString() const override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::string getUpdateFieldAndDate();
|
|
|
|
std::string doInvalidateQuery(const std::string & request) const;
|
2021-03-14 08:35:07 +00:00
|
|
|
BlockInputStreamPtr loadBase(const String & query);
|
2020-12-09 21:14:16 +00:00
|
|
|
|
|
|
|
const DictionaryStructure dict_struct;
|
|
|
|
Block sample_block;
|
2021-05-05 22:46:52 +00:00
|
|
|
postgres::PoolWithFailoverPtr pool;
|
2020-12-09 21:14:16 +00:00
|
|
|
Poco::Logger * log;
|
|
|
|
|
|
|
|
const std::string db;
|
|
|
|
const std::string table;
|
|
|
|
const std::string where;
|
|
|
|
ExternalQueryBuilder query_builder;
|
|
|
|
const std::string load_all_query;
|
|
|
|
std::string invalidate_query;
|
|
|
|
std::chrono::time_point<std::chrono::system_clock> update_time;
|
|
|
|
const std::string update_field;
|
|
|
|
mutable std::string invalidate_query_response;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif
|