More fixes

This commit is contained in:
Ivan Lezhankin 2021-05-31 18:00:04 +03:00
parent 06a0ab12bc
commit 54a385d1b0
2 changed files with 10 additions and 9 deletions

View File

@ -80,20 +80,22 @@ void ApplyWithSubqueryVisitor::visit(ASTTableExpression & table, const Data & da
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))
{
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 (table_id.database_name.empty())
if (identifier->isShort())
{
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())
{
auto old_alias = func.arguments->children[1]->tryGetAlias();
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())
func.arguments->children[1]->setAlias(old_alias);
}

View File

@ -498,10 +498,9 @@ std::vector<TableNeededColumns> normalizeColumnNamesExtractNeeded(
if (got_alias)
{
auto alias = aliases.find(ident->name())->second;
bool alias_equals_column_name = alias->ptr()->getColumnNameWithoutAlias() == ident->getColumnNameWithoutAlias();
// FIXME: check test 01600_multiple_left_joins_with_aliases
// || (alias_table == IdentifierSemantic::getTableName(ident->ptr())
// && ident->shortName() == alias->as<ASTIdentifier>()->shortName()))
auto alias_ident = alias->clone();
alias_ident->as<ASTIdentifier>()->restoreTable();
bool alias_equals_column_name = alias_ident->getColumnNameWithoutAlias() == ident->getColumnNameWithoutAlias();
if (!alias_equals_column_name)
throw Exception("Alias clashes with qualified column '" + ident->name() + "'", ErrorCodes::AMBIGUOUS_COLUMN_NAME);
}