| 1 | #pragma once | 
|---|
| 2 |  | 
|---|
| 3 | #include <mutex> | 
|---|
| 4 |  | 
|---|
| 5 | #include <ext/shared_ptr_helper.h> | 
|---|
| 6 |  | 
|---|
| 7 | #include <Core/NamesAndTypes.h> | 
|---|
| 8 | #include <Storages/IStorage.h> | 
|---|
| 9 | #include <DataStreams/IBlockOutputStream.h> | 
|---|
| 10 |  | 
|---|
| 11 |  | 
|---|
| 12 | namespace DB | 
|---|
| 13 | { | 
|---|
| 14 |  | 
|---|
| 15 | /** Implements storage in the RAM. | 
|---|
| 16 | * Suitable for temporary data. | 
|---|
| 17 | * It does not support keys. | 
|---|
| 18 | * Data is stored as a set of blocks and is not stored anywhere else. | 
|---|
| 19 | */ | 
|---|
| 20 | class StorageMemory : public ext::shared_ptr_helper<StorageMemory>, public IStorage | 
|---|
| 21 | { | 
|---|
| 22 | friend class MemoryBlockInputStream; | 
|---|
| 23 | friend class MemoryBlockOutputStream; | 
|---|
| 24 | friend struct ext::shared_ptr_helper<StorageMemory>; | 
|---|
| 25 |  | 
|---|
| 26 | public: | 
|---|
| 27 | String getName() const override { return "Memory"; } | 
|---|
| 28 | String getTableName() const override { return table_name; } | 
|---|
| 29 | String getDatabaseName() const override { return database_name; } | 
|---|
| 30 |  | 
|---|
| 31 | size_t getSize() const { return data.size(); } | 
|---|
| 32 |  | 
|---|
| 33 | BlockInputStreams read( | 
|---|
| 34 | const Names & column_names, | 
|---|
| 35 | const SelectQueryInfo & query_info, | 
|---|
| 36 | const Context & context, | 
|---|
| 37 | QueryProcessingStage::Enum processed_stage, | 
|---|
| 38 | size_t max_block_size, | 
|---|
| 39 | unsigned num_streams) override; | 
|---|
| 40 |  | 
|---|
| 41 | BlockOutputStreamPtr write(const ASTPtr & query, const Context & context) override; | 
|---|
| 42 |  | 
|---|
| 43 | void drop(TableStructureWriteLockHolder &) override; | 
|---|
| 44 |  | 
|---|
| 45 | void truncate(const ASTPtr &, const Context &, TableStructureWriteLockHolder &) override; | 
|---|
| 46 |  | 
|---|
| 47 | void rename(const String & /*new_path_to_db*/, const String & new_database_name, const String & new_table_name, TableStructureWriteLockHolder &) override | 
|---|
| 48 | { | 
|---|
| 49 | table_name = new_table_name; | 
|---|
| 50 | database_name = new_database_name; | 
|---|
| 51 | } | 
|---|
| 52 |  | 
|---|
| 53 | private: | 
|---|
| 54 | String database_name; | 
|---|
| 55 | String table_name; | 
|---|
| 56 |  | 
|---|
| 57 | /// The data itself. `list` - so that when inserted to the end, the existing iterators are not invalidated. | 
|---|
| 58 | BlocksList data; | 
|---|
| 59 |  | 
|---|
| 60 | std::mutex mutex; | 
|---|
| 61 |  | 
|---|
| 62 | protected: | 
|---|
| 63 | StorageMemory(String database_name_, String table_name_, ColumnsDescription columns_description_, ConstraintsDescription constraints_); | 
|---|
| 64 | }; | 
|---|
| 65 |  | 
|---|
| 66 | } | 
|---|
| 67 |  | 
|---|