mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-26 01:22:04 +00:00
Updated ExternalDictionariesLoader interface with context parameter
This commit is contained in:
parent
32831e37ba
commit
849a980644
@ -79,7 +79,7 @@ public:
|
||||
|
||||
std::shared_ptr<const IDictionaryBase> getDictionary(const String & dictionary_name)
|
||||
{
|
||||
auto dict = context.getExternalDictionariesLoader().getDictionary(dictionary_name);
|
||||
auto dict = context.getExternalDictionariesLoader().getDictionary(dictionary_name, context);
|
||||
|
||||
if (!access_checked)
|
||||
{
|
||||
@ -118,7 +118,7 @@ public:
|
||||
|
||||
DictionaryStructure getDictionaryStructure(const String & dictionary_name) const
|
||||
{
|
||||
return context.getExternalDictionariesLoader().getDictionaryStructure(dictionary_name);
|
||||
return context.getExternalDictionariesLoader().getDictionaryStructure(dictionary_name, context);
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -762,7 +762,7 @@ static bool allowDictJoin(StoragePtr joined_storage, const Context & context, St
|
||||
return false;
|
||||
|
||||
dict_name = dict->dictionaryName();
|
||||
auto dictionary = context.getExternalDictionariesLoader().getDictionary(dict_name);
|
||||
auto dictionary = context.getExternalDictionariesLoader().getDictionary(dict_name, context);
|
||||
if (!dictionary)
|
||||
return false;
|
||||
|
||||
|
@ -23,9 +23,9 @@ namespace ErrorCodes
|
||||
}
|
||||
|
||||
/// Must not acquire Context lock in constructor to avoid possibility of deadlocks.
|
||||
ExternalDictionariesLoader::ExternalDictionariesLoader(Context & context_)
|
||||
ExternalDictionariesLoader::ExternalDictionariesLoader(Context & global_context_)
|
||||
: ExternalLoader("external dictionary", &Poco::Logger::get("ExternalDictionariesLoader"))
|
||||
, context(context_)
|
||||
, global_context(global_context_)
|
||||
{
|
||||
setConfigSettings({"dictionary", "name", "database", "uuid"});
|
||||
enableAsyncLoading(true);
|
||||
@ -40,31 +40,31 @@ ExternalLoader::LoadablePtr ExternalDictionariesLoader::create(
|
||||
/// For dictionaries from databases (created with DDL queries) we have to perform
|
||||
/// additional checks, so we identify them here.
|
||||
bool dictionary_from_database = !repository_name.empty();
|
||||
return DictionaryFactory::instance().create(name, config, key_in_config, context, dictionary_from_database);
|
||||
return DictionaryFactory::instance().create(name, config, key_in_config, global_context, dictionary_from_database);
|
||||
}
|
||||
|
||||
ExternalDictionariesLoader::DictPtr ExternalDictionariesLoader::getDictionary(const std::string & dictionary_name) const
|
||||
ExternalDictionariesLoader::DictPtr ExternalDictionariesLoader::getDictionary(const std::string & dictionary_name, const Context & context) const
|
||||
{
|
||||
std::string resolved_dictionary_name = resolveDictionaryName(dictionary_name);
|
||||
std::string resolved_dictionary_name = resolveDictionaryName(dictionary_name, context.getCurrentDatabase());
|
||||
return std::static_pointer_cast<const IDictionaryBase>(load(resolved_dictionary_name));
|
||||
}
|
||||
|
||||
ExternalDictionariesLoader::DictPtr ExternalDictionariesLoader::tryGetDictionary(const std::string & dictionary_name) const
|
||||
ExternalDictionariesLoader::DictPtr ExternalDictionariesLoader::tryGetDictionary(const std::string & dictionary_name, const Context & context) const
|
||||
{
|
||||
std::string resolved_dictionary_name = resolveDictionaryName(dictionary_name);
|
||||
std::string resolved_dictionary_name = resolveDictionaryName(dictionary_name, context.getCurrentDatabase());
|
||||
return std::static_pointer_cast<const IDictionaryBase>(tryLoad(resolved_dictionary_name));
|
||||
}
|
||||
|
||||
|
||||
void ExternalDictionariesLoader::reloadDictionary(const std::string & dictionary_name) const
|
||||
void ExternalDictionariesLoader::reloadDictionary(const std::string & dictionary_name, const Context & context) const
|
||||
{
|
||||
std::string resolved_dictionary_name = resolveDictionaryName(dictionary_name);
|
||||
std::string resolved_dictionary_name = resolveDictionaryName(dictionary_name, context.getCurrentDatabase());
|
||||
loadOrReload(resolved_dictionary_name);
|
||||
}
|
||||
|
||||
DictionaryStructure ExternalDictionariesLoader::getDictionaryStructure(const std::string & dictionary_name) const
|
||||
DictionaryStructure ExternalDictionariesLoader::getDictionaryStructure(const std::string & dictionary_name, const Context & query_context) const
|
||||
{
|
||||
std::string resolved_name = resolveDictionaryName(dictionary_name);
|
||||
std::string resolved_name = resolveDictionaryName(dictionary_name, query_context.getCurrentDatabase());
|
||||
|
||||
auto load_result = getLoadResult(resolved_name);
|
||||
if (!load_result.config)
|
||||
@ -73,7 +73,7 @@ DictionaryStructure ExternalDictionariesLoader::getDictionaryStructure(const std
|
||||
return ExternalDictionariesLoader::getDictionaryStructure(*load_result.config);
|
||||
}
|
||||
|
||||
std::string ExternalDictionariesLoader::resolveDictionaryName(const std::string & dictionary_name) const
|
||||
std::string ExternalDictionariesLoader::resolveDictionaryName(const std::string & dictionary_name, const std::string & current_database_name) const
|
||||
{
|
||||
std::string resolved_name = resolveDictionaryNameFromDatabaseCatalog(dictionary_name);
|
||||
bool has_dictionary = has(resolved_name);
|
||||
@ -85,7 +85,7 @@ std::string ExternalDictionariesLoader::resolveDictionaryName(const std::string
|
||||
/// It will help if dictionary is created with DDL and is in current database.
|
||||
if (dictionary_name.find('.') == std::string::npos)
|
||||
{
|
||||
String dictionary_name_with_database = context.getCurrentDatabase() + '.' + dictionary_name;
|
||||
String dictionary_name_with_database = current_database_name + '.' + dictionary_name;
|
||||
resolved_name = resolveDictionaryNameFromDatabaseCatalog(dictionary_name_with_database);
|
||||
has_dictionary = has(resolved_name);
|
||||
}
|
||||
@ -110,7 +110,7 @@ std::string ExternalDictionariesLoader::resolveDictionaryNameFromDatabaseCatalog
|
||||
std::string maybe_database_name = name.substr(0, pos);
|
||||
std::string maybe_table_name = name.substr(pos + 1);
|
||||
|
||||
auto [db, table] = DatabaseCatalog::instance().tryGetDatabaseAndTable({maybe_database_name, maybe_table_name}, context);
|
||||
auto [db, table] = DatabaseCatalog::instance().tryGetDatabaseAndTable({maybe_database_name, maybe_table_name}, global_context);
|
||||
if (!db)
|
||||
return name;
|
||||
assert(table);
|
||||
|
@ -18,17 +18,18 @@ public:
|
||||
using DictPtr = std::shared_ptr<const IDictionaryBase>;
|
||||
|
||||
/// Dictionaries will be loaded immediately and then will be updated in separate thread, each 'reload_period' seconds.
|
||||
explicit ExternalDictionariesLoader(Context & context_);
|
||||
explicit ExternalDictionariesLoader(Context & global_context_);
|
||||
|
||||
DictPtr getDictionary(const std::string & dictionary_name) const;
|
||||
DictPtr getDictionary(const std::string & dictionary_name, const Context & context) const;
|
||||
|
||||
DictPtr tryGetDictionary(const std::string & dictionary_name) const;
|
||||
DictPtr tryGetDictionary(const std::string & dictionary_name, const Context & context) const;
|
||||
|
||||
void reloadDictionary(const std::string & dictionary_name) const;
|
||||
void reloadDictionary(const std::string & dictionary_name, const Context & context) const;
|
||||
|
||||
DictionaryStructure getDictionaryStructure(const std::string & dictionary_name) const;
|
||||
DictionaryStructure getDictionaryStructure(const std::string & dictionary_name, const Context & context) const;
|
||||
|
||||
static DictionaryStructure getDictionaryStructure(const Poco::Util::AbstractConfiguration & config, const std::string & key_in_config = "dictionary");
|
||||
|
||||
static DictionaryStructure getDictionaryStructure(const ObjectConfig & config);
|
||||
|
||||
static void resetAll();
|
||||
@ -37,7 +38,7 @@ protected:
|
||||
LoadablePtr create(const std::string & name, const Poco::Util::AbstractConfiguration & config,
|
||||
const std::string & key_in_config, const std::string & repository_name) const override;
|
||||
|
||||
std::string resolveDictionaryName(const std::string & dictionary_name) const;
|
||||
std::string resolveDictionaryName(const std::string & dictionary_name, const std::string & current_database_name) const;
|
||||
|
||||
/// Try convert qualified dictionary name to persistent UUID
|
||||
std::string resolveDictionaryNameFromDatabaseCatalog(const std::string & name) const;
|
||||
@ -46,7 +47,7 @@ protected:
|
||||
friend class DatabaseDictionary;
|
||||
|
||||
private:
|
||||
Context & context;
|
||||
Context & global_context;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -278,7 +278,7 @@ BlockIO InterpreterSystemQuery::execute()
|
||||
context.checkAccess(AccessType::SYSTEM_RELOAD_DICTIONARY);
|
||||
|
||||
auto & external_dictionaries_loader = system_context.getExternalDictionariesLoader();
|
||||
external_dictionaries_loader.reloadDictionary(query.target_dictionary);
|
||||
external_dictionaries_loader.reloadDictionary(query.target_dictionary, context);
|
||||
|
||||
ExternalDictionariesLoader::resetAll();
|
||||
break;
|
||||
|
@ -135,7 +135,7 @@ void optimizeGroupBy(ASTSelectQuery * select_query, const NameSet & source_colum
|
||||
const auto & dict_name = dict_name_ast->value.safeGet<String>();
|
||||
const auto & attr_name = attr_name_ast->value.safeGet<String>();
|
||||
|
||||
const auto & dict_ptr = context.getExternalDictionariesLoader().getDictionary(dict_name);
|
||||
const auto & dict_ptr = context.getExternalDictionariesLoader().getDictionary(dict_name, context);
|
||||
if (!dict_ptr->isInjective(attr_name))
|
||||
{
|
||||
++i;
|
||||
|
@ -133,7 +133,7 @@ Pipe StorageDictionary::read(
|
||||
const size_t max_block_size,
|
||||
const unsigned /*threads*/)
|
||||
{
|
||||
auto dictionary = context.getExternalDictionariesLoader().getDictionary(dictionary_name);
|
||||
auto dictionary = context.getExternalDictionariesLoader().getDictionary(dictionary_name, context);
|
||||
auto stream = dictionary->getBlockInputStream(column_names, max_block_size);
|
||||
/// TODO: update dictionary interface for processors.
|
||||
return Pipe(std::make_shared<SourceFromInputStream>(stream));
|
||||
@ -153,7 +153,8 @@ void registerStorageDictionary(StorageFactory & factory)
|
||||
|
||||
if (!args.attach)
|
||||
{
|
||||
const auto & dictionary = args.context.getExternalDictionariesLoader().getDictionary(dictionary_name);
|
||||
const auto & context = args.context;
|
||||
const auto & dictionary = context.getExternalDictionariesLoader().getDictionary(dictionary_name, context);
|
||||
const DictionaryStructure & dictionary_structure = dictionary->getStructure();
|
||||
checkNamesAndTypesCompatibleWithDictionary(dictionary_name, args.columns, dictionary_structure);
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ void TableFunctionDictionary::parseArguments(const ASTPtr & ast_function, const
|
||||
ColumnsDescription TableFunctionDictionary::getActualTableStructure(const Context & context) const
|
||||
{
|
||||
const ExternalDictionariesLoader & external_loader = context.getExternalDictionariesLoader();
|
||||
auto dictionary_structure = external_loader.getDictionaryStructure(dictionary_name);
|
||||
auto dictionary_structure = external_loader.getDictionaryStructure(dictionary_name, context);
|
||||
auto result = ColumnsDescription(StorageDictionary::getNamesAndTypes(dictionary_structure));
|
||||
|
||||
return result;
|
||||
|
Loading…
Reference in New Issue
Block a user