1 | #pragma once |
2 | #include <DataStreams/OneBlockInputStream.h> |
3 | #include <DataTypes/DataTypeString.h> |
4 | #include <Storages/ColumnsDescription.h> |
5 | #include <Storages/IStorage.h> |
6 | #include <ext/shared_ptr_helper.h> |
7 | |
8 | namespace DB |
9 | { |
10 | |
11 | class Context; |
12 | |
13 | |
14 | /** Base class for system tables whose all columns have String type. |
15 | */ |
16 | template <typename Self> |
17 | class IStorageSystemOneBlock : public IStorage |
18 | { |
19 | protected: |
20 | virtual void fillData(MutableColumns & res_columns, const Context & context, const SelectQueryInfo & query_info) const = 0; |
21 | |
22 | public: |
23 | IStorageSystemOneBlock(const String & name_) : name(name_) |
24 | { |
25 | setColumns(ColumnsDescription(Self::getNamesAndTypes())); |
26 | } |
27 | |
28 | std::string getTableName() const override { return name; } |
29 | std::string getDatabaseName() const override { return "system" ; } |
30 | |
31 | BlockInputStreams read(const Names & column_names, |
32 | const SelectQueryInfo & query_info, |
33 | const Context & context, |
34 | QueryProcessingStage::Enum /*processed_stage*/, |
35 | size_t /*max_block_size*/, |
36 | unsigned /*num_streams*/) override |
37 | { |
38 | check(column_names); |
39 | |
40 | Block sample_block = getSampleBlock(); |
41 | MutableColumns res_columns = sample_block.cloneEmptyColumns(); |
42 | fillData(res_columns, context, query_info); |
43 | |
44 | return BlockInputStreams(1, std::make_shared<OneBlockInputStream>(sample_block.cloneWithColumns(std::move(res_columns)))); |
45 | } |
46 | |
47 | private: |
48 | const String name; |
49 | }; |
50 | |
51 | } |
52 | |