1 | #pragma once |
2 | |
3 | #include <Core/Block.h> |
4 | #include "config_core.h" |
5 | #if USE_POCO_MONGODB |
6 | |
7 | # include "DictionaryStructure.h" |
8 | # include "IDictionarySource.h" |
9 | |
10 | namespace Poco |
11 | { |
12 | namespace Util |
13 | { |
14 | class AbstractConfiguration; |
15 | } |
16 | |
17 | namespace MongoDB |
18 | { |
19 | class Connection; |
20 | } |
21 | } |
22 | |
23 | |
24 | namespace DB |
25 | { |
26 | /// Allows loading dictionaries from a MongoDB collection |
27 | class MongoDBDictionarySource final : public IDictionarySource |
28 | { |
29 | MongoDBDictionarySource( |
30 | const DictionaryStructure & dict_struct_, |
31 | const std::string & host_, |
32 | UInt16 port_, |
33 | const std::string & user_, |
34 | const std::string & password_, |
35 | const std::string & method_, |
36 | const std::string & db_, |
37 | const std::string & collection_, |
38 | const Block & sample_block_); |
39 | |
40 | public: |
41 | MongoDBDictionarySource( |
42 | const DictionaryStructure & dict_struct, |
43 | const Poco::Util::AbstractConfiguration & config, |
44 | const std::string & config_prefix, |
45 | Block & sample_block); |
46 | |
47 | MongoDBDictionarySource(const MongoDBDictionarySource & other); |
48 | |
49 | ~MongoDBDictionarySource() override; |
50 | |
51 | BlockInputStreamPtr loadAll() override; |
52 | |
53 | BlockInputStreamPtr loadUpdatedAll() override |
54 | { |
55 | throw Exception{"Method loadUpdatedAll is unsupported for MongoDBDictionarySource" , ErrorCodes::NOT_IMPLEMENTED}; |
56 | } |
57 | |
58 | bool supportsSelectiveLoad() const override { return true; } |
59 | |
60 | BlockInputStreamPtr loadIds(const std::vector<UInt64> & ids) override; |
61 | |
62 | BlockInputStreamPtr loadKeys(const Columns & key_columns, const std::vector<size_t> & requested_rows) override; |
63 | |
64 | /// @todo: for MongoDB, modification date can somehow be determined from the `_id` object field |
65 | bool isModified() const override { return true; } |
66 | |
67 | ///Not yet supported |
68 | bool hasUpdateField() const override { return false; } |
69 | |
70 | DictionarySourcePtr clone() const override { return std::make_unique<MongoDBDictionarySource>(*this); } |
71 | |
72 | std::string toString() const override; |
73 | |
74 | private: |
75 | const DictionaryStructure dict_struct; |
76 | const std::string host; |
77 | const UInt16 port; |
78 | const std::string user; |
79 | const std::string password; |
80 | const std::string method; |
81 | const std::string db; |
82 | const std::string collection; |
83 | Block sample_block; |
84 | |
85 | std::shared_ptr<Poco::MongoDB::Connection> connection; |
86 | }; |
87 | |
88 | } |
89 | #endif |
90 | |
91 | /*namespace DB |
92 | { |
93 | class DictionarySourceFactory; |
94 | void registerDictionarySourceMongoDB(DictionarySourceFactory & factory); |
95 | }*/ |
96 | |