1#include <Interpreters/ExternalModelsLoader.h>
2#include <Interpreters/Context.h>
3
4namespace DB
5{
6
7namespace ErrorCodes
8{
9 extern const int INVALID_CONFIG_PARAMETER;
10}
11
12
13ExternalModelsLoader::ExternalModelsLoader(Context & context_)
14 : ExternalLoader("external model", &Logger::get("ExternalModelsLoader"))
15 , context(context_)
16{
17 setConfigSettings({"models", "name", {}});
18 enablePeriodicUpdates(true);
19}
20
21std::shared_ptr<const IExternalLoadable> ExternalModelsLoader::create(
22 const std::string & name, const Poco::Util::AbstractConfiguration & config,
23 const std::string & config_prefix, const std::string & /* repository_name */) const
24{
25 String type = config.getString(config_prefix + ".type");
26 ExternalLoadableLifetime lifetime(config, config_prefix + ".lifetime");
27
28 /// TODO: add models factory.
29 if (type == "catboost")
30 {
31 return std::make_unique<CatBoostModel>(
32 name, config.getString(config_prefix + ".path"),
33 context.getConfigRef().getString("catboost_dynamic_library_path"),
34 lifetime
35 );
36 }
37 else
38 {
39 throw Exception("Unknown model type: " + type, ErrorCodes::INVALID_CONFIG_PARAMETER);
40 }
41}
42}
43