1#pragma once
2
3#include <Storages/IStorage.h>
4#include <Core/Defines.h>
5#include <Common/MultiVersion.h>
6#include <ext/shared_ptr_helper.h>
7#include <IO/WriteBufferFromString.h>
8#include <IO/Operators.h>
9
10
11namespace Poco
12{
13class Logger;
14}
15
16namespace DB
17{
18struct DictionaryStructure;
19struct IDictionaryBase;
20class ExternalDictionaries;
21
22class StorageDictionary : public ext::shared_ptr_helper<StorageDictionary>, public IStorage
23{
24 friend struct ext::shared_ptr_helper<StorageDictionary>;
25public:
26 std::string getName() const override { return "Dictionary"; }
27 std::string getTableName() const override { return table_name; }
28 std::string getDatabaseName() const override { return database_name; }
29
30 BlockInputStreams read(const Names & column_names,
31 const SelectQueryInfo & query_info,
32 const Context & context,
33 QueryProcessingStage::Enum processed_stage,
34 size_t max_block_size = DEFAULT_BLOCK_SIZE,
35 unsigned threads = 1) override;
36
37 static NamesAndTypesList getNamesAndTypes(const DictionaryStructure & dictionary_structure);
38
39 template <typename ForwardIterator>
40 static std::string generateNamesAndTypesDescription(ForwardIterator begin, ForwardIterator end)
41 {
42 std::string description;
43 {
44 WriteBufferFromString buffer(description);
45 bool first = true;
46 for (; begin != end; ++begin)
47 {
48 if (!first)
49 buffer << ", ";
50 first = false;
51
52 buffer << begin->name << ' ' << begin->type->getName();
53 }
54 }
55
56 return description;
57 }
58
59private:
60 using Ptr = MultiVersion<IDictionaryBase>::Version;
61
62 String table_name;
63 String database_name;
64 String dictionary_name;
65 Poco::Logger * logger;
66
67 void checkNamesAndTypesCompatibleWithDictionary(const DictionaryStructure & dictionary_structure) const;
68
69protected:
70 StorageDictionary(
71 const String & database_name_,
72 const String & table_name_,
73 const ColumnsDescription & columns_,
74 const Context & context,
75 bool attach,
76 const String & dictionary_name_);
77};
78
79}
80