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;
|
|
|
|
UInt16 port;
|
|
|
|
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>;
|
|
|
|
|
|
|
|
/// Highest priority is 0, the bigger the number in map, the less the priority.
|
|
|
|
using ExternalDataSourcesConfigurationByPriority = std::map<size_t, std::vector<ExternalDataSourceConfiguration>>;
|
|
|
|
|
|
|
|
|
2021-09-01 17:59:11 +00:00
|
|
|
struct StoragePostgreSQLConfiguration : ExternalDataSourceConfiguration
|
|
|
|
{
|
|
|
|
explicit StoragePostgreSQLConfiguration(
|
2021-09-01 23:17:15 +00:00
|
|
|
const ExternalDataSourceConfiguration & common_configuration,
|
|
|
|
const String & on_conflict_ = "")
|
2021-09-01 17:59:11 +00:00
|
|
|
: ExternalDataSourceConfiguration(common_configuration)
|
2021-09-01 23:17:15 +00:00
|
|
|
, on_conflict(on_conflict_) {}
|
2021-09-01 17:59:11 +00:00
|
|
|
|
|
|
|
String on_conflict;
|
|
|
|
std::vector<std::pair<String, UInt16>> addresses; /// Failover replicas.
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
ExternalDataSourcesConfigurationByPriority
|
|
|
|
tryGetConfigurationsByPriorityAsNamedCollection(const Poco::Util::AbstractConfiguration & dict_config, const String & dict_config_prefix, ContextPtr context);
|
2021-09-01 17:59:11 +00:00
|
|
|
|
|
|
|
}
|