ClickHouse/dbms/Databases/DatabaseOnDisk.h

98 lines
3.6 KiB
C++
Raw Normal View History

2019-10-02 10:10:45 +00:00
#pragma once
2019-10-03 09:31:59 +00:00
#include <Common/escapeForFileName.h>
#include <Common/quoteString.h>
2019-10-02 10:10:45 +00:00
#include <Databases/DatabasesCommon.h>
2019-10-03 09:31:59 +00:00
#include <Interpreters/Context.h>
2019-10-03 07:59:48 +00:00
#include <Parsers/ASTCreateQuery.h>
#include <Storages/IStorage.h>
2019-10-02 10:10:45 +00:00
namespace DB
{
2019-10-10 17:33:01 +00:00
std::pair<String, StoragePtr> createTableFromAST(
ASTCreateQuery ast_create_query,
const String & database_name,
2019-11-01 12:47:55 +00:00
const String & table_data_path_relative,
2019-10-10 17:33:01 +00:00
Context & context,
bool has_force_restore_data_flag);
2019-12-02 19:11:18 +00:00
/** Get the string with the table definition based on the CREATE query.
2019-10-10 17:33:01 +00:00
* It is an ATTACH query that you can execute to create a table from the correspondent database.
* See the implementation.
*/
String getObjectDefinitionFromCreateQuery(const ASTPtr & query);
2019-10-08 00:24:26 +00:00
/* Class to provide basic operations with tables when metadata is stored on disk in .sql files.
2019-10-03 07:59:48 +00:00
*/
class DatabaseOnDisk : public DatabaseWithOwnTablesBase
2019-10-02 10:10:45 +00:00
{
public:
DatabaseOnDisk(const String & name, const String & metadata_path_, const String & logger, const Context & context);
2019-10-10 17:33:01 +00:00
void createTable(
2019-10-02 10:10:45 +00:00
const Context & context,
2019-10-03 07:59:48 +00:00
const String & table_name,
const StoragePtr & table,
const ASTPtr & query) override;
2019-10-02 10:10:45 +00:00
2020-01-22 11:30:11 +00:00
void dropTable(
2019-10-10 17:33:01 +00:00
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;
2019-10-10 17:33:01 +00:00
void renameTable(
2019-10-02 10:10:45 +00:00
const Context & context,
const String & table_name,
IDatabase & to_database,
2020-03-31 20:38:05 +00:00
const String & to_table_name,
bool exchange) override;
2019-10-02 10:10:45 +00:00
ASTPtr getCreateDatabaseQuery(const Context & context) const override;
2019-10-02 10:10:45 +00:00
void drop(const Context & context) override;
2019-10-02 10:10:45 +00:00
String getObjectMetadataPath(const String & object_name) const override;
2019-10-02 10:10:45 +00:00
time_t getObjectMetadataModificationTime(const String & object_name) const override;
2019-10-03 08:35:58 +00:00
String getDataPath() const override { return data_path; }
2019-12-25 16:13:48 +00:00
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); }
String getMetadataPath() const override { return metadata_path; }
2019-10-03 08:35:58 +00:00
2020-03-19 21:14:52 +00:00
static ASTPtr parseQueryFromMetadata(Poco::Logger * log, const Context & context, const String & metadata_file_path, bool throw_on_error = true, bool remove_empty = false);
protected:
2020-01-22 11:30:11 +00:00
static constexpr const char * create_suffix = ".tmp";
static constexpr const char * drop_suffix = ".tmp_drop";
2019-10-03 08:27:43 +00:00
using IteratingFunction = std::function<void(const String &)>;
2020-01-23 19:10:09 +00:00
void iterateMetadataFiles(const Context & context, const IteratingFunction & process_metadata_file) const;
void iterateMetadataFiles(const Context & context, const IteratingFunction & process_metadata_file,
const IteratingFunction & process_tmp_drop_metadata_file) const;
2019-10-03 08:27:43 +00:00
ASTPtr getCreateTableQueryImpl(
2019-10-03 07:59:48 +00:00
const Context & context,
const String & table_name,
bool throw_on_error) const override;
2019-10-10 17:33:01 +00:00
ASTPtr getCreateQueryFromMetadata(const Context & context, const String & metadata_path, bool throw_on_error) const;
2019-10-03 07:59:48 +00:00
2020-03-23 00:12:13 +00:00
virtual void commitAlterTable(const StorageID & table_id, const String & table_metadata_tmp_path, const String & table_metadata_path);
virtual void commitCreateTable(const ASTCreateQuery & query, const StoragePtr & table,
const String & table_metadata_tmp_path, const String & table_metadata_path);
2020-01-23 19:10:09 +00:00
2020-01-22 11:30:11 +00:00
//bool detachTableAndRemoveMetadata(const String & table_name);
//void replaceMetadata(const ASTPtr & create, );
2019-10-03 07:59:48 +00:00
const String metadata_path;
2019-11-11 11:34:03 +00:00
/*const*/ String data_path;
2020-04-01 22:41:29 +00:00
const Context & global_context;
};
2019-10-03 07:59:48 +00:00
2019-10-02 10:10:45 +00:00
}