2017-10-17 10:44:46 +00:00
|
|
|
#include <Interpreters/ExternalModels.h>
|
|
|
|
#include <Interpreters/Context.h>
|
2017-10-17 10:43:42 +00:00
|
|
|
|
2017-10-17 10:44:46 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
|
|
|
extern const int INVALID_CONFIG_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
2017-10-31 19:45:58 +00:00
|
|
|
const ExternalLoaderUpdateSettings externalModelsUpdateSettings { };
|
2017-10-17 10:44:46 +00:00
|
|
|
|
2017-10-26 18:39:55 +00:00
|
|
|
const ExternalLoaderConfigSettings & getExternalModelsConfigSettings()
|
|
|
|
{
|
|
|
|
static ExternalLoaderConfigSettings settings;
|
|
|
|
static std::once_flag flag;
|
2017-10-17 10:44:46 +00:00
|
|
|
|
2018-01-10 00:04:08 +00:00
|
|
|
std::call_once(flag, []
|
|
|
|
{
|
2017-10-26 18:39:55 +00:00
|
|
|
settings.external_config = "model";
|
|
|
|
settings.external_name = "name";
|
|
|
|
settings.path_setting_name = "models_config";
|
|
|
|
});
|
2017-10-17 10:44:46 +00:00
|
|
|
|
2017-10-26 18:39:55 +00:00
|
|
|
return settings;
|
|
|
|
}
|
2017-10-17 10:44:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-11-28 11:00:07 +00:00
|
|
|
ExternalModels::ExternalModels(
|
|
|
|
std::unique_ptr<IExternalLoaderConfigRepository> config_repository,
|
2019-04-10 18:36:52 +00:00
|
|
|
Context & context)
|
2017-10-17 10:44:46 +00:00
|
|
|
: ExternalLoader(context.getConfigRef(),
|
2017-10-26 18:39:55 +00:00
|
|
|
externalModelsUpdateSettings,
|
2017-10-17 10:44:46 +00:00
|
|
|
getExternalModelsConfigSettings(),
|
2017-11-28 11:00:07 +00:00
|
|
|
std::move(config_repository),
|
2017-10-17 10:44:46 +00:00
|
|
|
&Logger::get("ExternalModels"),
|
|
|
|
"external model"),
|
|
|
|
context(context)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<IExternalLoadable> ExternalModels::create(
|
2019-04-10 18:36:52 +00:00
|
|
|
const std::string & name, const Configuration & config, const std::string & config_prefix) const
|
2017-10-17 10:44:46 +00:00
|
|
|
{
|
|
|
|
String type = config.getString(config_prefix + ".type");
|
2017-10-17 15:38:36 +00:00
|
|
|
ExternalLoadableLifetime lifetime(config, config_prefix + ".lifetime");
|
2017-10-17 10:44:46 +00:00
|
|
|
|
|
|
|
/// TODO: add models factory.
|
|
|
|
if (type == "catboost")
|
|
|
|
{
|
|
|
|
return std::make_unique<CatBoostModel>(
|
|
|
|
name, config.getString(config_prefix + ".path"),
|
|
|
|
context.getConfigRef().getString("catboost_dynamic_library_path"),
|
2017-10-31 11:18:09 +00:00
|
|
|
lifetime
|
2017-10-17 10:44:46 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw Exception("Unknown model type: " + type, ErrorCodes::INVALID_CONFIG_PARAMETER);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|