1 | #pragma once |
---|---|
2 | |
3 | #include <Core/Block.h> |
4 | |
5 | #include "config_core.h" |
6 | #if USE_MYSQL |
7 | |
8 | # include <common/LocalDateTime.h> |
9 | # include <mysqlxx/PoolWithFailover.h> |
10 | # include "DictionaryStructure.h" |
11 | # include "ExternalQueryBuilder.h" |
12 | # include "IDictionarySource.h" |
13 | |
14 | |
15 | namespace Poco |
16 | { |
17 | class Logger; |
18 | |
19 | namespace Util |
20 | { |
21 | class AbstractConfiguration; |
22 | } |
23 | } |
24 | |
25 | |
26 | namespace DB |
27 | { |
28 | /// Allows loading dictionaries from a MySQL database |
29 | class MySQLDictionarySource final : public IDictionarySource |
30 | { |
31 | public: |
32 | MySQLDictionarySource( |
33 | const DictionaryStructure & dict_struct_, |
34 | const Poco::Util::AbstractConfiguration & config, |
35 | const std::string & config_prefix, |
36 | const Block & sample_block_); |
37 | |
38 | /// copy-constructor is provided in order to support cloneability |
39 | MySQLDictionarySource(const MySQLDictionarySource & other); |
40 | MySQLDictionarySource & operator=(const MySQLDictionarySource &) = delete; |
41 | |
42 | BlockInputStreamPtr loadAll() override; |
43 | |
44 | BlockInputStreamPtr loadUpdatedAll() override; |
45 | |
46 | BlockInputStreamPtr loadIds(const std::vector<UInt64> & ids) override; |
47 | |
48 | BlockInputStreamPtr loadKeys(const Columns & key_columns, const std::vector<size_t> & requested_rows) override; |
49 | |
50 | bool isModified() const override; |
51 | |
52 | bool supportsSelectiveLoad() const override; |
53 | |
54 | bool hasUpdateField() const override; |
55 | |
56 | DictionarySourcePtr clone() const override; |
57 | |
58 | std::string toString() const override; |
59 | |
60 | private: |
61 | std::string getUpdateFieldAndDate(); |
62 | |
63 | static std::string quoteForLike(const std::string s); |
64 | |
65 | LocalDateTime getLastModification() const; |
66 | |
67 | // execute invalidate_query. expects single cell in result |
68 | std::string doInvalidateQuery(const std::string & request) const; |
69 | |
70 | Poco::Logger * log; |
71 | |
72 | std::chrono::time_point<std::chrono::system_clock> update_time; |
73 | const DictionaryStructure dict_struct; |
74 | const std::string db; |
75 | const std::string table; |
76 | const std::string where; |
77 | const std::string update_field; |
78 | const bool dont_check_update_time; |
79 | Block sample_block; |
80 | mutable mysqlxx::PoolWithFailover pool; |
81 | ExternalQueryBuilder query_builder; |
82 | const std::string load_all_query; |
83 | LocalDateTime last_modification; |
84 | std::string invalidate_query; |
85 | mutable std::string invalidate_query_response; |
86 | const bool close_connection; |
87 | }; |
88 | |
89 | } |
90 | |
91 | #endif |
92 |