ClickHouse/dbms/AggregateFunctions/AggregateFunctionEntropy.cpp

46 lines
1.3 KiB
C++
Raw Normal View History

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-12-15 06:34:43 +00:00
#include "registerAggregateFunctions.h"
2019-02-09 20:17:20 +00:00
2019-02-02 14:27:43 +00:00
namespace DB
{
namespace ErrorCodes
{
extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH;
}
namespace
{
AggregateFunctionPtr createAggregateFunctionEntropy(const std::string & name, const DataTypes & argument_types, const Array & parameters)
{
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.
2019-02-11 19:26:32 +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);
}
}