2014-11-21 12:29:33 +00:00
|
|
|
#pragma once
|
|
|
|
|
2015-12-23 05:31:51 +00:00
|
|
|
#include <DB/IO/WriteHelpers.h>
|
2014-11-21 12:29:33 +00:00
|
|
|
#include <DB/AggregateFunctions/IAggregateFunction.h>
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
template <typename T, typename Derived>
|
|
|
|
class IBinaryAggregateFunction : public IAggregateFunctionHelper<T>
|
|
|
|
{
|
2015-11-15 08:31:08 +00:00
|
|
|
private:
|
2014-11-21 12:29:33 +00:00
|
|
|
Derived & getDerived() { return static_cast<Derived &>(*this); }
|
|
|
|
const Derived & getDerived() const { return static_cast<const Derived &>(*this); }
|
|
|
|
|
|
|
|
public:
|
2015-11-15 08:31:08 +00:00
|
|
|
void setArguments(const DataTypes & arguments) override final
|
2014-11-21 12:29:33 +00:00
|
|
|
{
|
|
|
|
if (arguments.size() != 2)
|
|
|
|
throw Exception{
|
|
|
|
"Passed " + toString(arguments.size()) + " arguments to binary aggregate function " + this->getName(),
|
|
|
|
ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH
|
|
|
|
};
|
|
|
|
|
|
|
|
getDerived().setArgumentsImpl(arguments);
|
|
|
|
}
|
|
|
|
|
2016-09-19 22:30:40 +00:00
|
|
|
void add(AggregateDataPtr place, const IColumn ** columns, const size_t row_num, Arena * arena) const override final
|
2014-11-21 12:29:33 +00:00
|
|
|
{
|
2016-09-19 22:30:40 +00:00
|
|
|
getDerived().addImpl(place, *columns[0], *columns[1], row_num, arena);
|
2014-11-21 12:29:33 +00:00
|
|
|
}
|
2015-11-21 19:46:27 +00:00
|
|
|
|
2016-09-19 22:30:40 +00:00
|
|
|
static void addFree(const IAggregateFunction * that, AggregateDataPtr place, const IColumn ** columns, size_t row_num, Arena * arena)
|
2015-11-21 19:46:27 +00:00
|
|
|
{
|
2016-09-19 22:30:40 +00:00
|
|
|
static_cast<const Derived &>(*that).addImpl(place, *columns[0], *columns[1], row_num, arena);
|
2015-11-21 19:46:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
IAggregateFunction::AddFunc getAddressOfAddFunction() const override final { return &addFree; }
|
2014-11-21 12:29:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|