Merge pull request #42883 from zzsmdfj/fix_join_to_subqueries_null_pointer

Fix  join to subqueries rewriter null pointer
This commit is contained in:
Nikolay Degterinsky 2022-11-04 19:56:40 +03:00 committed by GitHub
commit 6995fa1afd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 4 deletions

View File

@ -546,10 +546,13 @@ std::vector<TableNeededColumns> normalizeColumnNamesExtractNeeded(
{
auto alias = aliases.find(ident->name())->second;
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);
if (auto * alias_ident_typed = alias_ident->as<ASTIdentifier>())
{
alias_ident_typed->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);
}
}
String short_name = ident->shortName();
String original_long_name;

View File

@ -1,3 +1,8 @@
SELECT (if(a.test == 'a', b.test, c.test)) as `a.test` FROM
(SELECT 1 AS id, 'a' AS test) a
LEFT JOIN (SELECT 1 AS id, 'b' AS test) b ON b.id = a.id
LEFT JOIN (SELECT 1 AS id, 'c' AS test) c ON c.id = a.id;
SELECT COLUMNS('test') FROM
(SELECT 1 AS id, 'a' AS test) a
LEFT JOIN (SELECT 1 AS id, 'b' AS test) b ON b.id = a.id