mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 15:12:02 +00:00
init
This commit is contained in:
parent
ed4d955df6
commit
bbeb3f61e5
@ -114,17 +114,33 @@ void QueryAliasesMatcher<T>::visit(const ASTSubquery & const_subquery, const AST
|
||||
subquery.prefer_alias_to_column_name = true;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool QueryAliasesMatcher<T>::checkIfNamesAreSame(Data & data, const ASTPtr & ast)
|
||||
{
|
||||
String name = ast->getColumnName();
|
||||
for (const auto & obj : data)
|
||||
{
|
||||
if (obj.second->getColumnName() == name)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void QueryAliasesMatcher<T>::visitOther(const ASTPtr & ast, Data & data)
|
||||
{
|
||||
auto & aliases = data;
|
||||
String alias = ast->tryGetAlias();
|
||||
|
||||
if (!alias.empty())
|
||||
{
|
||||
if (aliases.contains(alias) && ast->getTreeHash(/*ignore_aliases=*/ true) != aliases[alias]->getTreeHash(/*ignore_aliases=*/ true))
|
||||
throw Exception(wrongAliasMessage(ast, aliases[alias], alias), ErrorCodes::MULTIPLE_EXPRESSIONS_FOR_ALIAS);
|
||||
{
|
||||
if (checkIfNamesAreSame(aliases, ast))
|
||||
throw Exception(wrongAliasMessage(ast, aliases[alias], alias), ErrorCodes::MULTIPLE_EXPRESSIONS_FOR_ALIAS);
|
||||
}
|
||||
|
||||
aliases[alias] = ast;
|
||||
aliases[ast->getColumnNameWithoutAlias()] = ast;
|
||||
}
|
||||
|
||||
/** QueryAliasesVisitor is executed before ExecuteScalarSubqueriesVisitor.
|
||||
|
@ -38,6 +38,7 @@ private:
|
||||
static void visit(const ASTSubquery & subquery, const ASTPtr & ast, Data & data);
|
||||
static void visit(const ASTArrayJoin &, const ASTPtr & ast, Data & data);
|
||||
static void visitOther(const ASTPtr & ast, Data & data);
|
||||
static bool checkIfNamesAreSame(Data & data, const ASTPtr & ast);
|
||||
};
|
||||
|
||||
/// Visits AST nodes and collect their aliases in one map (with links to source nodes).
|
||||
|
Loading…
Reference in New Issue
Block a user