2011-10-31 17:55:06 +00:00
|
|
|
#include <map>
|
|
|
|
|
|
|
|
#include <DB/Core/Exception.h>
|
|
|
|
#include <DB/Core/ErrorCodes.h>
|
|
|
|
|
|
|
|
#include <DB/Storages/StorageMemory.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
using Poco::SharedPtr;
|
|
|
|
|
|
|
|
|
|
|
|
MemoryBlockInputStream::MemoryBlockInputStream(const Names & column_names_, StorageMemory & storage_)
|
|
|
|
: column_names(column_names_), storage(storage_), it(storage.data.begin())
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Block MemoryBlockInputStream::readImpl()
|
|
|
|
{
|
|
|
|
if (it == storage.data.end())
|
|
|
|
return Block();
|
|
|
|
else
|
|
|
|
return *it++;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MemoryBlockOutputStream::MemoryBlockOutputStream(StorageMemory & storage_)
|
|
|
|
: storage(storage_)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MemoryBlockOutputStream::write(const Block & block)
|
|
|
|
{
|
|
|
|
storage.check(block);
|
|
|
|
storage.data.push_back(block);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-01 17:12:11 +00:00
|
|
|
StorageMemory::StorageMemory(const std::string & name_, NamesAndTypesListPtr columns_)
|
2011-10-31 17:55:06 +00:00
|
|
|
: name(name_), columns(columns_)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-09 19:20:48 +00:00
|
|
|
BlockInputStreams StorageMemory::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,
|
|
|
|
unsigned max_threads)
|
2011-10-31 17:55:06 +00:00
|
|
|
{
|
|
|
|
check(column_names);
|
2012-05-22 18:32:45 +00:00
|
|
|
processed_stage = QueryProcessingStage::FetchColumns;
|
2012-01-09 19:20:48 +00:00
|
|
|
return BlockInputStreams(1, new MemoryBlockInputStream(column_names, *this));
|
2011-10-31 17:55:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BlockOutputStreamPtr StorageMemory::write(
|
|
|
|
ASTPtr query)
|
|
|
|
{
|
|
|
|
return new MemoryBlockOutputStream(*this);
|
|
|
|
}
|
|
|
|
|
2011-11-05 23:31:19 +00:00
|
|
|
|
|
|
|
void StorageMemory::drop()
|
|
|
|
{
|
|
|
|
data.clear();
|
|
|
|
}
|
|
|
|
|
2011-10-31 17:55:06 +00:00
|
|
|
}
|