mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 23:21:59 +00:00
Fixed error with alias substitution [#CLICKHOUSE-2986].
This commit is contained in:
parent
3a86673aea
commit
eb88391655
@ -1009,8 +1009,10 @@ void ExpressionAnalyzer::normalizeTreeImpl(
|
||||
/// rewrite rules that act when you go from top to bottom.
|
||||
bool replaced = false;
|
||||
|
||||
ASTFunction * func_node = typeid_cast<ASTFunction *>(ast.get());
|
||||
if (func_node)
|
||||
ASTIdentifier * identifier_node = nullptr;
|
||||
ASTFunction * func_node = nullptr;
|
||||
|
||||
if ((func_node = typeid_cast<ASTFunction *>(ast.get())))
|
||||
{
|
||||
/** Is there a column in the table whose name fully matches the function entry?
|
||||
* For example, in the table there is a column "domain(URL)", and we requested domain(URL).
|
||||
@ -1048,13 +1050,13 @@ void ExpressionAnalyzer::normalizeTreeImpl(
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (ASTIdentifier * node = typeid_cast<ASTIdentifier *>(ast.get()))
|
||||
else if ((identifier_node = typeid_cast<ASTIdentifier *>(ast.get())))
|
||||
{
|
||||
if (node->kind == ASTIdentifier::Column)
|
||||
if (identifier_node->kind == ASTIdentifier::Column)
|
||||
{
|
||||
/// If it is an alias, but not a parent alias (for constructs like "SELECT column + 1 AS column").
|
||||
Aliases::const_iterator jt = aliases.find(node->name);
|
||||
if (jt != aliases.end() && current_alias != node->name)
|
||||
Aliases::const_iterator jt = aliases.find(identifier_node->name);
|
||||
if (jt != aliases.end() && current_alias != identifier_node->name)
|
||||
{
|
||||
/// Let's replace it with the corresponding tree node.
|
||||
if (current_asts.count(jt->second.get()))
|
||||
@ -1116,7 +1118,7 @@ void ExpressionAnalyzer::normalizeTreeImpl(
|
||||
return;
|
||||
}
|
||||
|
||||
/// Recurring calls. Don't go into subqueries.
|
||||
/// Recurring calls. Don't go into subqueries. Don't go into components of compound identifiers.
|
||||
/// We also do not go to the left argument of lambda expressions, so as not to replace the formal parameters
|
||||
/// on aliases in expressions of the form 123 AS x, arrayMap(x -> 1, [2]).
|
||||
|
||||
@ -1134,6 +1136,9 @@ void ExpressionAnalyzer::normalizeTreeImpl(
|
||||
normalizeTreeImpl(child, finished_asts, current_asts, current_alias, level + 1);
|
||||
}
|
||||
}
|
||||
else if (identifier_node)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
for (auto & child : ast->children)
|
||||
|
@ -0,0 +1,2 @@
|
||||
1
|
||||
1
|
@ -0,0 +1,5 @@
|
||||
DROP TABLE IF EXISTS test.nested;
|
||||
CREATE TABLE test.nested (n Nested(x UInt8)) ENGINE = Memory;
|
||||
INSERT INTO test.nested VALUES ([1, 2]);
|
||||
SELECT 1 AS x FROM remote('127.0.0.1', test.nested) ARRAY JOIN n.x;
|
||||
DROP TABLE test.nested;
|
Loading…
Reference in New Issue
Block a user