2011-10-31 17:55:06 +00:00
|
|
|
|
#pragma once
|
|
|
|
|
|
2012-11-30 04:28:13 +00:00
|
|
|
|
#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:
|
2012-11-30 04:28:13 +00:00
|
|
|
|
MemoryBlockInputStream(const Names & column_names_, BlocksList::iterator begin_, BlocksList::iterator end_);
|
2011-10-31 17:55:06 +00:00
|
|
|
|
String getName() const { return "MemoryBlockInputStream"; }
|
2012-05-30 04:45:49 +00:00
|
|
|
|
BlockInputStreamPtr clone() { return new MemoryBlockInputStream(column_names, begin, end); }
|
2012-10-20 02:10:47 +00:00
|
|
|
|
protected:
|
|
|
|
|
Block readImpl();
|
2011-10-31 17:55:06 +00:00
|
|
|
|
private:
|
|
|
|
|
Names column_names;
|
2012-11-30 04:28:13 +00:00
|
|
|
|
BlocksList::iterator begin;
|
|
|
|
|
BlocksList::iterator end;
|
|
|
|
|
BlocksList::iterator it;
|
2011-10-31 17:55:06 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2012-11-30 04:28:13 +00:00
|
|
|
|
/// Сами данные. list - чтобы при вставке в конец, существующие итераторы не инвалидировались.
|
|
|
|
|
BlocksList data;
|
|
|
|
|
|
|
|
|
|
Poco::FastMutex mutex;
|
2011-10-31 17:55:06 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|