1#pragma once
2
3#include <IO/ConnectionTimeouts.h>
4#include <Poco/Data/SessionPool.h>
5#include <Poco/URI.h>
6#include <Common/XDBCBridgeHelper.h>
7#include "DictionaryStructure.h"
8#include "ExternalQueryBuilder.h"
9#include "IDictionarySource.h"
10
11
12namespace Poco
13{
14namespace Util
15{
16 class AbstractConfiguration;
17}
18
19class Logger;
20}
21
22
23namespace DB
24{
25/// Allows loading dictionaries from a XDBC source via bridges
26class XDBCDictionarySource final : public IDictionarySource
27{
28public:
29 XDBCDictionarySource(
30 const DictionaryStructure & dict_struct_,
31 const Poco::Util::AbstractConfiguration & config_,
32 const std::string & config_prefix_,
33 const Block & sample_block_,
34 const Context & context_,
35 BridgeHelperPtr bridge);
36
37 /// copy-constructor is provided in order to support cloneability
38 XDBCDictionarySource(const XDBCDictionarySource & other);
39 XDBCDictionarySource & operator=(const XDBCDictionarySource &) = delete;
40
41 BlockInputStreamPtr loadAll() override;
42
43 BlockInputStreamPtr loadUpdatedAll() override;
44
45 BlockInputStreamPtr loadIds(const std::vector<UInt64> & ids) override;
46
47 BlockInputStreamPtr loadKeys(const Columns & key_columns, const std::vector<size_t> & requested_rows) override;
48
49 bool isModified() const override;
50
51 bool supportsSelectiveLoad() const override;
52
53 bool hasUpdateField() const override;
54
55 DictionarySourcePtr clone() const override;
56
57 std::string toString() const override;
58
59private:
60 std::string getUpdateFieldAndDate();
61
62 // execute invalidate_query. expects single cell in result
63 std::string doInvalidateQuery(const std::string & request) const;
64
65 BlockInputStreamPtr loadBase(const std::string & query) const;
66
67 Poco::Logger * log;
68
69 std::chrono::time_point<std::chrono::system_clock> update_time;
70 const DictionaryStructure dict_struct;
71 const std::string db;
72 const std::string table;
73 const std::string where;
74 const std::string update_field;
75 Block sample_block;
76 ExternalQueryBuilder query_builder;
77 const std::string load_all_query;
78 std::string invalidate_query;
79 mutable std::string invalidate_query_response;
80
81 BridgeHelperPtr bridge_helper;
82 Poco::URI bridge_url;
83 ConnectionTimeouts timeouts;
84 const Context & global_context;
85};
86
87}
88