From b642bd494dea25f1e289a901225f6461832f529f Mon Sep 17 00:00:00 2001 From: Mark Papadakis Date: Thu, 1 Oct 2020 12:03:19 +0300 Subject: [PATCH] Update ActionsVisitor.cpp Refactoring: eliminated a local, throws if it matches the column name as opposed to iterating to the end of the container. --- src/Interpreters/ActionsVisitor.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/Interpreters/ActionsVisitor.cpp b/src/Interpreters/ActionsVisitor.cpp index 1d524669fd9..2236b35d458 100644 --- a/src/Interpreters/ActionsVisitor.cpp +++ b/src/Interpreters/ActionsVisitor.cpp @@ -509,15 +509,14 @@ void ActionsMatcher::visit(const ASTIdentifier & identifier, const ASTPtr & ast, { /// The requested column is not in the block. /// If such a column exists in the table, then the user probably forgot to surround it with an aggregate function or add it to GROUP BY. - - bool found = false; - for (const auto & column_name_type : data.source_columns) - if (column_name_type.name == column_name.get(ast)) - found = true; - - if (found) - throw Exception("Column " + backQuote(column_name.get(ast)) + " is not under aggregate function and not in GROUP BY", + + for (const auto & column_name_type : data.source_columns) { + if (column_name_type.name == column_name.get(ast)) { + throw Exception("Column " + backQuote(column_name.get(ast)) + " is not under aggregate function and not in GROUP BY", ErrorCodes::NOT_AN_AGGREGATE); + } + } + /// Special check for WITH statement alias. Add alias action to be able to use this alias. if (identifier.prefer_alias_to_column_name && !identifier.alias.empty())