2011-10-31 17:30:44 +00:00
|
|
|
#pragma once
|
|
|
|
|
2019-04-03 11:13:22 +00:00
|
|
|
#include <Common/NamePrompter.h>
|
2019-05-17 14:34:25 +00:00
|
|
|
#include <Parsers/IAST_fwd.h>
|
|
|
|
#include <Storages/ColumnsDescription.h>
|
2019-08-24 21:20:20 +00:00
|
|
|
#include <Storages/ConstraintsDescription.h>
|
2019-05-17 14:34:25 +00:00
|
|
|
#include <Storages/IStorage_fwd.h>
|
2019-12-15 06:34:43 +00:00
|
|
|
#include <Storages/registerStorages.h>
|
2020-04-06 05:19:40 +00:00
|
|
|
#include <Access/AccessType.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;
|
2019-12-04 16:06:55 +00:00
|
|
|
struct StorageID;
|
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
|
|
|
*/
|
2019-08-22 03:24:05 +00:00
|
|
|
class StorageFactory : private boost::noncopyable, public IHints<1, StorageFactory>
|
2011-10-31 17:30:44 +00:00
|
|
|
{
|
|
|
|
public:
|
2019-08-22 03:24:05 +00:00
|
|
|
|
|
|
|
static StorageFactory & instance();
|
|
|
|
|
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;
|
2019-10-25 19:07:47 +00:00
|
|
|
/// Path to table data.
|
|
|
|
/// Relative to <path> from server config (possibly <path> of some <disk> of some <volume> for *MergeTree)
|
|
|
|
const String & relative_data_path;
|
2019-12-04 16:06:55 +00:00
|
|
|
const StorageID & table_id;
|
2017-12-28 21:36:27 +00:00
|
|
|
Context & local_context;
|
|
|
|
Context & context;
|
2018-03-06 20:18:34 +00:00
|
|
|
const ColumnsDescription & columns;
|
2019-08-24 21:20:20 +00:00
|
|
|
const ConstraintsDescription & constraints;
|
2017-12-28 21:36:27 +00:00
|
|
|
bool attach;
|
|
|
|
bool has_force_restore_data_flag;
|
|
|
|
};
|
|
|
|
|
2020-01-25 19:14:33 +00:00
|
|
|
struct StorageFeatures
|
|
|
|
{
|
|
|
|
bool supports_settings = false;
|
|
|
|
bool supports_skipping_indices = false;
|
|
|
|
bool supports_sort_order = false;
|
|
|
|
bool supports_ttl = false;
|
2020-01-27 14:14:49 +00:00
|
|
|
bool supports_replication = false;
|
|
|
|
bool supports_deduplication = false;
|
2020-04-06 05:19:40 +00:00
|
|
|
AccessType source_access_type = AccessType::NONE;
|
2020-01-25 19:14:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
using CreatorFn = std::function<StoragePtr(const Arguments & arguments)>;
|
|
|
|
struct Creator
|
|
|
|
{
|
|
|
|
CreatorFn creator_fn;
|
|
|
|
StorageFeatures features;
|
|
|
|
};
|
|
|
|
|
|
|
|
using Storages = std::unordered_map<std::string, Creator>;
|
2017-12-28 21:36:27 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
StoragePtr get(
|
2019-12-16 18:10:35 +00:00
|
|
|
const ASTCreateQuery & query,
|
2019-10-25 19:07:47 +00:00
|
|
|
const String & relative_data_path,
|
2017-04-01 07:20:54 +00:00
|
|
|
Context & local_context,
|
|
|
|
Context & context,
|
2018-03-06 20:18:34 +00:00
|
|
|
const ColumnsDescription & columns,
|
2019-08-24 21:20:20 +00:00
|
|
|
const ConstraintsDescription & constraints,
|
2017-04-01 07:20:54 +00:00
|
|
|
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.
|
2020-01-25 19:14:33 +00:00
|
|
|
void registerStorage(const std::string & name, CreatorFn creator_fn, StorageFeatures features = StorageFeatures{
|
|
|
|
.supports_settings = false,
|
|
|
|
.supports_skipping_indices = false,
|
|
|
|
.supports_sort_order = false,
|
|
|
|
.supports_ttl = false,
|
2020-01-27 14:14:49 +00:00
|
|
|
.supports_replication = false,
|
|
|
|
.supports_deduplication = false,
|
2020-04-06 05:19:40 +00:00
|
|
|
.source_access_type = AccessType::NONE,
|
2020-01-25 19:14:33 +00:00
|
|
|
});
|
2017-12-28 21:36:27 +00:00
|
|
|
|
2020-01-25 19:14:33 +00:00
|
|
|
const Storages & getAllStorages() const
|
2018-07-25 16:08:23 +00:00
|
|
|
{
|
|
|
|
return storages;
|
|
|
|
}
|
|
|
|
|
2019-04-03 11:13:22 +00:00
|
|
|
std::vector<String> getAllRegisteredNames() const override
|
|
|
|
{
|
|
|
|
std::vector<String> result;
|
|
|
|
auto getter = [](const auto & pair) { return pair.first; };
|
|
|
|
std::transform(storages.begin(), storages.end(), std::back_inserter(result), getter);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-01-25 19:14:33 +00:00
|
|
|
using FeatureMatcherFn = std::function<bool(StorageFeatures)>;
|
|
|
|
std::vector<String> getAllRegisteredNamesByFeatureMatcherFn(FeatureMatcherFn feature_matcher_fn) const
|
|
|
|
{
|
|
|
|
std::vector<String> result;
|
|
|
|
for (const auto& pair : storages)
|
|
|
|
if (feature_matcher_fn(pair.second.features))
|
|
|
|
result.push_back(pair.first);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-04-06 05:19:40 +00:00
|
|
|
AccessType getSourceAccessType(const String & table_engine) const;
|
2020-01-25 19:14:33 +00:00
|
|
|
|
2017-12-28 21:36:27 +00:00
|
|
|
private:
|
|
|
|
Storages storages;
|
2011-10-31 17:30:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|