dictGet* with table name

This commit is contained in:
Amos Bird 2019-12-22 01:48:33 +08:00 committed by Vitaly Baranov
parent bc5f68f1ee
commit ce3c53a00a
5 changed files with 24 additions and 3 deletions

View File

@ -471,7 +471,7 @@ void ActionsMatcher::visit(const ASTFunction & node, const ASTPtr & ast, Data &
argument_types.push_back(column.type); argument_types.push_back(column.type);
argument_names.push_back(column.name); argument_names.push_back(column.name);
} }
else if (identifier && node.name == "joinGet" && arg == 0) else if (identifier && functionIsJoinGetOrDictGet(node.name) && arg == 0)
{ {
auto table_id = IdentifierSemantic::extractDatabaseAndTable(*identifier); auto table_id = IdentifierSemantic::extractDatabaseAndTable(*identifier);
table_id = data.context.resolveStorageID(table_id, Context::ResolveOrdinary); 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( ColumnWithTypeAndName column(
ColumnConst::create(std::move(column_string), 1), ColumnConst::create(std::move(column_string), 1),
std::make_shared<DataTypeString>(), std::make_shared<DataTypeString>(),
data.getUniqueName("__joinGet")); data.getUniqueName("__joinGetOrDictGet"));
data.addAction(ExpressionAction::addColumn(column)); data.addAction(ExpressionAction::addColumn(column));
argument_types.push_back(column.type); argument_types.push_back(column.type);
argument_names.push_back(column.name); argument_names.push_back(column.name);

View File

@ -44,7 +44,7 @@ void MarkTableIdentifiersMatcher::visit(const ASTFunction & func, ASTPtr &, Data
} }
// first argument of joinGet can be a table identifier // first argument of joinGet can be a table identifier
if (func.name == "joinGet") if (functionIsJoinGetOrDictGet(func.name))
{ {
auto & ast = func.arguments->children.at(0); auto & ast = func.arguments->children.at(0);
if (auto opt_name = tryGetIdentifierName(ast)) if (auto opt_name = tryGetIdentifierName(ast))

View File

@ -1,5 +1,7 @@
#pragma once #pragma once
#include <Common/StringUtils/StringUtils.h>
namespace DB namespace DB
{ {
@ -18,4 +20,9 @@ inline bool functionIsLikeOperator(const std::string & name)
return name == "like" || name == "notLike"; return name == "like" || name == "notLike";
} }
inline bool functionIsJoinGetOrDictGet(const std::string & name)
{
return name == "joinGet" || startsWith(name, "dictGet");
}
} }

View File

@ -17,3 +17,7 @@ database_for_dict dict1 ComplexKeyCache
database_for_dict dict2 Hashed database_for_dict dict2 Hashed
6 6
6 6
6
6
6
6

View File

@ -105,6 +105,16 @@ LAYOUT(HASHED());
SELECT dictGetString('database_for_dict.dict3', 'some_column', toUInt64(12)); SELECT dictGetString('database_for_dict.dict3', 'some_column', toUInt64(12));
-- dictGet with table name
USE database_for_dict;
SELECT dictGetString(dict3, 'some_column', toUInt64(12));
SELECT dictGetString(database_for_dict.dict3, 'some_column', toUInt64(12));
SELECT dictGetString(default.dict3, 'some_column', toUInt64(12)); -- {serverError 36}
SELECT dictGet(dict3, 'some_column', toUInt64(12));
SELECT dictGet(database_for_dict.dict3, 'some_column', toUInt64(12));
SELECT dictGet(default.dict3, 'some_column', toUInt64(12)); -- {serverError 36}
USE default;
DROP TABLE database_for_dict.table_for_dict; DROP TABLE database_for_dict.table_for_dict;
SYSTEM RELOAD DICTIONARIES; -- {serverError 60} SYSTEM RELOAD DICTIONARIES; -- {serverError 60}