Merge pull request #39850 from kitaisreal/select-query-has-join-method

Add hasJoin method into ASTSelectQuery
This commit is contained in:
Maksim Kita 2022-08-03 18:50:25 +02:00 committed by GitHub
commit e6efb47aa3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 1 deletions

View File

@ -344,6 +344,25 @@ const ASTTablesInSelectQueryElement * ASTSelectQuery::join() const
return getFirstTableJoin(*this);
}
bool ASTSelectQuery::hasJoin() const
{
if (!tables())
return false;
const auto & tables_in_select_query = tables()->as<ASTTablesInSelectQuery &>();
if (tables_in_select_query.children.empty())
return false;
for (const auto & child : tables_in_select_query.children)
{
const auto & tables_element = child->as<ASTTablesInSelectQueryElement &>();
if (tables_element.table_join)
return true;
}
return false;
}
static String getTableExpressionAlias(const ASTTableExpression * table_expression)
{
if (table_expression->subquery)

View File

@ -131,6 +131,7 @@ public:
std::pair<ASTPtr, bool> arrayJoinExpressionList() const;
const ASTTablesInSelectQueryElement * join() const;
bool hasJoin() const;
bool final() const;
bool withFill() const;
void replaceDatabaseAndTable(const String & database_name, const String & table_name);

View File

@ -5489,7 +5489,7 @@ std::optional<ProjectionCandidate> MergeTreeData::getQueryProcessingStageWithAgg
// In order to properly analyze joins, aliases should be recognized. However, aliases get lost during projection analysis.
// Let's disable projection if there are any JOIN clauses.
// TODO: We need a better identifier resolution mechanism for projection analysis.
if (select_query->join())
if (select_query->hasJoin())
return std::nullopt;
// INTERPOLATE expressions may include aliases, so aliases should be preserved