ClickHouse/dbms/include/DB/Storages/StorageMemory.h

87 lines
2.4 KiB
C
Raw Normal View History

2011-10-31 17:55:06 +00:00
#pragma once
#include <Poco/Mutex.h>
2011-10-31 17:55:06 +00:00
#include <DB/Core/NamesAndTypes.h>
#include <DB/Storages/IStorage.h>
#include <DB/DataStreams/IProfilingBlockInputStream.h>
namespace DB
{
class StorageMemory;
class MemoryBlockInputStream : public IProfilingBlockInputStream
{
public:
MemoryBlockInputStream(const Names & column_names_, BlocksList::iterator begin_, BlocksList::iterator end_, StoragePtr owned_storage);
2011-10-31 17:55:06 +00:00
String getName() const { return "MemoryBlockInputStream"; }
BlockInputStreamPtr clone() { return new MemoryBlockInputStream(column_names, begin, end, owned_storage); }
2012-10-20 02:10:47 +00:00
protected:
Block readImpl();
2011-10-31 17:55:06 +00:00
private:
Names column_names;
BlocksList::iterator begin;
BlocksList::iterator end;
BlocksList::iterator it;
2011-10-31 17:55:06 +00:00
};
class MemoryBlockOutputStream : public IBlockOutputStream
{
public:
MemoryBlockOutputStream(StoragePtr owned_storage);
2011-10-31 17:55:06 +00:00
void write(const Block & block);
BlockOutputStreamPtr clone() { return new MemoryBlockOutputStream(owned_storage); }
2011-10-31 17:55:06 +00:00
private:
StorageMemory & storage;
};
/** Реализует хранилище в оперативке.
* Подходит для временных данных.
* В нём не поддерживаются ключи.
* Данные хранятся в виде набора блоков и никуда дополнительно не сохраняются.
*/
class StorageMemory : public IStorage
{
friend class MemoryBlockInputStream;
friend class MemoryBlockOutputStream;
public:
static StoragePtr create(const std::string & name_, NamesAndTypesListPtr columns_);
2011-10-31 17:55:06 +00:00
std::string getName() const { return "Memory"; }
std::string getTableName() const { return name; }
2011-11-01 17:12:11 +00:00
const NamesAndTypesList & getColumnsList() const { return *columns; }
2011-10-31 17:55:06 +00:00
2012-01-09 19:20:48 +00:00
BlockInputStreams read(
2011-10-31 17:55:06 +00:00
const Names & column_names,
ASTPtr query,
const Settings & settings,
2012-05-22 18:32:45 +00:00
QueryProcessingStage::Enum & processed_stage,
2012-01-09 19:20:48 +00:00
size_t max_block_size = DEFAULT_BLOCK_SIZE,
2012-05-30 04:45:49 +00:00
unsigned threads = 1);
2011-10-31 17:55:06 +00:00
BlockOutputStreamPtr write(
ASTPtr query);
void dropImpl();
2012-06-18 06:19:13 +00:00
void rename(const String & new_path_to_db, const String & new_name) { name = new_name; }
2011-11-05 23:31:19 +00:00
2011-10-31 17:55:06 +00:00
private:
2012-06-18 06:19:13 +00:00
String name;
2011-11-01 17:12:11 +00:00
NamesAndTypesListPtr columns;
2011-10-31 17:55:06 +00:00
/// Сами данные. list - чтобы при вставке в конец, существующие итераторы не инвалидировались.
BlocksList data;
Poco::FastMutex mutex;
StorageMemory(const std::string & name_, NamesAndTypesListPtr columns_);
2011-10-31 17:55:06 +00:00
};
}