Fix tests

This commit is contained in:
kssenii 2023-02-27 17:42:04 +01:00
parent b19264cf9f
commit ad88251ee7
5 changed files with 18 additions and 5 deletions

View File

@ -353,6 +353,15 @@ bool NamedCollection::has(const Key & key) const
return pimpl->has(key);
}
bool NamedCollection::hasAny(const std::initializer_list<Key> & keys) const
{
std::lock_guard lock(mutex);
for (const auto & key : keys)
if (pimpl->has(key))
return true;
return false;
}
template <typename T> T NamedCollection::get(const Key & key) const
{
std::lock_guard lock(mutex);

View File

@ -35,6 +35,8 @@ public:
bool has(const Key & key) const;
bool hasAny(const std::initializer_list<Key> & keys) const;
template <typename T> T get(const Key & key) const;
template <typename T> T getOrDefault(const Key & key, const T & default_value) const;

View File

@ -27,8 +27,8 @@ HTTPHeaderEntries getHeadersFromNamedCollection(const NamedCollection & collecti
struct ExternalDatabaseEqualKeysSet
{
static constexpr std::array<std::pair<std::string_view, std::string_view>, 3> equal_keys{
std::pair{"username", "user"}, std::pair{"database", "db"}, std::pair{"hostname", "host"}};
static constexpr std::array<std::pair<std::string_view, std::string_view>, 5> equal_keys{
std::pair{"username", "user"}, std::pair{"database", "db"}, std::pair{"hostname", "host"}, std::pair{"addresses_expr", "host"}, std::pair{"addresses_expr", "hostname"}};
};
struct MongoDBEqualKeysSet
{

View File

@ -184,7 +184,7 @@ public:
struct Configuration : public StatelessTableEngineConfiguration
{
std::string url;
std::string http_method = "auto";
std::string http_method;
HTTPHeaderEntries headers;
std::string addresses_expr;
};

View File

@ -57,10 +57,12 @@ void TableFunctionRemote::parseArguments(const ASTPtr & ast_function, ContextPtr
validateNamedCollection<ValidateKeysMultiset<ExternalDatabaseEqualKeysSet>>(
*named_collection,
{"addresses_expr", "database", "db", "table"},
{"username", "user", "password", "sharding_key"});
{"addresses_expr", "host", "database", "db", "table"},
{"username", "user", "password", "sharding_key", "port"});
cluster_description = named_collection->getOrDefault<String>("addresses_expr", "");
if (cluster_description.empty() && named_collection->hasAny({"host", "hostname"}))
cluster_description = named_collection->has("port") ? named_collection->getAny<String>({"host", "hostname"}) + ':' + toString(named_collection->get<UInt64>("port")) : named_collection->getAny<String>({"host", "hostname"});
database = named_collection->getAnyOrDefault<String>({"db", "database"}, "default");
table = named_collection->get<String>("table");
username = named_collection->getAnyOrDefault<String>({"username", "user"}, "default");