1 | #pragma once |
2 | |
3 | #include <ext/shared_ptr_helper.h> |
4 | #include <Formats/FormatSettings.h> |
5 | #include <Storages/IStorage.h> |
6 | #include <Storages/MergeTree/MergeTreeData.h> |
7 | |
8 | |
9 | namespace DB |
10 | { |
11 | |
12 | class Context; |
13 | |
14 | struct StoragesInfo |
15 | { |
16 | StoragePtr storage = nullptr; |
17 | TableStructureReadLockHolder table_lock; |
18 | |
19 | String database; |
20 | String table; |
21 | String engine; |
22 | |
23 | bool need_inactive_parts = false; |
24 | MergeTreeData * data = nullptr; |
25 | |
26 | operator bool() const { return storage != nullptr; } |
27 | MergeTreeData::DataPartsVector getParts(MergeTreeData::DataPartStateVector & state, bool has_state_column) const; |
28 | }; |
29 | |
30 | /** A helper class that enumerates the storages that match given query. */ |
31 | class StoragesInfoStream |
32 | { |
33 | public: |
34 | StoragesInfoStream(const SelectQueryInfo & query_info, const Context & context); |
35 | StoragesInfo next(); |
36 | |
37 | private: |
38 | String query_id; |
39 | |
40 | ColumnPtr database_column; |
41 | ColumnPtr table_column; |
42 | ColumnPtr active_column; |
43 | |
44 | size_t next_row; |
45 | size_t rows; |
46 | |
47 | using StoragesMap = std::map<std::pair<String, String>, StoragePtr>; |
48 | StoragesMap storages; |
49 | }; |
50 | |
51 | /** Implements system table 'parts' which allows to get information about data parts for tables of MergeTree family. |
52 | */ |
53 | class StorageSystemPartsBase : public IStorage |
54 | { |
55 | public: |
56 | std::string getTableName() const override { return name; } |
57 | std::string getDatabaseName() const override { return "system" ; } |
58 | |
59 | NameAndTypePair getColumn(const String & column_name) const override; |
60 | |
61 | bool hasColumn(const String & column_name) const override; |
62 | |
63 | BlockInputStreams read( |
64 | const Names & column_names, |
65 | const SelectQueryInfo & query_info, |
66 | const Context & context, |
67 | QueryProcessingStage::Enum processed_stage, |
68 | size_t max_block_size, |
69 | unsigned num_streams) override; |
70 | |
71 | private: |
72 | const std::string name; |
73 | |
74 | bool hasStateColumn(const Names & column_names) const; |
75 | |
76 | protected: |
77 | const FormatSettings format_settings; |
78 | |
79 | StorageSystemPartsBase(std::string name_, NamesAndTypesList && columns_); |
80 | |
81 | virtual void processNextStorage(MutableColumns & columns, const StoragesInfo & info, bool has_state_column) = 0; |
82 | }; |
83 | |
84 | } |
85 | |