#pragma once #include #include namespace DB { /** Interface for aggregate functions taking zero number of arguments. For example, this is 'count' aggregate function. */ template class INullaryAggregateFunction : public IAggregateFunctionHelper { private: Derived & getDerived() { return static_cast(*this); } const Derived & getDerived() const { return static_cast(*this); } 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 { if (arguments.size() != 0) throw Exception("Passed " + toString(arguments.size()) + " arguments to nullary aggregate function " + this->getName(), ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH); } /// Accumulate a value. void add(AggregateDataPtr place, const IColumn ** columns, size_t row_num, Arena *) const override final { getDerived().addImpl(place); } static void addFree(const IAggregateFunction * that, AggregateDataPtr place, const IColumn ** columns, size_t row_num, Arena *) { return static_cast(*that).addImpl(place); } IAggregateFunction::AddFunc getAddressOfAddFunction() const override final { return &addFree; } /** Implement the following in descendant class: * void addImpl(AggregateDataPtr place) const; */ }; }