2019-01-31 13:26:11 +00:00
|
|
|
#include <AggregateFunctions/AggregateFunctionFactory.h>
|
|
|
|
#include <AggregateFunctions/AggregateFunctionGroupBitmap.h>
|
|
|
|
#include <AggregateFunctions/Helpers.h>
|
|
|
|
#include <AggregateFunctions/FactoryHelpers.h>
|
2019-09-19 09:20:49 +00:00
|
|
|
#include <DataTypes/DataTypeAggregateFunction.h>
|
2019-01-31 13:26:11 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
|
|
|
template <template <typename> class Data>
|
|
|
|
AggregateFunctionPtr createAggregateFunctionBitmap(const std::string & name, const DataTypes & argument_types, const Array & parameters)
|
|
|
|
{
|
|
|
|
assertNoParameters(name, parameters);
|
|
|
|
assertUnary(name, argument_types);
|
|
|
|
|
|
|
|
if (!argument_types[0]->canBeUsedInBitOperations())
|
|
|
|
throw Exception("The type " + argument_types[0]->getName() + " of argument for aggregate function " + name
|
|
|
|
+ " is illegal, because it cannot be used in Bitmap operations",
|
|
|
|
ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
|
|
|
|
|
2019-02-14 11:51:13 +00:00
|
|
|
AggregateFunctionPtr res(createWithUnsignedIntegerType<AggregateFunctionBitmap, Data>(*argument_types[0], argument_types[0]));
|
2019-01-31 13:26:11 +00:00
|
|
|
|
|
|
|
if (!res)
|
|
|
|
throw Exception("Illegal type " + argument_types[0]->getName() + " of argument for aggregate function " + name, ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2019-09-19 09:20:49 +00:00
|
|
|
template <template <typename, typename> class AggregateFunctionTemplate>
|
|
|
|
AggregateFunctionPtr createAggregateFunctionBitmapL2(const std::string & name, const DataTypes & argument_types, const Array & parameters)
|
|
|
|
{
|
|
|
|
assertNoParameters(name, parameters);
|
|
|
|
assertUnary(name, argument_types);
|
|
|
|
DataTypePtr argument_type_ptr = argument_types[0];
|
|
|
|
WhichDataType which(*argument_type_ptr);
|
|
|
|
if (which.idx == TypeIndex::AggregateFunction)
|
|
|
|
{
|
|
|
|
const DataTypeAggregateFunction& datatype_aggfunc = dynamic_cast<const DataTypeAggregateFunction&>(*argument_type_ptr);
|
|
|
|
AggregateFunctionPtr aggfunc = datatype_aggfunc.getFunction();
|
|
|
|
argument_type_ptr = aggfunc->getArgumentTypes()[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
AggregateFunctionPtr res(createWithUnsignedIntegerType<AggregateFunctionTemplate, AggregateFunctionGroupBitmapData>(*argument_type_ptr, argument_type_ptr));
|
|
|
|
|
|
|
|
if (!res)
|
|
|
|
throw Exception("Illegal type " + argument_types[0]->getName() + " of argument for aggregate function " + name, ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2019-01-31 13:26:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void registerAggregateFunctionsBitmap(AggregateFunctionFactory & factory)
|
|
|
|
{
|
|
|
|
factory.registerFunction("groupBitmap", createAggregateFunctionBitmap<AggregateFunctionGroupBitmapData>);
|
2019-09-19 09:20:49 +00:00
|
|
|
factory.registerFunction("groupBitmapAnd", createAggregateFunctionBitmapL2<AggregateFunctionBitmapL2And>);
|
|
|
|
factory.registerFunction("groupBitmapOr", createAggregateFunctionBitmapL2<AggregateFunctionBitmapL2Or>);
|
|
|
|
factory.registerFunction("groupBitmapXor", createAggregateFunctionBitmapL2<AggregateFunctionBitmapL2Xor>);
|
2019-01-31 13:26:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|