2014-05-21 13:27:40 +00:00
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <DB/DataTypes/DataTypeAggregateFunction.h>
|
|
|
|
|
#include <DB/AggregateFunctions/IAggregateFunction.h>
|
2014-05-28 14:54:42 +00:00
|
|
|
|
#include <DB/Columns/ColumnAggregateFunction.h>
|
2014-05-21 13:27:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Не агрегатная функция, а адаптер агрегатных функций,
|
|
|
|
|
* Агрегатные функции с суффиксом State отличаются от соответствующих тем, что их состояния не финализируются.
|
2014-06-03 20:29:04 +00:00
|
|
|
|
* Возвращаемый тип - DataTypeAggregateFunction.
|
2014-05-21 13:27:40 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2014-06-04 01:00:09 +00:00
|
|
|
|
class AggregateFunctionState final : public IAggregateFunction
|
2014-05-21 13:27:40 +00:00
|
|
|
|
{
|
|
|
|
|
private:
|
|
|
|
|
AggregateFunctionPtr nested_func_owner;
|
|
|
|
|
IAggregateFunction * nested_func;
|
|
|
|
|
DataTypes arguments;
|
|
|
|
|
Array params;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
AggregateFunctionState(AggregateFunctionPtr nested_) : nested_func_owner(nested_), nested_func(nested_func_owner.get()) {}
|
|
|
|
|
|
|
|
|
|
String getName() const
|
|
|
|
|
{
|
|
|
|
|
return nested_func->getName() + "State";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DataTypePtr getReturnType() const
|
|
|
|
|
{
|
|
|
|
|
return new DataTypeAggregateFunction(nested_func_owner, arguments, params);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void setArguments(const DataTypes & arguments_)
|
|
|
|
|
{
|
|
|
|
|
arguments = arguments_;
|
|
|
|
|
nested_func->setArguments(arguments);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void setParameters(const Array & params_)
|
|
|
|
|
{
|
|
|
|
|
params = params_;
|
|
|
|
|
nested_func->setParameters(params);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void create(AggregateDataPtr place) const
|
|
|
|
|
{
|
|
|
|
|
nested_func->create(place);
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-23 01:09:18 +00:00
|
|
|
|
void destroy(AggregateDataPtr place) const noexcept
|
2014-05-21 13:27:40 +00:00
|
|
|
|
{
|
|
|
|
|
nested_func->destroy(place);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool hasTrivialDestructor() const
|
|
|
|
|
{
|
|
|
|
|
return nested_func->hasTrivialDestructor();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t sizeOfData() const
|
|
|
|
|
{
|
|
|
|
|
return nested_func->sizeOfData();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t alignOfData() const
|
|
|
|
|
{
|
|
|
|
|
return nested_func->alignOfData();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void add(AggregateDataPtr place, const IColumn ** columns, size_t row_num) const
|
|
|
|
|
{
|
|
|
|
|
nested_func->add(place, columns, row_num);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs) const
|
|
|
|
|
{
|
|
|
|
|
nested_func->merge(place, rhs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void serialize(ConstAggregateDataPtr place, WriteBuffer & buf) const
|
|
|
|
|
{
|
|
|
|
|
nested_func->serialize(place, buf);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void deserializeMerge(AggregateDataPtr place, ReadBuffer & buf) const
|
|
|
|
|
{
|
|
|
|
|
nested_func->deserializeMerge(place, buf);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void insertResultInto(ConstAggregateDataPtr place, IColumn & to) const
|
|
|
|
|
{
|
2014-05-30 16:21:30 +00:00
|
|
|
|
static_cast<ColumnAggregateFunction &>(to).getData().push_back(const_cast<AggregateDataPtr>(place));
|
2014-05-21 13:27:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-05-30 16:21:30 +00:00
|
|
|
|
/// Аггрегатная функция или состояние аггрегатной функции.
|
|
|
|
|
bool isState() const { return true; }
|
2014-05-21 13:27:40 +00:00
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|