1 | #include <AggregateFunctions/AggregateFunctionFactory.h> |
2 | #include <AggregateFunctions/Helpers.h> |
3 | #include <AggregateFunctions/FactoryHelpers.h> |
4 | #include <DataTypes/DataTypeAggregateFunction.h> |
5 | #include "registerAggregateFunctions.h" |
6 | |
7 | // TODO include this last because of a broken roaring header. See the comment |
8 | // inside. |
9 | #include <AggregateFunctions/AggregateFunctionGroupBitmap.h> |
10 | |
11 | namespace DB |
12 | { |
13 | |
14 | namespace |
15 | { |
16 | |
17 | template <template <typename> class Data> |
18 | AggregateFunctionPtr createAggregateFunctionBitmap(const std::string & name, const DataTypes & argument_types, const Array & parameters) |
19 | { |
20 | assertNoParameters(name, parameters); |
21 | assertUnary(name, argument_types); |
22 | |
23 | if (!argument_types[0]->canBeUsedInBitOperations()) |
24 | throw Exception("The type " + argument_types[0]->getName() + " of argument for aggregate function " + name |
25 | + " is illegal, because it cannot be used in Bitmap operations" , |
26 | ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT); |
27 | |
28 | AggregateFunctionPtr res(createWithUnsignedIntegerType<AggregateFunctionBitmap, Data>(*argument_types[0], argument_types[0])); |
29 | |
30 | if (!res) |
31 | throw Exception("Illegal type " + argument_types[0]->getName() + " of argument for aggregate function " + name, ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT); |
32 | |
33 | return res; |
34 | } |
35 | |
36 | template <template <typename, typename> class AggregateFunctionTemplate> |
37 | AggregateFunctionPtr createAggregateFunctionBitmapL2(const std::string & name, const DataTypes & argument_types, const Array & parameters) |
38 | { |
39 | assertNoParameters(name, parameters); |
40 | assertUnary(name, argument_types); |
41 | DataTypePtr argument_type_ptr = argument_types[0]; |
42 | WhichDataType which(*argument_type_ptr); |
43 | if (which.idx != TypeIndex::AggregateFunction) |
44 | throw Exception("Illegal type " + argument_types[0]->getName() + " of argument for aggregate function " + name, ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT); |
45 | |
46 | const DataTypeAggregateFunction& datatype_aggfunc = dynamic_cast<const DataTypeAggregateFunction&>(*argument_type_ptr); |
47 | AggregateFunctionPtr aggfunc = datatype_aggfunc.getFunction(); |
48 | argument_type_ptr = aggfunc->getArgumentTypes()[0]; |
49 | AggregateFunctionPtr res(createWithUnsignedIntegerType<AggregateFunctionTemplate, AggregateFunctionGroupBitmapData>(*argument_type_ptr, argument_type_ptr)); |
50 | if (!res) |
51 | throw Exception("Illegal type " + argument_types[0]->getName() + " of argument for aggregate function " + name, ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT); |
52 | |
53 | return res; |
54 | } |
55 | |
56 | } |
57 | |
58 | void registerAggregateFunctionsBitmap(AggregateFunctionFactory & factory) |
59 | { |
60 | factory.registerFunction("groupBitmap" , createAggregateFunctionBitmap<AggregateFunctionGroupBitmapData>); |
61 | factory.registerFunction("groupBitmapAnd" , createAggregateFunctionBitmapL2<AggregateFunctionBitmapL2And>); |
62 | factory.registerFunction("groupBitmapOr" , createAggregateFunctionBitmapL2<AggregateFunctionBitmapL2Or>); |
63 | factory.registerFunction("groupBitmapXor" , createAggregateFunctionBitmapL2<AggregateFunctionBitmapL2Xor>); |
64 | } |
65 | |
66 | } |
67 | |