clickhouse: better error message when an aggregate function is missing. [#METR-9590]

This commit is contained in:
Michael Kolupaev 2014-01-13 11:29:24 +00:00
parent 841e866c68
commit 936fc15640
2 changed files with 23 additions and 1 deletions

View File

@ -220,6 +220,7 @@ namespace ErrorCodes
EMPTY_QUERY,
UNKNOWN_LOAD_BALANCING,
CANNOT_STATVFS,
NOT_AN_AGGREGATE,
POCO_EXCEPTION = 1000,
STD_EXCEPTION,

View File

@ -703,7 +703,28 @@ void ExpressionAnalyzer::getActionsImpl(ASTPtr ast, bool no_subqueries, bool onl
&& actions_stack.getSampleBlock().has(ast->getColumnName()))
return;
if (ASTFunction * node = dynamic_cast<ASTFunction *>(&*ast))
if (ASTIdentifier * node = dynamic_cast<ASTIdentifier *>(&*ast))
{
std::string name = node->getColumnName();
if (!only_consts && !actions_stack.getSampleBlock().has(name))
{
/// Запрошенного столбца нет в блоке.
/// Если такой столбец есть до агрегации, значит пользователь наверно забыл окружить его агрегатной функцией или добавить в GROUP BY.
bool found = false;
for (NamesAndTypesList::const_iterator it = columns_after_array_join.begin();
it != columns_after_array_join.end(); ++it)
if (it->first == name)
found = true;
if (found)
throw Exception("Column " + name + " is not under aggregate function and not in GROUP BY.",
ErrorCodes::NOT_AN_AGGREGATE);
else
throw Exception("Unknown identifier: " + name, ErrorCodes::UNKNOWN_IDENTIFIER);
}
}
else if (ASTFunction * node = dynamic_cast<ASTFunction *>(&*ast))
{
if (node->kind == ASTFunction::LAMBDA_EXPRESSION)
throw Exception("Unexpected expression", ErrorCodes::UNEXPECTED_EXPRESSION);