2015-01-21 11:39:48 +00:00
|
|
|
#include <DB/Interpreters/Dictionaries.h>
|
|
|
|
#include <DB/Dictionaries/DictionaryFactory.h>
|
|
|
|
#include <Poco/Util/XMLConfiguration.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
template <typename T> struct release
|
|
|
|
{
|
|
|
|
void operator()(const T * const ptr) { ptr->release(); }
|
|
|
|
};
|
|
|
|
template <typename T> using config_ptr_t = std::unique_ptr<T, release<T>>;
|
|
|
|
};
|
|
|
|
|
|
|
|
void Dictionaries::reloadExternalDictionaries()
|
|
|
|
{
|
|
|
|
const auto config_path = Poco::Util::Application::instance().config().getString("dictionaries_config");
|
2015-01-22 14:32:38 +00:00
|
|
|
if (config_path.empty())
|
|
|
|
return;
|
|
|
|
|
2015-01-21 11:39:48 +00:00
|
|
|
const config_ptr_t<Poco::Util::XMLConfiguration> config{new Poco::Util::XMLConfiguration{config_path}};
|
|
|
|
|
|
|
|
/// get all dictionaries' definitions
|
|
|
|
Poco::Util::AbstractConfiguration::Keys keys;
|
|
|
|
config->keys(keys);
|
|
|
|
|
|
|
|
/// for each dictionary defined in xml config
|
|
|
|
for (const auto & key : keys)
|
|
|
|
{
|
|
|
|
if (0 != strncmp(key.data(), "dictionary", strlen("dictionary")))
|
|
|
|
{
|
2015-01-22 14:32:38 +00:00
|
|
|
LOG_WARNING(log, "unknown node in dictionaries file: '" + key + "', 'dictionary'");
|
2015-01-21 11:39:48 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto & prefix = key + '.';
|
|
|
|
|
|
|
|
const auto & name = config->getString(prefix + "name");
|
|
|
|
if (name.empty())
|
|
|
|
{
|
2015-01-22 14:32:38 +00:00
|
|
|
LOG_WARNING(log, "dictionary name cannot be empty");
|
|
|
|
continue;
|
2015-01-21 11:39:48 +00:00
|
|
|
}
|
|
|
|
|
2015-01-22 14:32:38 +00:00
|
|
|
try
|
2015-01-21 11:39:48 +00:00
|
|
|
{
|
2015-01-22 14:32:38 +00:00
|
|
|
auto dict_ptr = DictionaryFactory::instance().create(*config, prefix, context);
|
|
|
|
const auto it = external_dictionaries.find(name);
|
|
|
|
if (it == std::end(external_dictionaries))
|
|
|
|
external_dictionaries.emplace(name, std::make_shared<MultiVersion<IDictionary>>(dict_ptr.release()));
|
|
|
|
else
|
|
|
|
it->second->set(dict_ptr.release());
|
2015-01-21 11:39:48 +00:00
|
|
|
}
|
2015-01-22 14:32:38 +00:00
|
|
|
catch (const Exception &)
|
2015-01-21 11:39:48 +00:00
|
|
|
{
|
2015-01-22 14:32:38 +00:00
|
|
|
handleException();
|
2015-01-21 11:39:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|