StorageMemory.cpp 1.3 KB
Newer Older
A
Alexey Milovidov 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
#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);
}


A
Alexey Milovidov 已提交
43
StorageMemory::StorageMemory(const std::string & name_, NamesAndTypesListPtr columns_)
A
Alexey Milovidov 已提交
44 45 46 47 48
	: name(name_), columns(columns_)
{
}


49
BlockInputStreams StorageMemory::read(
A
Alexey Milovidov 已提交
50 51
	const Names & column_names,
	ASTPtr query,
52
	QueryProcessingStage::Enum & processed_stage,
53 54
	size_t max_block_size,
	unsigned max_threads)
A
Alexey Milovidov 已提交
55 56
{
	check(column_names);
57
	processed_stage = QueryProcessingStage::FetchColumns;
58
	return BlockInputStreams(1, new MemoryBlockInputStream(column_names, *this));
A
Alexey Milovidov 已提交
59 60 61 62 63 64 65 66 67
}

	
BlockOutputStreamPtr StorageMemory::write(
	ASTPtr query)
{
	return new MemoryBlockOutputStream(*this);
}

A
Alexey Milovidov 已提交
68 69 70 71 72 73

void StorageMemory::drop()
{
	data.clear();
}

A
Alexey Milovidov 已提交
74
}