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>
|
2014-03-19 10:45:13 +00:00
|
|
|
|
#include <DB/DataStreams/IBlockOutputStream.h>
|
2011-10-31 17:55:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
class StorageMemory;
|
|
|
|
|
|
|
|
|
|
class MemoryBlockInputStream : public IProfilingBlockInputStream
|
|
|
|
|
{
|
|
|
|
|
public:
|
2014-03-19 10:45: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"; }
|
2013-05-03 10:20:53 +00:00
|
|
|
|
|
|
|
|
|
String getID() const
|
|
|
|
|
{
|
|
|
|
|
std::stringstream res;
|
2014-03-19 10:45:13 +00:00
|
|
|
|
res << "Memory(" << &*begin << ", " << &*end;
|
2013-05-03 10:20:53 +00:00
|
|
|
|
|
2014-10-26 00:01:36 +00:00
|
|
|
|
for (const auto & name : column_names)
|
|
|
|
|
res << ", " << name;
|
2013-05-03 10:20:53 +00:00
|
|
|
|
|
|
|
|
|
res << ")";
|
|
|
|
|
return res.str();
|
|
|
|
|
}
|
2014-10-26 00:01:36 +00:00
|
|
|
|
|
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:
|
2014-03-19 10:45:13 +00:00
|
|
|
|
MemoryBlockOutputStream(StorageMemory & storage_);
|
2011-10-31 17:55:06 +00:00
|
|
|
|
void write(const Block & block);
|
|
|
|
|
private:
|
|
|
|
|
StorageMemory & storage;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Реализует хранилище в оперативке.
|
|
|
|
|
* Подходит для временных данных.
|
|
|
|
|
* В нём не поддерживаются ключи.
|
|
|
|
|
* Данные хранятся в виде набора блоков и никуда дополнительно не сохраняются.
|
|
|
|
|
*/
|
|
|
|
|
class StorageMemory : public IStorage
|
|
|
|
|
{
|
|
|
|
|
friend class MemoryBlockInputStream;
|
|
|
|
|
friend class MemoryBlockOutputStream;
|
|
|
|
|
|
|
|
|
|
public:
|
2013-02-06 11:26:35 +00:00
|
|
|
|
static StoragePtr create(const std::string & name_, NamesAndTypesListPtr columns_);
|
2011-10-31 17:55:06 +00:00
|
|
|
|
|
2014-10-03 17:55:36 +00:00
|
|
|
|
std::string getName() const override { return "Memory"; }
|
|
|
|
|
std::string getTableName() const override { return name; }
|
2011-10-31 17:55:06 +00:00
|
|
|
|
|
2014-10-03 17:55:36 +00:00
|
|
|
|
const NamesAndTypesList & getColumnsList() const override { return *columns; }
|
2011-10-31 17:55:06 +00:00
|
|
|
|
|
2014-03-19 15:07:29 +00:00
|
|
|
|
size_t getSize() const { return data.size(); }
|
|
|
|
|
|
2012-01-09 19:20:48 +00:00
|
|
|
|
BlockInputStreams read(
|
2011-10-31 17:55:06 +00:00
|
|
|
|
const Names & column_names,
|
|
|
|
|
ASTPtr query,
|
2013-02-01 19:02:04 +00:00
|
|
|
|
const Settings & settings,
|
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,
|
2014-10-03 17:55:36 +00:00
|
|
|
|
unsigned threads = 1) override;
|
2011-10-31 17:55:06 +00:00
|
|
|
|
|
2014-10-03 17:55:36 +00:00
|
|
|
|
BlockOutputStreamPtr write(ASTPtr query) override;
|
2011-10-31 17:55:06 +00:00
|
|
|
|
|
2014-03-20 13:28:49 +00:00
|
|
|
|
void drop() override;
|
2014-10-03 17:55:36 +00:00
|
|
|
|
void rename(const String & new_path_to_db, const String & new_database_name, const String & new_table_name) override { name = new_table_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;
|
2014-10-26 00:01:36 +00:00
|
|
|
|
|
2013-02-06 11:26:35 +00:00
|
|
|
|
StorageMemory(const std::string & name_, NamesAndTypesListPtr columns_);
|
2011-10-31 17:55:06 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|