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

79 lines
2.0 KiB
C
Raw Normal View History

2011-10-31 17:55:06 +00:00
#pragma once
#include <DB/Core/NamesAndTypes.h>
#include <DB/Storages/IStorage.h>
#include <DB/DataStreams/IProfilingBlockInputStream.h>
namespace DB
{
class StorageMemory;
class MemoryBlockInputStream : public IProfilingBlockInputStream
{
public:
2012-05-30 04:45:49 +00:00
MemoryBlockInputStream(const Names & column_names_, Blocks::iterator begin_, Blocks::iterator end_);
2011-10-31 17:55:06 +00:00
Block readImpl();
String getName() const { return "MemoryBlockInputStream"; }
2012-05-30 04:45:49 +00:00
BlockInputStreamPtr clone() { return new MemoryBlockInputStream(column_names, begin, end); }
2011-10-31 17:55:06 +00:00
private:
Names column_names;
2012-05-30 04:45:49 +00:00
Blocks::iterator begin;
Blocks::iterator end;
2011-10-31 17:55:06 +00:00
Blocks::iterator it;
};
class MemoryBlockOutputStream : public IBlockOutputStream
{
public:
MemoryBlockOutputStream(StorageMemory & storage_);
void write(const Block & block);
BlockOutputStreamPtr clone() { return new MemoryBlockOutputStream(storage); }
private:
StorageMemory & storage;
};
/** Реализует хранилище в оперативке.
* Подходит для временных данных.
* В нём не поддерживаются ключи.
* Данные хранятся в виде набора блоков и никуда дополнительно не сохраняются.
*/
class StorageMemory : public IStorage
{
friend class MemoryBlockInputStream;
friend class MemoryBlockOutputStream;
public:
2011-11-01 17:12:11 +00:00
StorageMemory(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,
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);
2011-11-05 23:31:19 +00:00
void drop();
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
/// Сами данные
Blocks data;
};
}