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,11 +546,14 @@ std::vector<TableNeededColumns> normalizeColumnNamesExtractNeeded(
{ {
auto alias = aliases.find(ident->name())->second; auto alias = aliases.find(ident->name())->second;
auto alias_ident = alias->clone(); auto alias_ident = alias->clone();
alias_ident->as<ASTIdentifier>()->restoreTable(); if (auto * alias_ident_typed = alias_ident->as<ASTIdentifier>())
{
alias_ident_typed->restoreTable();
bool alias_equals_column_name = alias_ident->getColumnNameWithoutAlias() == ident->getColumnNameWithoutAlias(); bool alias_equals_column_name = alias_ident->getColumnNameWithoutAlias() == ident->getColumnNameWithoutAlias();
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);
} }
}
String short_name = ident->shortName(); String short_name = ident->shortName();
String original_long_name; String original_long_name;
if (public_identifiers.contains(ident)) if (public_identifiers.contains(ident))

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 COLUMNS('test') FROM
(SELECT 1 AS id, 'a' AS test) a (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, 'b' AS test) b ON b.id = a.id