Merge pull request #53342 from ClickHouse/fix-context-has-expired

Fix "Context has expired" error in dictionaries
This commit is contained in:
Alexey Milovidov 2023-08-12 17:27:15 +03:00 committed by GitHub
commit 38ac027658
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 4 deletions

View File

@ -62,14 +62,13 @@ namespace ErrorCodes
*/
class FunctionDictHelper : WithContext
class FunctionDictHelper
{
public:
explicit FunctionDictHelper(ContextPtr context_) : WithContext(context_) {}
explicit FunctionDictHelper(ContextPtr context_) : current_context(context_) {}
std::shared_ptr<const IDictionary> getDictionary(const String & dictionary_name)
{
auto current_context = getContext();
auto dict = current_context->getExternalDictionariesLoader().getDictionary(dictionary_name, current_context);
if (!access_checked)
@ -132,10 +131,12 @@ public:
DictionaryStructure getDictionaryStructure(const String & dictionary_name) const
{
return getContext()->getExternalDictionariesLoader().getDictionaryStructure(dictionary_name, getContext());
return current_context->getExternalDictionariesLoader().getDictionaryStructure(dictionary_name, current_context);
}
private:
ContextPtr current_context;
/// Access cannot be not granted, since in this case checkAccess() will throw and access_checked will not be updated.
std::atomic<bool> access_checked = false;

View File

@ -0,0 +1 @@
0

View File

@ -0,0 +1,23 @@
DROP DICTIONARY IF EXISTS dict;
DROP TABLE IF EXISTS source;
CREATE TABLE source
(
id UInt64,
value String
)
ENGINE=Memory;
CREATE DICTIONARY dict
(
id UInt64,
value String
)
PRIMARY KEY id
SOURCE(CLICKHOUSE(TABLE 'source'))
LAYOUT(DIRECT());
SELECT 1 IN (SELECT dictGet('dict', 'value', materialize('1')));
DROP DICTIONARY dict;
DROP TABLE source;