ClickHouse/dbms/Databases/DatabaseOnDisk.h

86 lines
2.9 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-25 13:58:15 +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)
: DatabaseWithOwnTablesBase(name, logger)
, metadata_path(metadata_path_)
, data_path("data/" + escapeForFileName(database_name) + "/") {}
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
void removeTable(
2019-10-10 17:33:01 +00:00
const Context & context,
const String & table_name) 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,
const String & to_table_name,
TableStructureWriteLockHolder & lock) 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
protected:
2019-10-03 08:27:43 +00:00
using IteratingFunction = std::function<void(const String &)>;
void iterateMetadataFiles(const Context & context, const IteratingFunction & iterating_function) 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 parseQueryFromMetadata(const Context & context, const String & metadata_file_path, bool throw_on_error = true, bool remove_empty = false) const;
ASTPtr getCreateQueryFromMetadata(const Context & context, const String & metadata_path, bool throw_on_error) const;
2019-10-03 07:59:48 +00:00
const String metadata_path;
const String data_path;
};
2019-10-03 07:59:48 +00:00
2019-10-02 10:10:45 +00:00
}