| 1 | #pragma once |
| 2 | |
| 3 | #include <Parsers/ASTSelectQuery.h> |
| 4 | #include <Parsers/IAST_fwd.h> |
| 5 | #include <Storages/IStorage.h> |
| 6 | |
| 7 | #include <ext/shared_ptr_helper.h> |
| 8 | |
| 9 | |
| 10 | namespace DB |
| 11 | { |
| 12 | |
| 13 | class StorageView : public ext::shared_ptr_helper<StorageView>, public IStorage |
| 14 | { |
| 15 | friend struct ext::shared_ptr_helper<StorageView>; |
| 16 | public: |
| 17 | std::string getName() const override { return "View" ; } |
| 18 | std::string getTableName() const override { return table_name; } |
| 19 | std::string getDatabaseName() const override { return database_name; } |
| 20 | |
| 21 | /// It is passed inside the query and solved at its level. |
| 22 | bool supportsSampling() const override { return true; } |
| 23 | bool supportsFinal() const override { return true; } |
| 24 | |
| 25 | BlockInputStreams read( |
| 26 | const Names & column_names, |
| 27 | const SelectQueryInfo & query_info, |
| 28 | const Context & context, |
| 29 | QueryProcessingStage::Enum processed_stage, |
| 30 | size_t max_block_size, |
| 31 | unsigned num_streams) override; |
| 32 | |
| 33 | void rename(const String & /*new_path_to_db*/, const String & new_database_name, const String & new_table_name, TableStructureWriteLockHolder &) override |
| 34 | { |
| 35 | table_name = new_table_name; |
| 36 | database_name = new_database_name; |
| 37 | } |
| 38 | |
| 39 | private: |
| 40 | String table_name; |
| 41 | String database_name; |
| 42 | ASTPtr inner_query; |
| 43 | |
| 44 | void replaceTableNameWithSubquery(ASTSelectQuery * select_query, ASTPtr & subquery); |
| 45 | |
| 46 | protected: |
| 47 | StorageView( |
| 48 | const String & database_name_, |
| 49 | const String & table_name_, |
| 50 | const ASTCreateQuery & query, |
| 51 | const ColumnsDescription & columns_); |
| 52 | }; |
| 53 | |
| 54 | } |
| 55 | |