ClickHouse/src/Interpreters/ExternalDictionariesLoader.cpp

58 lines
1.7 KiB
C++
Raw Normal View History

2019-09-26 11:19:10 +00:00
#include <Interpreters/ExternalDictionariesLoader.h>
#include <Dictionaries/DictionaryFactory.h>
#include <Dictionaries/DictionaryStructure.h>
#if !defined(ARCADIA_BUILD)
# include "config_core.h"
#endif
2019-09-26 11:19:10 +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.
ExternalDictionariesLoader::ExternalDictionariesLoader(Context & context_)
: ExternalLoader("external dictionary", &Logger::get("ExternalDictionariesLoader"))
, context(context_)
2019-09-26 11:19:10 +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
/// additional checks, so we identify them here.
2019-12-11 11:09:21 +00:00
bool dictionary_from_database = !repository_name.empty();
return DictionaryFactory::instance().create(name, config, key_in_config, context, dictionary_from_database);
2019-09-26 11:19:10 +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);
}
void ExternalDictionariesLoader::resetAll()
{
#if USE_MYSQL
mysqlxx::PoolFactory::instance().reset();
#endif
}
2019-09-26 11:19:10 +00:00
}