2016-10-25 13:49:07 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-01-21 04:24:28 +00:00
|
|
|
#include <mutex>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Databases/IDatabase.h>
|
|
|
|
#include <Storages/IStorage.h>
|
2016-10-25 13:49:07 +00:00
|
|
|
|
|
|
|
|
2017-01-21 04:24:28 +00:00
|
|
|
namespace Poco { class Logger; }
|
|
|
|
|
|
|
|
|
2016-10-25 13:49:07 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
/** A non-persistent database to store temporary data.
|
|
|
|
* It doesn't make any manipulations with filesystem.
|
|
|
|
* All tables are created by calling code.
|
|
|
|
* TODO: Maybe DatabaseRuntime is more suitable class name.
|
|
|
|
*/
|
|
|
|
class DatabaseMemory : public IDatabase
|
|
|
|
{
|
|
|
|
protected:
|
2017-04-01 07:20:54 +00:00
|
|
|
const String name;
|
|
|
|
mutable std::mutex mutex;
|
|
|
|
Tables tables;
|
2016-10-25 13:49:07 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
Poco::Logger * log;
|
2016-10-25 13:49:07 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
DatabaseMemory(const String & name_) : name(name_) {}
|
2016-10-25 13:49:07 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
String getEngineName() const override { return "Memory"; }
|
2016-10-25 13:49:07 +00:00
|
|
|
|
2017-09-11 12:39:01 +00:00
|
|
|
void loadTables(
|
|
|
|
Context & context,
|
|
|
|
ThreadPool * thread_pool,
|
|
|
|
bool has_force_restore_data_flag) override;
|
2016-10-25 13:49:07 +00:00
|
|
|
|
2017-09-11 12:39:01 +00:00
|
|
|
bool empty(const Context & context) const override;
|
2016-10-25 13:49:07 +00:00
|
|
|
|
2017-09-11 12:39:01 +00:00
|
|
|
DatabaseIteratorPtr getIterator(const Context & context) override;
|
2016-10-25 13:49:07 +00:00
|
|
|
|
2017-09-11 12:39:01 +00:00
|
|
|
bool isTableExist(
|
|
|
|
const Context & context,
|
|
|
|
const String & table_name) const override;
|
|
|
|
|
|
|
|
StoragePtr tryGetTable(
|
|
|
|
const Context & context,
|
2018-01-30 17:47:04 +00:00
|
|
|
const String & table_name) const override;
|
2016-10-25 13:49:07 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
void createTable(
|
2017-09-11 12:39:01 +00:00
|
|
|
const Context & context,
|
|
|
|
const String & table_name,
|
|
|
|
const StoragePtr & table,
|
2017-10-25 19:52:32 +00:00
|
|
|
const ASTPtr & query) override;
|
2017-01-23 18:05:07 +00:00
|
|
|
|
2017-09-11 12:39:01 +00:00
|
|
|
void removeTable(
|
|
|
|
const Context & context,
|
|
|
|
const String & table_name) override;
|
2016-10-25 13:49:07 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
void attachTable(const String & table_name, const StoragePtr & table) override;
|
|
|
|
StoragePtr detachTable(const String & table_name) override;
|
2016-10-25 13:49:07 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
void renameTable(
|
2017-09-11 12:39:01 +00:00
|
|
|
const Context & context,
|
|
|
|
const String & table_name,
|
|
|
|
IDatabase & to_database,
|
|
|
|
const String & to_table_name) override;
|
2016-10-25 13:49:07 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
void alterTable(
|
|
|
|
const Context & context,
|
|
|
|
const String & name,
|
|
|
|
const NamesAndTypesList & columns,
|
|
|
|
const NamesAndTypesList & materialized_columns,
|
|
|
|
const NamesAndTypesList & alias_columns,
|
|
|
|
const ColumnDefaults & column_defaults,
|
|
|
|
const ASTModifier & engine_modifier) override;
|
2017-09-11 12:39:01 +00:00
|
|
|
|
|
|
|
time_t getTableMetadataModificationTime(
|
|
|
|
const Context & context,
|
|
|
|
const String & table_name) override;
|
|
|
|
|
|
|
|
ASTPtr getCreateQuery(
|
|
|
|
const Context & context,
|
|
|
|
const String & table_name) const override;
|
|
|
|
|
|
|
|
void shutdown() override;
|
|
|
|
void drop() override;
|
2016-10-25 13:49:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|