2018-06-22 18:30:09 +00:00
|
|
|
#include "AggregateFunctionHistogram.h"
|
|
|
|
#include "AggregateFunctionFactory.h"
|
|
|
|
#include "FactoryHelpers.h"
|
|
|
|
#include "Helpers.h"
|
|
|
|
|
|
|
|
#include <Common/FieldVisitors.h>
|
|
|
|
|
|
|
|
namespace DB {
|
|
|
|
|
2018-06-22 14:56:53 +00:00
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
|
|
|
extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH;
|
|
|
|
extern const int ILLEGAL_TYPE_OF_ARGUMENT;
|
|
|
|
extern const int BAD_ARGUMENTS;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2018-06-22 18:30:09 +00:00
|
|
|
AggregateFunctionPtr createAggregateFunctionHistogram(const std::string & name, const DataTypes & arguments, const Array & params)
|
|
|
|
{
|
|
|
|
if (params.size() != 1)
|
2018-06-22 14:56:53 +00:00
|
|
|
throw Exception("Function " + name + " requires bins count", ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
|
2018-06-22 18:30:09 +00:00
|
|
|
|
2018-06-22 14:56:53 +00:00
|
|
|
UInt32 bins_count = applyVisitor(FieldVisitorConvertToNumber<UInt32>(), params[0]);
|
2018-06-22 18:30:09 +00:00
|
|
|
|
2018-06-22 14:56:53 +00:00
|
|
|
if (bins_count == 0)
|
|
|
|
throw Exception("Bin count should be positive", ErrorCodes::BAD_ARGUMENTS);
|
2018-06-22 18:30:09 +00:00
|
|
|
|
2018-06-22 14:56:53 +00:00
|
|
|
assertUnary(name, arguments);
|
2018-06-22 18:30:09 +00:00
|
|
|
AggregateFunctionPtr res(createWithNumericType<AggregateFunctionHistogram>(*arguments[0], bins_count));
|
|
|
|
|
2018-06-22 14:56:53 +00:00
|
|
|
if (!res)
|
|
|
|
throw Exception("Illegal type " + arguments[0]->getName() + " of argument for aggregate function " + name, ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
|
|
|
|
|
2018-06-22 18:30:09 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2018-06-22 14:56:53 +00:00
|
|
|
}
|
|
|
|
|
2018-06-22 18:30:09 +00:00
|
|
|
void registerAggregateFunctionHistogram(AggregateFunctionFactory & factory)
|
|
|
|
{
|
|
|
|
factory.registerFunction("histogram", createAggregateFunctionHistogram);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|