2019-02-02 14:27:43 +00:00
|
|
|
#include <AggregateFunctions/AggregateFunctionFactory.h>
|
|
|
|
#include <AggregateFunctions/AggregateFunctionEntropy.h>
|
|
|
|
#include <AggregateFunctions/FactoryHelpers.h>
|
2019-02-09 20:17:20 +00:00
|
|
|
#include <AggregateFunctions/Helpers.h>
|
|
|
|
|
2019-02-02 14:27:43 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2021-05-26 11:32:14 +00:00
|
|
|
struct Settings;
|
2019-02-02 14:27:43 +00:00
|
|
|
|
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
|
|
|
extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
2021-06-07 00:15:11 +00:00
|
|
|
AggregateFunctionPtr createAggregateFunctionEntropy(
|
|
|
|
const std::string & name, const DataTypes & argument_types, const Array & parameters, const Settings *)
|
2019-02-02 14:27:43 +00:00
|
|
|
{
|
|
|
|
assertNoParameters(name, parameters);
|
|
|
|
if (argument_types.empty())
|
|
|
|
throw Exception("Incorrect number of arguments for aggregate function " + name,
|
|
|
|
ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
|
|
|
|
|
2019-02-09 20:17:20 +00:00
|
|
|
size_t num_args = argument_types.size();
|
|
|
|
if (num_args == 1)
|
2019-02-02 14:27:43 +00:00
|
|
|
{
|
2019-02-09 20:35:55 +00:00
|
|
|
/// Specialized implementation for single argument of numeric type.
|
2020-04-22 05:39:31 +00:00
|
|
|
if (auto * res = createWithNumericBasedType<AggregateFunctionEntropy>(*argument_types[0], argument_types))
|
2019-02-09 20:17:20 +00:00
|
|
|
return AggregateFunctionPtr(res);
|
2019-02-02 14:27:43 +00:00
|
|
|
}
|
|
|
|
|
2019-02-09 20:35:55 +00:00
|
|
|
/// Generic implementation for other types or for multiple arguments.
|
2019-02-11 19:26:32 +00:00
|
|
|
return std::make_shared<AggregateFunctionEntropy<UInt128>>(argument_types);
|
2019-02-02 14:27:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void registerAggregateFunctionEntropy(AggregateFunctionFactory & factory)
|
|
|
|
{
|
|
|
|
factory.registerFunction("entropy", createAggregateFunctionEntropy);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|