1 | #pragma once |
2 | |
3 | #include <Core/Field.h> |
4 | #include <DataTypes/IDataType.h> |
5 | #include <IO/WriteHelpers.h> |
6 | |
7 | |
8 | namespace DB |
9 | { |
10 | |
11 | namespace ErrorCodes |
12 | { |
13 | extern const int AGGREGATE_FUNCTION_DOESNT_ALLOW_PARAMETERS; |
14 | extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH; |
15 | } |
16 | |
17 | inline void assertNoParameters(const std::string & name, const Array & parameters) |
18 | { |
19 | if (!parameters.empty()) |
20 | throw Exception("Aggregate function " + name + " cannot have parameters" , ErrorCodes::AGGREGATE_FUNCTION_DOESNT_ALLOW_PARAMETERS); |
21 | } |
22 | |
23 | inline void assertUnary(const std::string & name, const DataTypes & argument_types) |
24 | { |
25 | if (argument_types.size() != 1) |
26 | throw Exception("Aggregate function " + name + " requires single argument" , ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH); |
27 | } |
28 | |
29 | inline void assertBinary(const std::string & name, const DataTypes & argument_types) |
30 | { |
31 | if (argument_types.size() != 2) |
32 | throw Exception("Aggregate function " + name + " requires two arguments" , ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH); |
33 | } |
34 | |
35 | template<std::size_t maximal_arity> |
36 | inline void assertArityAtMost(const std::string & name, const DataTypes & argument_types) |
37 | { |
38 | if (argument_types.size() <= maximal_arity) |
39 | return; |
40 | |
41 | if constexpr (maximal_arity == 0) |
42 | throw Exception("Aggregate function " + name + " cannot have arguments" , |
43 | ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH); |
44 | |
45 | if constexpr (maximal_arity == 1) |
46 | throw Exception("Aggregate function " + name + " requires zero or one argument" , |
47 | ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH); |
48 | |
49 | throw Exception("Aggregate function " + name + " requires at most " + toString(maximal_arity) + " arguments" , |
50 | ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH); |
51 | } |
52 | |
53 | } |
54 | |