2016-10-25 13:49:07 +00:00
|
|
|
#pragma once
|
|
|
|
|
2018-03-23 20:46:43 +00:00
|
|
|
#include <Databases/DatabasesCommon.h>
|
2020-01-20 20:08:47 +00:00
|
|
|
#include <Common/escapeForFileName.h>
|
|
|
|
#include <Parsers/ASTCreateQuery.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.
|
|
|
|
*/
|
2020-03-19 23:48:53 +00:00
|
|
|
class DatabaseMemory final : public DatabaseWithOwnTablesBase
|
2016-10-25 13:49:07 +00:00
|
|
|
{
|
|
|
|
public:
|
2021-04-10 23:33:54 +00:00
|
|
|
DatabaseMemory(const String & name_, ContextPtr context);
|
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-04-01 07:20:54 +00:00
|
|
|
void createTable(
|
2021-04-10 23:33:54 +00:00
|
|
|
ContextPtr context,
|
2017-09-11 12:39:01 +00:00
|
|
|
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
|
|
|
|
2020-01-22 11:30:11 +00:00
|
|
|
void dropTable(
|
2021-04-10 23:33:54 +00:00
|
|
|
ContextPtr context,
|
2020-03-20 00:07:52 +00:00
|
|
|
const String & table_name,
|
2020-03-20 12:45:06 +00:00
|
|
|
bool no_delay) override;
|
2016-10-25 13:49:07 +00:00
|
|
|
|
2021-04-10 23:33:54 +00:00
|
|
|
ASTPtr getCreateTableQueryImpl(const String & name, ContextPtr context, bool throw_on_error) const override;
|
2020-04-23 16:51:48 +00:00
|
|
|
ASTPtr getCreateDatabaseQuery() const override;
|
2020-01-20 20:08:47 +00:00
|
|
|
|
|
|
|
/// DatabaseMemory allows to create tables, which store data on disk.
|
|
|
|
/// It's needed to create such tables in default database of clickhouse-local.
|
|
|
|
/// TODO May be it's better to use DiskMemory for such tables.
|
|
|
|
/// To save data on disk it's possible to explicitly CREATE DATABASE db ENGINE=Ordinary in clickhouse-local.
|
|
|
|
String getTableDataPath(const String & table_name) const override { return data_path + escapeForFileName(table_name) + "/"; }
|
|
|
|
String getTableDataPath(const ASTCreateQuery & query) const override { return getTableDataPath(query.table); }
|
|
|
|
|
2020-04-13 14:09:56 +00:00
|
|
|
UUID tryGetTableUUID(const String & table_name) const override;
|
|
|
|
|
2021-04-10 23:33:54 +00:00
|
|
|
void drop(ContextPtr context) override;
|
2020-05-18 13:51:01 +00:00
|
|
|
|
2020-01-20 20:08:47 +00:00
|
|
|
private:
|
|
|
|
String data_path;
|
2020-01-30 12:51:47 +00:00
|
|
|
using NameToASTCreate = std::unordered_map<String, ASTPtr>;
|
|
|
|
NameToASTCreate create_queries;
|
2016-10-25 13:49:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|