diff --git a/src/Dictionaries/ClickHouseDictionarySource.cpp b/src/Dictionaries/ClickHouseDictionarySource.cpp index a5a04d277da..640371947a9 100644 --- a/src/Dictionaries/ClickHouseDictionarySource.cpp +++ b/src/Dictionaries/ClickHouseDictionarySource.cpp @@ -65,14 +65,12 @@ ClickHouseDictionarySource::ClickHouseDictionarySource( const DictionaryStructure & dict_struct_, const Configuration & configuration_, const Block & sample_block_, - ContextMutablePtr context_, - std::shared_ptr local_session_) + ContextMutablePtr context_) : update_time{std::chrono::system_clock::from_time_t(0)} , dict_struct{dict_struct_} , configuration{configuration_} , query_builder{dict_struct, configuration.db, "", configuration.table, configuration.query, configuration.where, IdentifierQuotingStyle::Backticks} , sample_block{sample_block_} - , local_session(local_session_) , context(context_) , pool{createPool(configuration)} , load_all_query{query_builder.composeLoadAllQuery()} @@ -86,7 +84,6 @@ ClickHouseDictionarySource::ClickHouseDictionarySource(const ClickHouseDictionar , invalidate_query_response{other.invalidate_query_response} , query_builder{dict_struct, configuration.db, "", configuration.table, configuration.query, configuration.where, IdentifierQuotingStyle::Backticks} , sample_block{other.sample_block} - , local_session(other.local_session) , context(Context::createCopy(other.context)) , pool{createPool(configuration)} , load_all_query{other.load_all_query} @@ -252,17 +249,18 @@ void registerDictionarySourceClickHouse(DictionarySourceFactory & factory) }; ContextMutablePtr context; - std::shared_ptr local_session; if (configuration.is_local) { - /// Start local session in case when the dictionary is loaded in-process (without TCP communication). - local_session = std::make_shared(global_context, ClientInfo::Interface::LOCAL); - local_session->authenticate(configuration.user, configuration.password, {}); - context = local_session->makeQueryContext(); - context->applySettingsChanges(readSettingsFromDictionaryConfig(config, config_prefix)); + /// We should set user info even for the case when the dictionary is loaded in-process (without TCP communication). + Session session(global_context, ClientInfo::Interface::LOCAL); + session.authenticate(configuration.user, configuration.password, {}); + context = session.makeQueryContext(); } else - context = copyContextAndApplySettingsFromDictionaryConfig(global_context, config, config_prefix); + { + context = Context::createCopy(global_context); + } + context->applySettingsChanges(readSettingsFromDictionaryConfig(config, config_prefix)); String dictionary_name = config.getString(".dictionary.name", ""); String dictionary_database = config.getString(".dictionary.database", ""); @@ -270,7 +268,7 @@ void registerDictionarySourceClickHouse(DictionarySourceFactory & factory) if (dictionary_name == configuration.table && dictionary_database == configuration.db) throw Exception(ErrorCodes::BAD_ARGUMENTS, "ClickHouseDictionarySource table cannot be dictionary table"); - return std::make_unique(dict_struct, configuration, sample_block, context, local_session); + return std::make_unique(dict_struct, configuration, sample_block, context); }; factory.registerSource("clickhouse", create_table_source); diff --git a/src/Dictionaries/ClickHouseDictionarySource.h b/src/Dictionaries/ClickHouseDictionarySource.h index 58243e43b15..be09fa415fd 100644 --- a/src/Dictionaries/ClickHouseDictionarySource.h +++ b/src/Dictionaries/ClickHouseDictionarySource.h @@ -39,8 +39,7 @@ public: const DictionaryStructure & dict_struct_, const Configuration & configuration_, const Block & sample_block_, - ContextMutablePtr context_, - std::shared_ptr local_session_); + ContextMutablePtr context_); /// copy-constructor is provided in order to support cloneability ClickHouseDictionarySource(const ClickHouseDictionarySource & other); @@ -82,7 +81,6 @@ private: mutable std::string invalidate_query_response; ExternalQueryBuilder query_builder; Block sample_block; - std::shared_ptr local_session; ContextMutablePtr context; ConnectionPoolWithFailoverPtr pool; const std::string load_all_query; diff --git a/src/Interpreters/Context.h b/src/Interpreters/Context.h index bc87f570366..7d31a8375d8 100644 --- a/src/Interpreters/Context.h +++ b/src/Interpreters/Context.h @@ -381,7 +381,6 @@ public: /// Sets the current user assuming that he/she is already authenticated. /// WARNING: This function doesn't check password! - /// Normally you shouldn't call this function. Use the Session class to do authentication instead. void setUser(const UUID & user_id_); UserPtr getUser() const;