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
8namespace DB
9{
10
11class Context;
12
13
14/** Base class for system tables whose all columns have String type.
15 */
16template <typename Self>
17class IStorageSystemOneBlock : public IStorage
18{
19protected:
20 virtual void fillData(MutableColumns & res_columns, const Context & context, const SelectQueryInfo & query_info) const = 0;
21
22public:
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
47private:
48 const String name;
49};
50
51}
52