ClickHouse/src/Databases/DatabaseMemory.h

57 lines
1.9 KiB
C++
Raw Normal View History

#pragma once
#include <Databases/DatabasesCommon.h>
2020-01-20 20:08:47 +00:00
#include <Common/escapeForFileName.h>
#include <Parsers/ASTCreateQuery.h>
namespace Poco { class Logger; }
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 final : public DatabaseWithOwnTablesBase
{
public:
2020-04-13 14:09:56 +00:00
DatabaseMemory(const String & name_, const Context & global_context_);
String getEngineName() const override { return "Memory"; }
void createTable(
const Context & context,
const String & table_name,
const StoragePtr & table,
const ASTPtr & query) override;
2020-01-22 11:30:11 +00:00
void dropTable(
const Context & 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;
2020-01-30 12:51:47 +00:00
ASTPtr getCreateTableQueryImpl(const Context & /*context*/, const String & name, bool throw_on_error) const override;
ASTPtr getCreateDatabaseQuery(const Context & /*context*/) 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;
2020-01-20 20:08:47 +00:00
private:
2020-04-13 14:09:56 +00:00
const Context & global_context;
2020-01-20 20:08:47 +00:00
String data_path;
2020-01-30 12:51:47 +00:00
using NameToASTCreate = std::unordered_map<String, ASTPtr>;
NameToASTCreate create_queries;
};
}