2021-09-01 17:59:11 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Parsers/ASTIdentifier.h>
|
|
|
|
#include <Interpreters/Context.h>
|
|
|
|
#include <Poco/Util/AbstractConfiguration.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace ExternalDataSource
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
struct ExternalDataSourceConfiguration
|
|
|
|
{
|
|
|
|
String host;
|
2021-09-02 13:01:26 +00:00
|
|
|
UInt16 port = 0;
|
2021-09-01 17:59:11 +00:00
|
|
|
String username;
|
|
|
|
String password;
|
|
|
|
String database;
|
|
|
|
String table;
|
2021-09-01 23:17:15 +00:00
|
|
|
String schema;
|
2021-09-01 17:59:11 +00:00
|
|
|
|
|
|
|
ExternalDataSourceConfiguration() = default;
|
|
|
|
ExternalDataSourceConfiguration(const ExternalDataSourceConfiguration & configuration) = default;
|
2021-09-01 23:17:15 +00:00
|
|
|
|
|
|
|
String toString() const;
|
2021-09-01 17:59:11 +00:00
|
|
|
};
|
|
|
|
|
2021-09-01 23:17:15 +00:00
|
|
|
using ExternalDataSourceConfigurationPtr = std::shared_ptr<ExternalDataSourceConfiguration>;
|
|
|
|
|
|
|
|
|
2021-09-01 17:59:11 +00:00
|
|
|
struct StoragePostgreSQLConfiguration : ExternalDataSourceConfiguration
|
|
|
|
{
|
2021-09-02 13:01:26 +00:00
|
|
|
explicit StoragePostgreSQLConfiguration(const ExternalDataSourceConfiguration & common_configuration)
|
|
|
|
: ExternalDataSourceConfiguration(common_configuration) {}
|
2021-09-01 17:59:11 +00:00
|
|
|
|
|
|
|
String on_conflict;
|
|
|
|
std::vector<std::pair<String, UInt16>> addresses; /// Failover replicas.
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2021-09-02 13:01:26 +00:00
|
|
|
struct StorageMySQLConfiguration : ExternalDataSourceConfiguration
|
|
|
|
{
|
|
|
|
explicit StorageMySQLConfiguration(const ExternalDataSourceConfiguration & common_configuration)
|
|
|
|
: ExternalDataSourceConfiguration(common_configuration) {}
|
|
|
|
|
|
|
|
bool replace_query;
|
|
|
|
String on_duplicate_clause;
|
|
|
|
std::vector<std::pair<String, UInt16>> addresses; /// Failover replicas.
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2021-09-01 17:59:11 +00:00
|
|
|
using EngineArgs = std::vector<std::pair<String, DB::Field>>;
|
|
|
|
|
|
|
|
/* If storage engine's configuration was define via named_collections,
|
|
|
|
* return all options in ExternalDataSource::Configuration struct.
|
|
|
|
*
|
|
|
|
* Also check if engine arguemnts have key-value defined configuration options:
|
|
|
|
* ENGINE = PostgreSQL(postgresql_configuration, database = 'postgres_database');
|
|
|
|
* In this case they will override values defined in config.
|
|
|
|
*
|
|
|
|
* If there are key-value arguments apart from common: `host`, `port`, `username`, `password`, `database`,
|
|
|
|
* i.e. storage-specific arguments, then return them back in a set: ExternalDataSource::EngineArgs.
|
|
|
|
*/
|
|
|
|
std::tuple<ExternalDataSourceConfiguration, EngineArgs, bool>
|
2021-09-01 23:17:15 +00:00
|
|
|
tryGetConfigurationAsNamedCollection(ASTs args, ContextPtr context, bool is_database_engine = false);
|
|
|
|
|
2021-09-02 13:01:26 +00:00
|
|
|
ExternalDataSourceConfiguration tryGetConfigurationAsNamedCollection(
|
|
|
|
const Poco::Util::AbstractConfiguration & dict_config, const String & dict_config_prefix, ContextPtr context);
|
|
|
|
|
|
|
|
|
|
|
|
/// Highest priority is 0, the bigger the number in map, the less the priority.
|
|
|
|
using ExternalDataSourcesConfigurationByPriority = std::map<size_t, std::vector<ExternalDataSourceConfiguration>>;
|
|
|
|
|
|
|
|
struct ExternalDataSourcesByPriority
|
|
|
|
{
|
|
|
|
String database;
|
|
|
|
String table;
|
|
|
|
String schema;
|
|
|
|
ExternalDataSourcesConfigurationByPriority replicas_configurations;
|
|
|
|
};
|
|
|
|
|
|
|
|
ExternalDataSourcesByPriority
|
2021-09-01 23:17:15 +00:00
|
|
|
tryGetConfigurationsByPriorityAsNamedCollection(const Poco::Util::AbstractConfiguration & dict_config, const String & dict_config_prefix, ContextPtr context);
|
2021-09-01 17:59:11 +00:00
|
|
|
|
|
|
|
}
|