1 | #include <AggregateFunctions/AggregateFunctionFactory.h> |
2 | #include <AggregateFunctions/AggregateFunctionBitwise.h> |
3 | #include <AggregateFunctions/Helpers.h> |
4 | #include <AggregateFunctions/FactoryHelpers.h> |
5 | #include "registerAggregateFunctions.h" |
6 | |
7 | |
8 | namespace DB |
9 | { |
10 | |
11 | namespace |
12 | { |
13 | |
14 | template <template <typename> class Data> |
15 | AggregateFunctionPtr createAggregateFunctionBitwise(const std::string & name, const DataTypes & argument_types, const Array & parameters) |
16 | { |
17 | assertNoParameters(name, parameters); |
18 | assertUnary(name, argument_types); |
19 | |
20 | if (!argument_types[0]->canBeUsedInBitOperations()) |
21 | throw Exception("The type " + argument_types[0]->getName() + " of argument for aggregate function " + name |
22 | + " is illegal, because it cannot be used in bitwise operations" , |
23 | ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT); |
24 | |
25 | AggregateFunctionPtr res(createWithUnsignedIntegerType<AggregateFunctionBitwise, Data>(*argument_types[0], argument_types[0])); |
26 | |
27 | if (!res) |
28 | throw Exception("Illegal type " + argument_types[0]->getName() + " of argument for aggregate function " + name, ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT); |
29 | |
30 | return res; |
31 | } |
32 | |
33 | } |
34 | |
35 | void registerAggregateFunctionsBitwise(AggregateFunctionFactory & factory) |
36 | { |
37 | factory.registerFunction("groupBitOr" , createAggregateFunctionBitwise<AggregateFunctionGroupBitOrData>); |
38 | factory.registerFunction("groupBitAnd" , createAggregateFunctionBitwise<AggregateFunctionGroupBitAndData>); |
39 | factory.registerFunction("groupBitXor" , createAggregateFunctionBitwise<AggregateFunctionGroupBitXorData>); |
40 | |
41 | /// Aliases for compatibility with MySQL. |
42 | factory.registerAlias("BIT_OR" , "groupBitOr" , AggregateFunctionFactory::CaseInsensitive); |
43 | factory.registerAlias("BIT_AND" , "groupBitAnd" , AggregateFunctionFactory::CaseInsensitive); |
44 | factory.registerAlias("BIT_XOR" , "groupBitXor" , AggregateFunctionFactory::CaseInsensitive); |
45 | } |
46 | |
47 | } |
48 | |