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
|
|
|
|
2017-06-06 17:18:32 +00:00
|
|
|
#include <ext/shared_ptr_helper.h>
|
2016-08-26 21:25:05 +00:00
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Core/NamesAndTypes.h>
|
|
|
|
#include <Storages/IStorage.h>
|
|
|
|
#include <DataStreams/IBlockOutputStream.h>
|
2011-10-31 17:55:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2017-04-16 15:00:33 +00:00
|
|
|
/** Implements storage in the RAM.
|
|
|
|
* Suitable for temporary data.
|
|
|
|
* It does not support keys.
|
|
|
|
* Data is stored as a set of blocks and is not stored anywhere else.
|
2011-10-31 17:55:06 +00:00
|
|
|
*/
|
2017-06-06 18:36:13 +00:00
|
|
|
class StorageMemory : public ext::shared_ptr_helper<StorageMemory>, public IStorage
|
2011-10-31 17:55:06 +00:00
|
|
|
{
|
|
|
|
friend class MemoryBlockInputStream;
|
|
|
|
friend class MemoryBlockOutputStream;
|
|
|
|
|
|
|
|
public:
|
2017-04-01 07:20:54 +00:00
|
|
|
std::string getName() const override { return "Memory"; }
|
|
|
|
std::string getTableName() const override { return name; }
|
2011-10-31 17:55:06 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
size_t getSize() const { return data.size(); }
|
2014-03-19 15:07:29 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
BlockInputStreams read(
|
|
|
|
const Names & column_names,
|
2017-07-15 03:48:36 +00:00
|
|
|
const SelectQueryInfo & query_info,
|
2017-04-01 07:20:54 +00:00
|
|
|
const Context & context,
|
|
|
|
QueryProcessingStage::Enum & processed_stage,
|
2017-06-02 15:54:39 +00:00
|
|
|
size_t max_block_size,
|
|
|
|
unsigned num_streams) override;
|
2011-10-31 17:55:06 +00:00
|
|
|
|
2017-05-21 22:25:25 +00:00
|
|
|
BlockOutputStreamPtr write(const ASTPtr & query, const Settings & settings) override;
|
2011-10-31 17:55:06 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
void drop() override;
|
2017-12-01 21:13:25 +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:
|
2017-04-01 07:20:54 +00:00
|
|
|
String name;
|
2011-10-31 17:55:06 +00:00
|
|
|
|
2017-04-16 15:00:33 +00:00
|
|
|
/// The data itself. `list` - so that when inserted to the end, the existing iterators are not invalidated.
|
2017-04-01 07:20:54 +00:00
|
|
|
BlocksList data;
|
2012-11-30 04:28:13 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
std::mutex mutex;
|
2014-10-26 00:01:36 +00:00
|
|
|
|
2017-11-04 03:20:18 +00:00
|
|
|
protected:
|
2017-04-01 07:20:54 +00:00
|
|
|
StorageMemory(
|
|
|
|
const std::string & name_,
|
2017-12-25 21:57:29 +00:00
|
|
|
const NamesAndTypesList & columns_,
|
|
|
|
const NamesAndTypesList & materialized_columns_,
|
|
|
|
const NamesAndTypesList & alias_columns_,
|
2017-04-01 07:20:54 +00:00
|
|
|
const ColumnDefaults & column_defaults_);
|
2011-10-31 17:55:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|