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
|
|
|
|
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-03 11:16:32 +00:00
|
|
|
explicit StoragePostgreSQLConfiguration(
|
|
|
|
const ExternalDataSourceConfiguration & common_configuration,
|
|
|
|
const std::vector<std::pair<String, UInt16>> & addresses_ = {})
|
|
|
|
: ExternalDataSourceConfiguration(common_configuration)
|
|
|
|
, addresses(addresses_) {}
|
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) {}
|
|
|
|
|
2021-09-04 18:46:09 +00:00
|
|
|
bool replace_query = false;
|
2021-09-02 13:01:26 +00:00
|
|
|
String on_duplicate_clause;
|
|
|
|
std::vector<std::pair<String, UInt16>> addresses; /// Failover replicas.
|
|
|
|
};
|
|
|
|
|
2021-09-03 11:16:32 +00:00
|
|
|
struct StorageMongoDBConfiguration : ExternalDataSourceConfiguration
|
|
|
|
{
|
|
|
|
explicit StorageMongoDBConfiguration(const ExternalDataSourceConfiguration & common_configuration)
|
|
|
|
: ExternalDataSourceConfiguration(common_configuration) {}
|
|
|
|
|
|
|
|
String collection;
|
|
|
|
String options;
|
|
|
|
};
|
|
|
|
|
2021-09-02 13:01:26 +00:00
|
|
|
|
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.
|
|
|
|
*
|
2021-09-04 18:46:09 +00:00
|
|
|
* Also check if engine arguments have key-value defined configuration options:
|
2021-09-01 17:59:11 +00:00
|
|
|
* 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-03 11:16:32 +00:00
|
|
|
getExternalDataSourceConfiguration(ASTs args, ContextPtr context, bool is_database_engine = false);
|
2021-09-01 23:17:15 +00:00
|
|
|
|
2021-09-03 11:16:32 +00:00
|
|
|
ExternalDataSourceConfiguration getExternalDataSourceConfiguration(
|
2021-09-02 13:01:26 +00:00
|
|
|
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-03 11:16:32 +00:00
|
|
|
getExternalDataSourceConfigurationByPriority(const Poco::Util::AbstractConfiguration & dict_config, const String & dict_config_prefix, ContextPtr context);
|
2021-09-01 17:59:11 +00:00
|
|
|
|
|
|
|
}
|