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;
|
|
|
|
|
typedef std::vector<Block> Blocks;
|
|
|
|
|
|
|
|
|
|
class MemoryBlockInputStream : public IProfilingBlockInputStream
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
MemoryBlockInputStream(const Names & column_names_, StorageMemory & storage_);
|
|
|
|
|
Block readImpl();
|
|
|
|
|
String getName() const { return "MemoryBlockInputStream"; }
|
|
|
|
|
BlockInputStreamPtr clone() { return new MemoryBlockInputStream(column_names, storage); }
|
|
|
|
|
private:
|
|
|
|
|
Names column_names;
|
|
|
|
|
StorageMemory & storage;
|
|
|
|
|
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,
|
|
|
|
|
unsigned max_threads = 1);
|
2011-10-31 17:55:06 +00:00
|
|
|
|
|
|
|
|
|
BlockOutputStreamPtr write(
|
|
|
|
|
ASTPtr query);
|
|
|
|
|
|
2011-11-05 23:31:19 +00:00
|
|
|
|
void drop();
|
|
|
|
|
|
2011-10-31 17:55:06 +00:00
|
|
|
|
private:
|
|
|
|
|
const std::string name;
|
2011-11-01 17:12:11 +00:00
|
|
|
|
NamesAndTypesListPtr columns;
|
2011-10-31 17:55:06 +00:00
|
|
|
|
|
|
|
|
|
/// Сами данные
|
|
|
|
|
Blocks data;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|