ClickHouse/dbms/src/Storages/StorageMemory.h

60 lines
1.6 KiB
C++
Raw Normal View History

2011-10-31 17:55:06 +00:00
#pragma once
#include <mutex>
2017-06-06 17:18:32 +00:00
#include <ext/shared_ptr_helper.h>
#include <Core/NamesAndTypes.h>
#include <Storages/IStorage.h>
#include <DataStreams/IBlockOutputStream.h>
2011-10-31 17:55:06 +00:00
namespace DB
{
2017-04-16 15:00:33 +00:00
/** Implements storage in the RAM.
* Suitable for temporary data.
* It does not support keys.
* Data is stored as a set of blocks and is not stored anywhere else.
2011-10-31 17:55:06 +00:00
*/
class StorageMemory : public ext::shared_ptr_helper<StorageMemory>, public IStorage
2011-10-31 17:55:06 +00:00
{
friend class MemoryBlockInputStream;
friend class MemoryBlockOutputStream;
public:
std::string getName() const override { return "Memory"; }
std::string getTableName() const override { return table_name; }
2011-10-31 17:55:06 +00:00
size_t getSize() const { return data.size(); }
BlockInputStreams read(
const Names & column_names,
const SelectQueryInfo & query_info,
const Context & context,
QueryProcessingStage::Enum processed_stage,
2017-06-02 15:54:39 +00:00
size_t max_block_size,
unsigned num_streams) override;
2011-10-31 17:55:06 +00:00
2017-05-21 22:25:25 +00:00
BlockOutputStreamPtr write(const ASTPtr & query, const Settings & settings) override;
2011-10-31 17:55:06 +00:00
void drop() override;
2018-04-21 00:35:20 +00:00
2018-06-09 15:48:22 +00:00
void truncate(const ASTPtr &) override;
2018-04-21 00:35:20 +00:00
void rename(const String & /*new_path_to_db*/, const String & /*new_database_name*/, const String & new_table_name) override { table_name = new_table_name; }
2011-11-05 23:31:19 +00:00
2011-10-31 17:55:06 +00:00
private:
String table_name;
2011-10-31 17:55:06 +00:00
2017-04-16 15:00:33 +00:00
/// The data itself. `list` - so that when inserted to the end, the existing iterators are not invalidated.
BlocksList data;
std::mutex mutex;
protected:
StorageMemory(String table_name_, ColumnsDescription columns_description_);
2011-10-31 17:55:06 +00:00
};
}