2011-10-31 17:30:44 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Storages/IStorage.h>
|
2017-07-10 04:34:14 +00:00
|
|
|
#include <ext/singleton.h>
|
2017-12-28 21:36:27 +00:00
|
|
|
#include <unordered_map>
|
2011-10-31 17:30:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2012-05-22 19:32:56 +00:00
|
|
|
class Context;
|
2017-12-30 00:36:06 +00:00
|
|
|
class ASTCreateQuery;
|
|
|
|
class ASTStorage;
|
2011-10-31 17:30:44 +00:00
|
|
|
|
|
|
|
|
2017-12-30 00:36:06 +00:00
|
|
|
/** Allows to create a table by the name and parameters of the engine.
|
2018-03-06 20:18:34 +00:00
|
|
|
* In 'columns' Nested data structures must be flattened.
|
2017-06-06 17:06:14 +00:00
|
|
|
* You should subsequently call IStorage::startup method to work with table.
|
2011-10-31 17:30:44 +00:00
|
|
|
*/
|
2017-07-10 04:34:14 +00:00
|
|
|
class StorageFactory : public ext::singleton<StorageFactory>
|
2011-10-31 17:30:44 +00:00
|
|
|
{
|
|
|
|
public:
|
2017-12-28 21:36:27 +00:00
|
|
|
struct Arguments
|
|
|
|
{
|
2017-12-30 00:36:06 +00:00
|
|
|
const String & engine_name;
|
|
|
|
ASTs & engine_args;
|
|
|
|
ASTStorage * storage_def;
|
|
|
|
const ASTCreateQuery & query;
|
2017-12-28 21:36:27 +00:00
|
|
|
const String & data_path;
|
|
|
|
const String & table_name;
|
|
|
|
const String & database_name;
|
|
|
|
Context & local_context;
|
|
|
|
Context & context;
|
2018-03-06 20:18:34 +00:00
|
|
|
const ColumnsDescription & columns;
|
2017-12-28 21:36:27 +00:00
|
|
|
bool attach;
|
|
|
|
bool has_force_restore_data_flag;
|
|
|
|
};
|
|
|
|
|
|
|
|
using Creator = std::function<StoragePtr(const Arguments & arguments)>;
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
StoragePtr get(
|
2017-10-25 19:52:32 +00:00
|
|
|
ASTCreateQuery & query,
|
2017-04-01 07:20:54 +00:00
|
|
|
const String & data_path,
|
|
|
|
const String & table_name,
|
|
|
|
const String & database_name,
|
|
|
|
Context & local_context,
|
|
|
|
Context & context,
|
2018-03-06 20:18:34 +00:00
|
|
|
const ColumnsDescription & columns,
|
2017-04-01 07:20:54 +00:00
|
|
|
bool attach,
|
|
|
|
bool has_force_restore_data_flag) const;
|
2017-12-28 21:36:27 +00:00
|
|
|
|
2017-12-30 04:03:30 +00:00
|
|
|
/// Register a table engine by its name.
|
|
|
|
/// No locking, you must register all engines before usage of get.
|
2017-12-28 21:36:27 +00:00
|
|
|
void registerStorage(const std::string & name, Creator creator);
|
|
|
|
|
|
|
|
private:
|
|
|
|
using Storages = std::unordered_map<std::string, Creator>;
|
|
|
|
Storages storages;
|
2011-10-31 17:30:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|