Fix nullptr dereference in collectScopeValidIdentifiersForTypoCorrection

This commit is contained in:
vdimir 2022-11-15 12:36:28 +00:00
parent ebde28bc50
commit d7c882951f
No known key found for this signature in database
GPG Key ID: 6EE4CE2BEDC51862
3 changed files with 22 additions and 1 deletions

View File

@ -1517,6 +1517,7 @@ void QueryAnalyzer::collectScopeValidIdentifiersForTypoCorrection(
{
for (const auto & [name, expression] : scope.alias_name_to_expression_node)
{
assert(expression);
auto expression_identifier = Identifier(name);
valid_identifiers_result.insert(expression_identifier);
@ -2170,7 +2171,24 @@ QueryTreeNodePtr QueryAnalyzer::tryResolveIdentifierFromAliases(const Identifier
auto & alias_identifier_node = it->second->as<IdentifierNode &>();
auto identifier = alias_identifier_node.getIdentifier();
auto lookup_result = tryResolveIdentifier(IdentifierLookup{identifier, identifier_lookup.lookup_context}, scope, identifier_resolve_settings);
it->second = lookup_result.resolved_identifier;
if (lookup_result.isResolved())
{
it->second = lookup_result.resolved_identifier;
}
else
{
alias_name_to_node_map.erase(it);
std::unordered_set<Identifier> valid_identifiers;
collectScopeWithParentScopesValidIdentifiersForTypoCorrection(identifier, scope, true, false, false, valid_identifiers);
auto hints = collectIdentifierTypoHints(identifier, valid_identifiers);
throw Exception(ErrorCodes::UNKNOWN_IDENTIFIER, "Unknown {} identifier '{}' in scope {}{}",
toStringLowercase(IdentifierLookupContext::EXPRESSION),
identifier.getFullName(),
scope.scope_node->formatASTForErrorMessage(),
getHintsErrorMessageSuffix(hints));
}
/** During collection of aliases if node is identifier and has alias, we cannot say if it is
* column or function node. Check QueryExpressionsAliasVisitor documentation for clarification.

View File

@ -0,0 +1,3 @@
SET allow_experimental_analyzer = 1;
SELECT min(b), x AS b FROM (SELECT max(number) FROM numbers(1)); -- { serverError UNKNOWN_IDENTIFIER }