diff --git a/dbms/src/Common/ErrorCodes.cpp b/dbms/src/Common/ErrorCodes.cpp index 513a26987e0..f151f59f7f1 100644 --- a/dbms/src/Common/ErrorCodes.cpp +++ b/dbms/src/Common/ErrorCodes.cpp @@ -393,6 +393,7 @@ namespace ErrorCodes extern const int REPLICA_STATUS_CHANGED = 416; extern const int EXPECTED_ALL_OR_ANY = 417; extern const int UNKNOWN_JOIN_STRICTNESS = 418; + extern const int CANNOT_ADD_DIFFERENT_AGGREGATE_STATES = 419; extern const int KEEPER_EXCEPTION = 999; extern const int POCO_EXCEPTION = 1000; diff --git a/dbms/src/Functions/FunctionsArithmetic.h b/dbms/src/Functions/FunctionsArithmetic.h index 98f574dff13..d16da285976 100644 --- a/dbms/src/Functions/FunctionsArithmetic.h +++ b/dbms/src/Functions/FunctionsArithmetic.h @@ -44,6 +44,7 @@ namespace ErrorCodes extern const int LOGICAL_ERROR; extern const int TOO_LESS_ARGUMENTS_FOR_FUNCTION; extern const int DECIMAL_OVERFLOW; + extern const int CANNOT_ADD_DIFFERENT_AGGREGATE_STATES; } @@ -1186,11 +1187,11 @@ public: if (new_arguments[0]->getFunctionName() != new_arguments[1]->getFunctionName()) throw Exception("Cannot add aggregate states of different functions: " - + new_arguments[0]->getFunctionName() + " and " + new_arguments[1]->getFunctionName(), ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT); + + new_arguments[0]->getFunctionName() + " and " + new_arguments[1]->getFunctionName(), ErrorCodes::CANNOT_ADD_DIFFERENT_AGGREGATE_STATES); if (new_arguments[0]->getReturnType()->getName() != new_arguments[1]->getReturnType()->getName()) throw Exception("Cannot add aggregate states with different return types: " - + new_arguments[0]->getReturnType()->getName() + " and " + new_arguments[1]->getReturnType()->getName(), ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT); + + new_arguments[0]->getReturnType()->getName() + " and " + new_arguments[1]->getReturnType()->getName(), ErrorCodes::CANNOT_ADD_DIFFERENT_AGGREGATE_STATES); return arguments[0]; } diff --git a/dbms/tests/queries/0_stateless/00705_aggregate_states_addition.sql b/dbms/tests/queries/0_stateless/00705_aggregate_states_addition.sql index 37eb6caf6fe..df071080cb4 100644 --- a/dbms/tests/queries/0_stateless/00705_aggregate_states_addition.sql +++ b/dbms/tests/queries/0_stateless/00705_aggregate_states_addition.sql @@ -8,8 +8,8 @@ INSERT INTO add_aggregate VALUES(3, 1); SELECT countMerge(x + y) FROM (SELECT countState(a) as x, countState(b) as y from add_aggregate); SELECT sumMerge(x + y), sumMerge(x), sumMerge(y) FROM (SELECT sumState(a) as x, sumState(b) as y from add_aggregate); -SELECT sumMerge(x) FROM (SELECT sumState(a) + countState(b) as x FROM add_aggregate); -- { serverError 43 } -SELECT sumMerge(x) FROM (SELECT sumState(a) + sumState(toInt32(b)) as x FROM add_aggregate); -- { serverError 43 } +SELECT sumMerge(x) FROM (SELECT sumState(a) + countState(b) as x FROM add_aggregate); -- { serverError 419 } +SELECT sumMerge(x) FROM (SELECT sumState(a) + sumState(toInt32(b)) as x FROM add_aggregate); -- { serverError 419 } SELECT minMerge(x) FROM (SELECT minState(a) + minState(b) as x FROM add_aggregate);