1#include <AggregateFunctions/AggregateFunctionFactory.h>
2#include <AggregateFunctions/AggregateFunctionEntropy.h>
3#include <AggregateFunctions/FactoryHelpers.h>
4#include <AggregateFunctions/Helpers.h>
5#include "registerAggregateFunctions.h"
6
7
8namespace DB
9{
10
11namespace ErrorCodes
12{
13 extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH;
14}
15
16namespace
17{
18
19AggregateFunctionPtr createAggregateFunctionEntropy(const std::string & name, const DataTypes & argument_types, const Array & parameters)
20{
21 assertNoParameters(name, parameters);
22 if (argument_types.empty())
23 throw Exception("Incorrect number of arguments for aggregate function " + name,
24 ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
25
26 size_t num_args = argument_types.size();
27 if (num_args == 1)
28 {
29 /// Specialized implementation for single argument of numeric type.
30 if (auto res = createWithNumericBasedType<AggregateFunctionEntropy>(*argument_types[0], argument_types))
31 return AggregateFunctionPtr(res);
32 }
33
34 /// Generic implementation for other types or for multiple arguments.
35 return std::make_shared<AggregateFunctionEntropy<UInt128>>(argument_types);
36}
37
38}
39
40void registerAggregateFunctionEntropy(AggregateFunctionFactory & factory)
41{
42 factory.registerFunction("entropy", createAggregateFunctionEntropy);
43}
44
45}
46