From 57bd7afc0316c4649b0385f959d04374668be7da Mon Sep 17 00:00:00 2001 From: Vitaly Baranov Date: Tue, 19 May 2020 21:12:30 +0300 Subject: [PATCH] Fix passing dictionary's name to dictGet() with alias. --- src/Interpreters/ActionsVisitor.cpp | 4 ++-- src/Interpreters/MarkTableIdentifiersVisitor.cpp | 14 ++++++++------ src/Interpreters/misc.h | 7 ++++++- .../01018_ddl_dictionaries_select.reference | 1 + .../0_stateless/01018_ddl_dictionaries_select.sql | 3 +++ 5 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/Interpreters/ActionsVisitor.cpp b/src/Interpreters/ActionsVisitor.cpp index 7bb2dda0ab4..3fa53e3e694 100644 --- a/src/Interpreters/ActionsVisitor.cpp +++ b/src/Interpreters/ActionsVisitor.cpp @@ -471,7 +471,7 @@ void ActionsMatcher::visit(const ASTFunction & node, const ASTPtr & ast, Data & argument_types.push_back(column.type); argument_names.push_back(column.name); } - else if (identifier && functionIsJoinGetOrDictGet(node.name) && arg == 0) + else if (identifier && (functionIsJoinGet(node.name) || functionIsDictGet(node.name)) && arg == 0) { auto table_id = IdentifierSemantic::extractDatabaseAndTable(*identifier); table_id = data.context.resolveStorageID(table_id, Context::ResolveOrdinary); @@ -480,7 +480,7 @@ void ActionsMatcher::visit(const ASTFunction & node, const ASTPtr & ast, Data & ColumnWithTypeAndName column( ColumnConst::create(std::move(column_string), 1), std::make_shared(), - data.getUniqueName("__joinGetOrDictGet")); + data.getUniqueName("__" + node.name)); data.addAction(ExpressionAction::addColumn(column)); argument_types.push_back(column.type); argument_names.push_back(column.name); diff --git a/src/Interpreters/MarkTableIdentifiersVisitor.cpp b/src/Interpreters/MarkTableIdentifiersVisitor.cpp index 93477064862..c7b8701c4a0 100644 --- a/src/Interpreters/MarkTableIdentifiersVisitor.cpp +++ b/src/Interpreters/MarkTableIdentifiersVisitor.cpp @@ -38,16 +38,18 @@ void MarkTableIdentifiersMatcher::visit(const ASTFunction & func, ASTPtr &, Data if (functionIsInOrGlobalInOperator(func.name)) { auto & ast = func.arguments->children.at(1); - if (auto opt_name = tryGetIdentifierName(ast)) - if (!data.aliases.count(*opt_name)) - setIdentifierSpecial(ast); + auto opt_name = tryGetIdentifierName(ast); + if (opt_name && !data.aliases.count(*opt_name)) + setIdentifierSpecial(ast); } - // first argument of joinGet can be a table identifier - if (functionIsJoinGetOrDictGet(func.name)) + // First argument of joinGet can be a table name, perhaps with a database. + // First argument of dictGet can be a dictionary name, perhaps with a database. + if (functionIsJoinGet(func.name) || functionIsDictGet(func.name)) { auto & ast = func.arguments->children.at(0); - if (auto opt_name = tryGetIdentifierName(ast)) + auto opt_name = tryGetIdentifierName(ast); + if (opt_name && !data.aliases.count(*opt_name)) setIdentifierSpecial(ast); } } diff --git a/src/Interpreters/misc.h b/src/Interpreters/misc.h index 97cfbf252f9..bc994194336 100644 --- a/src/Interpreters/misc.h +++ b/src/Interpreters/misc.h @@ -20,9 +20,14 @@ inline bool functionIsLikeOperator(const std::string & name) return name == "like" || name == "notLike"; } -inline bool functionIsJoinGetOrDictGet(const std::string & name) +inline bool functionIsJoinGet(const std::string & name) { return name == "joinGet" || startsWith(name, "dictGet"); } +inline bool functionIsDictGet(const std::string & name) +{ + return startsWith(name, "dictGet") || (name == "dictHas") || (name == "dictIsIn"); +} + } diff --git a/tests/queries/0_stateless/01018_ddl_dictionaries_select.reference b/tests/queries/0_stateless/01018_ddl_dictionaries_select.reference index 7c13bf305ee..28ee2a8690b 100644 --- a/tests/queries/0_stateless/01018_ddl_dictionaries_select.reference +++ b/tests/queries/0_stateless/01018_ddl_dictionaries_select.reference @@ -20,4 +20,5 @@ database_for_dict dict2 Hashed 6 6 6 +database_for_dict.dict3 6 6 diff --git a/tests/queries/0_stateless/01018_ddl_dictionaries_select.sql b/tests/queries/0_stateless/01018_ddl_dictionaries_select.sql index f3dd7682ffd..7f2e1d08671 100644 --- a/tests/queries/0_stateless/01018_ddl_dictionaries_select.sql +++ b/tests/queries/0_stateless/01018_ddl_dictionaries_select.sql @@ -115,6 +115,9 @@ SELECT dictGet(database_for_dict.dict3, 'some_column', toUInt64(12)); SELECT dictGet(default.dict3, 'some_column', toUInt64(12)); -- {serverError 36} USE default; +-- alias should be handled correctly +SELECT 'database_for_dict.dict3' as n, dictGet(n, 'some_column', toUInt64(12)); + DROP TABLE database_for_dict.table_for_dict; SYSTEM RELOAD DICTIONARIES; -- {serverError 60}