mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-13 09:52:38 +00:00
More fixes
This commit is contained in:
parent
06a0ab12bc
commit
54a385d1b0
@ -80,20 +80,22 @@ void ApplyWithSubqueryVisitor::visit(ASTTableExpression & table, const Data & da
|
|||||||
|
|
||||||
void ApplyWithSubqueryVisitor::visit(ASTFunction & func, const Data & data)
|
void ApplyWithSubqueryVisitor::visit(ASTFunction & func, const Data & data)
|
||||||
{
|
{
|
||||||
|
/// Special CTE case, where the right argument of IN is alias (ASTIdentifier) from WITH clause.
|
||||||
|
|
||||||
if (checkFunctionIsInOrGlobalInOperator(func))
|
if (checkFunctionIsInOrGlobalInOperator(func))
|
||||||
{
|
{
|
||||||
auto & ast = func.arguments->children.at(1);
|
auto & ast = func.arguments->children.at(1);
|
||||||
if (const auto * identifier = ast->as<ASTTableIdentifier>())
|
if (const auto * identifier = ast->as<ASTIdentifier>())
|
||||||
{
|
{
|
||||||
auto table_id = identifier->getTableId();
|
if (identifier->isShort())
|
||||||
if (table_id.database_name.empty())
|
|
||||||
{
|
{
|
||||||
auto subquery_it = data.subqueries.find(table_id.table_name);
|
auto name = identifier->shortName();
|
||||||
|
auto subquery_it = data.subqueries.find(name);
|
||||||
if (subquery_it != data.subqueries.end())
|
if (subquery_it != data.subqueries.end())
|
||||||
{
|
{
|
||||||
auto old_alias = func.arguments->children[1]->tryGetAlias();
|
auto old_alias = func.arguments->children[1]->tryGetAlias();
|
||||||
func.arguments->children[1] = subquery_it->second->clone();
|
func.arguments->children[1] = subquery_it->second->clone();
|
||||||
func.arguments->children[1]->as<ASTSubquery &>().cte_name = table_id.table_name;
|
func.arguments->children[1]->as<ASTSubquery &>().cte_name = name;
|
||||||
if (!old_alias.empty())
|
if (!old_alias.empty())
|
||||||
func.arguments->children[1]->setAlias(old_alias);
|
func.arguments->children[1]->setAlias(old_alias);
|
||||||
}
|
}
|
||||||
|
@ -498,10 +498,9 @@ std::vector<TableNeededColumns> normalizeColumnNamesExtractNeeded(
|
|||||||
if (got_alias)
|
if (got_alias)
|
||||||
{
|
{
|
||||||
auto alias = aliases.find(ident->name())->second;
|
auto alias = aliases.find(ident->name())->second;
|
||||||
bool alias_equals_column_name = alias->ptr()->getColumnNameWithoutAlias() == ident->getColumnNameWithoutAlias();
|
auto alias_ident = alias->clone();
|
||||||
// FIXME: check test 01600_multiple_left_joins_with_aliases
|
alias_ident->as<ASTIdentifier>()->restoreTable();
|
||||||
// || (alias_table == IdentifierSemantic::getTableName(ident->ptr())
|
bool alias_equals_column_name = alias_ident->getColumnNameWithoutAlias() == ident->getColumnNameWithoutAlias();
|
||||||
// && ident->shortName() == alias->as<ASTIdentifier>()->shortName()))
|
|
||||||
if (!alias_equals_column_name)
|
if (!alias_equals_column_name)
|
||||||
throw Exception("Alias clashes with qualified column '" + ident->name() + "'", ErrorCodes::AMBIGUOUS_COLUMN_NAME);
|
throw Exception("Alias clashes with qualified column '" + ident->name() + "'", ErrorCodes::AMBIGUOUS_COLUMN_NAME);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user