ClickHouse/dbms/include/DB/AggregateFunctions/INullaryAggregateFunction.h

47 lines
1.5 KiB
C++
Raw Normal View History

2011-09-19 03:40:05 +00:00
#pragma once
2015-12-23 05:31:51 +00:00
#include <DB/IO/WriteHelpers.h>
2011-09-19 03:40:05 +00:00
#include <DB/AggregateFunctions/IAggregateFunction.h>
namespace DB
{
/** Interface for aggregate functions taking zero number of arguments. For example, this is 'count' aggregate function.
2011-09-19 03:40:05 +00:00
*/
template <typename T, typename Derived>
class INullaryAggregateFunction : public IAggregateFunctionHelper<T>
2011-09-19 03:40:05 +00:00
{
private:
Derived & getDerived() { return static_cast<Derived &>(*this); }
const Derived & getDerived() const { return static_cast<const Derived &>(*this); }
2011-09-19 03:40:05 +00:00
public:
/// By default, checks that number of arguments is zero. You could override if you would like to allow to have ignored arguments.
void setArguments(const DataTypes & arguments) override
2011-09-19 03:40:05 +00:00
{
if (arguments.size() != 0)
2013-06-21 20:34:19 +00:00
throw Exception("Passed " + toString(arguments.size()) + " arguments to nullary aggregate function " + this->getName(),
2011-09-19 03:40:05 +00:00
ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
}
/// Accumulate a value.
void add(AggregateDataPtr place, const IColumn ** columns, size_t row_num, Arena *) const override final
2011-09-19 03:40:05 +00:00
{
getDerived().addImpl(place);
2011-09-19 03:40:05 +00:00
}
static void addFree(const IAggregateFunction * that, AggregateDataPtr place, const IColumn ** columns, size_t row_num, Arena *)
{
return static_cast<const Derived &>(*that).addImpl(place);
}
IAggregateFunction::AddFunc getAddressOfAddFunction() const override final { return &addFree; }
/** Implement the following in descendant class:
2015-11-15 06:23:44 +00:00
* void addImpl(AggregateDataPtr place) const;
*/
2011-09-19 03:40:05 +00:00
};
}