#pragma once #include #include #include namespace ExternalDataSource { } namespace DB { struct ExternalDataSourceConfiguration { String host; UInt16 port = 0; String username; String password; String database; String table; String schema; ExternalDataSourceConfiguration() = default; ExternalDataSourceConfiguration(const ExternalDataSourceConfiguration & configuration) = default; String toString() const; }; using ExternalDataSourceConfigurationPtr = std::shared_ptr; struct StoragePostgreSQLConfiguration : ExternalDataSourceConfiguration { explicit StoragePostgreSQLConfiguration(const ExternalDataSourceConfiguration & common_configuration) : ExternalDataSourceConfiguration(common_configuration) {} String on_conflict; std::vector> addresses; /// Failover replicas. }; struct StorageMySQLConfiguration : ExternalDataSourceConfiguration { explicit StorageMySQLConfiguration(const ExternalDataSourceConfiguration & common_configuration) : ExternalDataSourceConfiguration(common_configuration) {} bool replace_query; String on_duplicate_clause; std::vector> addresses; /// Failover replicas. }; using EngineArgs = std::vector>; /* 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 tryGetConfigurationAsNamedCollection(ASTs args, ContextPtr context, bool is_database_engine = false); 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>; struct ExternalDataSourcesByPriority { String database; String table; String schema; ExternalDataSourcesConfigurationByPriority replicas_configurations; }; ExternalDataSourcesByPriority tryGetConfigurationsByPriorityAsNamedCollection(const Poco::Util::AbstractConfiguration & dict_config, const String & dict_config_prefix, ContextPtr context); }