aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/IO/Resource/ClassifiersConfig.cpp
blob: fcd4655e2e4e65e94bf098a5114c90caeea4ddae (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <IO/Resource/ClassifiersConfig.h>

#include <Common/Exception.h>

namespace DB
{

namespace ErrorCodes
{
    extern const int RESOURCE_NOT_FOUND;
}

ClassifierDescription::ClassifierDescription(const Poco::Util::AbstractConfiguration & config, const String & config_prefix)
{
    Poco::Util::AbstractConfiguration::Keys keys;
    config.keys(config_prefix, keys);
    for (const auto & key : keys)
        emplace(key, config.getString(config_prefix + "." + key));
}

ClassifiersConfig::ClassifiersConfig(const Poco::Util::AbstractConfiguration & config)
{
    Poco::Util::AbstractConfiguration::Keys keys;
    const String config_prefix = "classifiers";
    config.keys(config_prefix, keys);
    for (const auto & key : keys)
        classifiers.emplace(std::piecewise_construct,
            std::forward_as_tuple(key),
            std::forward_as_tuple(config, config_prefix + "." + key));
}

const ClassifierDescription & ClassifiersConfig::get(const String & classifier_name)
{
    if (auto it = classifiers.find(classifier_name); it != classifiers.end())
        return it->second;
    else
        throw Exception(ErrorCodes::RESOURCE_NOT_FOUND, "Unknown classifier '{}' to access resources", classifier_name);
}

}