2019-09-26 11:19:10 +00:00
|
|
|
#include <Interpreters/ExternalDictionariesLoader.h>
|
|
|
|
#include <Dictionaries/DictionaryFactory.h>
|
2020-04-12 20:50:32 +00:00
|
|
|
#include <Dictionaries/DictionaryStructure.h>
|
2020-04-16 12:31:57 +00:00
|
|
|
|
|
|
|
#if !defined(ARCADIA_BUILD)
|
|
|
|
# include "config_core.h"
|
|
|
|
#endif
|
2019-09-26 11:19:10 +00:00
|
|
|
|
2019-10-08 17:27:00 +00:00
|
|
|
#if USE_MYSQL
|
|
|
|
# include <mysqlxx/PoolFactory.h>
|
|
|
|
#endif
|
|
|
|
|
2019-09-26 11:19:10 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
/// Must not acquire Context lock in constructor to avoid possibility of deadlocks.
|
2019-10-18 15:44:32 +00:00
|
|
|
ExternalDictionariesLoader::ExternalDictionariesLoader(Context & context_)
|
2020-05-30 21:57:37 +00:00
|
|
|
: ExternalLoader("external dictionary", &Poco::Logger::get("ExternalDictionariesLoader"))
|
2019-09-30 16:12:08 +00:00
|
|
|
, context(context_)
|
2019-09-26 11:19:10 +00:00
|
|
|
{
|
2019-12-30 23:30:06 +00:00
|
|
|
setConfigSettings({"dictionary", "name", "database"});
|
2019-09-26 11:19:10 +00:00
|
|
|
enableAsyncLoading(true);
|
|
|
|
enablePeriodicUpdates(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ExternalLoader::LoadablePtr ExternalDictionariesLoader::create(
|
2019-12-11 11:09:21 +00:00
|
|
|
const std::string & name, const Poco::Util::AbstractConfiguration & config,
|
|
|
|
const std::string & key_in_config, const std::string & repository_name) const
|
2019-09-26 11:19:10 +00:00
|
|
|
{
|
2020-01-11 09:50:41 +00:00
|
|
|
/// For dictionaries from databases (created with DDL queries) we have to perform
|
2019-12-10 17:27:29 +00:00
|
|
|
/// additional checks, so we identify them here.
|
2019-12-11 11:09:21 +00:00
|
|
|
bool dictionary_from_database = !repository_name.empty();
|
2019-12-10 17:27:29 +00:00
|
|
|
return DictionaryFactory::instance().create(name, config, key_in_config, context, dictionary_from_database);
|
2019-09-26 11:19:10 +00:00
|
|
|
}
|
2020-02-27 09:34:06 +00:00
|
|
|
|
2020-04-12 20:50:32 +00:00
|
|
|
|
|
|
|
DictionaryStructure
|
|
|
|
ExternalDictionariesLoader::getDictionaryStructure(const Poco::Util::AbstractConfiguration & config, const std::string & key_in_config)
|
|
|
|
{
|
|
|
|
return {config, key_in_config + ".structure"};
|
|
|
|
}
|
|
|
|
|
|
|
|
DictionaryStructure ExternalDictionariesLoader::getDictionaryStructure(const ObjectConfig & config)
|
|
|
|
{
|
|
|
|
return getDictionaryStructure(*config.config, config.key_in_config);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-27 09:34:06 +00:00
|
|
|
void ExternalDictionariesLoader::resetAll()
|
|
|
|
{
|
2020-04-16 12:31:57 +00:00
|
|
|
#if USE_MYSQL
|
|
|
|
mysqlxx::PoolFactory::instance().reset();
|
|
|
|
#endif
|
2020-02-27 09:34:06 +00:00
|
|
|
}
|
|
|
|
|
2019-09-26 11:19:10 +00:00
|
|
|
}
|