2018-09-28 02:46:33 +00:00
|
|
|
#pragma once
|
|
|
|
|
2018-12-10 15:25:45 +00:00
|
|
|
#include <IO/ConnectionTimeouts.h>
|
2018-09-28 02:46:33 +00:00
|
|
|
#include <Poco/Data/SessionPool.h>
|
|
|
|
#include <Poco/URI.h>
|
2021-03-12 21:12:34 +00:00
|
|
|
#include <Bridge/XDBCBridgeHelper.h>
|
2018-11-28 11:37:12 +00:00
|
|
|
#include "DictionaryStructure.h"
|
|
|
|
#include "ExternalQueryBuilder.h"
|
|
|
|
#include "IDictionarySource.h"
|
2018-09-28 02:46:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace Poco
|
|
|
|
{
|
2018-10-03 12:10:57 +00:00
|
|
|
namespace Util
|
|
|
|
{
|
|
|
|
class AbstractConfiguration;
|
|
|
|
}
|
2018-09-28 02:46:33 +00:00
|
|
|
|
2018-10-03 12:10:57 +00:00
|
|
|
class Logger;
|
2018-09-28 02:46:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
/// Allows loading dictionaries from a XDBC source via bridges
|
2021-04-10 23:33:54 +00:00
|
|
|
class XDBCDictionarySource final : public IDictionarySource, WithContext
|
2018-10-03 12:10:57 +00:00
|
|
|
{
|
|
|
|
public:
|
2018-12-10 15:25:45 +00:00
|
|
|
XDBCDictionarySource(
|
|
|
|
const DictionaryStructure & dict_struct_,
|
2018-10-03 12:10:57 +00:00
|
|
|
const Poco::Util::AbstractConfiguration & config_,
|
|
|
|
const std::string & config_prefix_,
|
|
|
|
const Block & sample_block_,
|
2021-04-10 23:33:54 +00:00
|
|
|
ContextPtr context_,
|
2018-10-03 12:10:57 +00:00
|
|
|
BridgeHelperPtr bridge);
|
2018-09-28 02:46:33 +00:00
|
|
|
|
2018-10-03 12:10:57 +00:00
|
|
|
/// copy-constructor is provided in order to support cloneability
|
|
|
|
XDBCDictionarySource(const XDBCDictionarySource & other);
|
2019-07-08 00:51:43 +00:00
|
|
|
XDBCDictionarySource & operator=(const XDBCDictionarySource &) = delete;
|
2018-09-28 02:46:33 +00:00
|
|
|
|
2018-10-03 12:10:57 +00:00
|
|
|
BlockInputStreamPtr loadAll() override;
|
2018-09-28 02:46:33 +00:00
|
|
|
|
2018-10-03 12:10:57 +00:00
|
|
|
BlockInputStreamPtr loadUpdatedAll() override;
|
2018-09-28 02:46:33 +00:00
|
|
|
|
2018-10-03 12:10:57 +00:00
|
|
|
BlockInputStreamPtr loadIds(const std::vector<UInt64> & ids) override;
|
2018-09-28 02:46:33 +00:00
|
|
|
|
2018-10-03 12:10:57 +00:00
|
|
|
BlockInputStreamPtr loadKeys(const Columns & key_columns, const std::vector<size_t> & requested_rows) override;
|
2018-09-28 02:46:33 +00:00
|
|
|
|
2018-10-03 12:10:57 +00:00
|
|
|
bool isModified() const override;
|
2018-09-28 02:46:33 +00:00
|
|
|
|
2018-10-03 12:10:57 +00:00
|
|
|
bool supportsSelectiveLoad() const override;
|
2018-09-28 02:46:33 +00:00
|
|
|
|
2018-10-03 12:10:57 +00:00
|
|
|
bool hasUpdateField() const override;
|
2018-09-28 02:46:33 +00:00
|
|
|
|
2018-10-03 12:10:57 +00:00
|
|
|
DictionarySourcePtr clone() const override;
|
2018-09-28 02:46:33 +00:00
|
|
|
|
2018-10-03 12:10:57 +00:00
|
|
|
std::string toString() const override;
|
2018-09-28 02:46:33 +00:00
|
|
|
|
2018-10-03 12:10:57 +00:00
|
|
|
private:
|
|
|
|
std::string getUpdateFieldAndDate();
|
2018-09-28 02:46:33 +00:00
|
|
|
|
2018-10-03 12:10:57 +00:00
|
|
|
// execute invalidate_query. expects single cell in result
|
|
|
|
std::string doInvalidateQuery(const std::string & request) const;
|
2018-09-28 02:46:33 +00:00
|
|
|
|
2021-04-17 08:09:22 +00:00
|
|
|
BlockInputStreamPtr loadFromQuery(const Poco::URI url, const Block & required_sample_block, const std::string & query) const;
|
2018-09-28 02:46:33 +00:00
|
|
|
|
2018-10-03 12:10:57 +00:00
|
|
|
Poco::Logger * log;
|
2018-09-28 02:46:33 +00:00
|
|
|
|
2018-10-03 12:10:57 +00:00
|
|
|
std::chrono::time_point<std::chrono::system_clock> update_time;
|
|
|
|
const DictionaryStructure dict_struct;
|
|
|
|
const std::string db;
|
2020-07-06 12:23:36 +00:00
|
|
|
const std::string schema;
|
2018-10-03 12:10:57 +00:00
|
|
|
const std::string table;
|
|
|
|
const std::string where;
|
|
|
|
const std::string update_field;
|
|
|
|
Block sample_block;
|
|
|
|
ExternalQueryBuilder query_builder;
|
|
|
|
const std::string load_all_query;
|
|
|
|
std::string invalidate_query;
|
|
|
|
mutable std::string invalidate_query_response;
|
2018-09-28 02:46:33 +00:00
|
|
|
|
2018-10-03 12:10:57 +00:00
|
|
|
BridgeHelperPtr bridge_helper;
|
|
|
|
Poco::URI bridge_url;
|
|
|
|
ConnectionTimeouts timeouts;
|
|
|
|
};
|
2018-11-28 11:37:12 +00:00
|
|
|
|
2018-09-28 02:46:33 +00:00
|
|
|
}
|