2011-10-31 17:55:06 +00:00
|
|
|
|
#pragma once
|
|
|
|
|
|
2016-05-28 10:15:36 +00:00
|
|
|
|
#include <mutex>
|
2012-11-30 04:28:13 +00:00
|
|
|
|
|
2011-10-31 17:55:06 +00:00
|
|
|
|
#include <DB/Core/NamesAndTypes.h>
|
|
|
|
|
#include <DB/Storages/IStorage.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 StorageMemory : public IStorage
|
|
|
|
|
{
|
|
|
|
|
friend class MemoryBlockInputStream;
|
|
|
|
|
friend class MemoryBlockOutputStream;
|
|
|
|
|
|
|
|
|
|
public:
|
2014-09-30 03:08:47 +00:00
|
|
|
|
static StoragePtr create(
|
|
|
|
|
const std::string & name_,
|
|
|
|
|
NamesAndTypesListPtr columns_);
|
|
|
|
|
|
|
|
|
|
static StoragePtr create(
|
|
|
|
|
const std::string & name_,
|
|
|
|
|
NamesAndTypesListPtr columns_,
|
2014-10-03 15:30:10 +00:00
|
|
|
|
const NamesAndTypesList & materialized_columns_,
|
2014-09-30 03:08:47 +00:00
|
|
|
|
const NamesAndTypesList & alias_columns_,
|
|
|
|
|
const ColumnDefaults & column_defaults_);
|
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-10 15:45:43 +00:00
|
|
|
|
const NamesAndTypesList & getColumnsListImpl() 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,
|
2014-12-17 11:53:17 +00:00
|
|
|
|
const Context & context,
|
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
|
|
|
|
|
2015-09-10 20:43:42 +00:00
|
|
|
|
BlockOutputStreamPtr write(ASTPtr query, const Settings & settings) 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;
|
|
|
|
|
|
2016-05-28 10:15:36 +00:00
|
|
|
|
std::mutex mutex;
|
2014-10-26 00:01:36 +00:00
|
|
|
|
|
2014-09-30 03:08:47 +00:00
|
|
|
|
StorageMemory(
|
|
|
|
|
const std::string & name_,
|
|
|
|
|
NamesAndTypesListPtr columns_);
|
|
|
|
|
|
|
|
|
|
StorageMemory(
|
|
|
|
|
const std::string & name_,
|
|
|
|
|
NamesAndTypesListPtr columns_,
|
2014-10-03 15:30:10 +00:00
|
|
|
|
const NamesAndTypesList & materialized_columns_,
|
2014-09-30 03:08:47 +00:00
|
|
|
|
const NamesAndTypesList & alias_columns_,
|
|
|
|
|
const ColumnDefaults & column_defaults_);
|
2011-10-31 17:55:06 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|