1#pragma once
2
3#include <Common/SharedLibrary.h>
4#include <common/LocalDateTime.h>
5#include "DictionaryStructure.h"
6#include <Core/ExternalResultDescription.h>
7#include "IDictionarySource.h"
8
9
10namespace Poco
11{
12class Logger;
13
14namespace Util
15{
16 class AbstractConfiguration;
17}
18}
19
20
21namespace DB
22{
23class CStringsHolder;
24
25/// Allows loading dictionaries from dynamic libraries (.so)
26/// Experimental version
27/// Example: dbms/tests/external_dictionaries/dictionary_library/dictionary_library.cpp
28class LibraryDictionarySource final : public IDictionarySource
29{
30public:
31 LibraryDictionarySource(
32 const DictionaryStructure & dict_struct_,
33 const Poco::Util::AbstractConfiguration & config,
34 const std::string & config_prefix_,
35 Block & sample_block_,
36 const Context & context,
37 bool check_config);
38
39 LibraryDictionarySource(const LibraryDictionarySource & other);
40 LibraryDictionarySource & operator=(const LibraryDictionarySource &) = delete;
41
42 ~LibraryDictionarySource() override;
43
44 BlockInputStreamPtr loadAll() override;
45
46 BlockInputStreamPtr loadUpdatedAll() override
47 {
48 throw Exception{"Method loadUpdatedAll is unsupported for LibraryDictionarySource", ErrorCodes::NOT_IMPLEMENTED};
49 }
50
51 BlockInputStreamPtr loadIds(const std::vector<UInt64> & ids) override;
52
53 BlockInputStreamPtr loadKeys(const Columns & key_columns, const std::vector<std::size_t> & requested_rows) override;
54
55 bool isModified() const override;
56
57 bool supportsSelectiveLoad() const override;
58
59 ///Not yet supported
60 bool hasUpdateField() const override { return false; }
61
62 DictionarySourcePtr clone() const override;
63
64 std::string toString() const override;
65
66private:
67 Poco::Logger * log;
68
69 LocalDateTime getLastModification() const;
70
71 const DictionaryStructure dict_struct;
72 const std::string config_prefix;
73 const std::string path;
74 Block sample_block;
75 SharedLibraryPtr library;
76 ExternalResultDescription description;
77 std::shared_ptr<CStringsHolder> settings;
78 void * lib_data = nullptr;
79};
80
81}
82