2017-05-03 19:46:41 +00:00
|
|
|
|
2014-05-21 13:27:40 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <DataTypes/DataTypeAggregateFunction.h>
|
|
|
|
#include <AggregateFunctions/IAggregateFunction.h>
|
|
|
|
#include <Columns/ColumnAggregateFunction.h>
|
2019-08-21 02:28:04 +00:00
|
|
|
#include <Common/assert_cast.h>
|
2014-05-21 13:27:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
|
2017-03-09 00:56:38 +00:00
|
|
|
/** Not an aggregate function, but an adapter of aggregate functions,
|
|
|
|
* Aggregate functions with the `State` suffix differ from the corresponding ones in that their states are not finalized.
|
|
|
|
* Return type - DataTypeAggregateFunction.
|
2014-05-21 13:27:40 +00:00
|
|
|
*/
|
|
|
|
|
2017-12-20 07:36:30 +00:00
|
|
|
class AggregateFunctionState final : public IAggregateFunctionHelper<AggregateFunctionState>
|
2014-05-21 13:27:40 +00:00
|
|
|
{
|
|
|
|
private:
|
2017-12-20 07:36:30 +00:00
|
|
|
AggregateFunctionPtr nested_func;
|
2017-04-01 07:20:54 +00:00
|
|
|
DataTypes arguments;
|
|
|
|
Array params;
|
2014-05-21 13:27:40 +00:00
|
|
|
|
|
|
|
public:
|
2019-08-03 11:02:40 +00:00
|
|
|
AggregateFunctionState(AggregateFunctionPtr nested_, const DataTypes & arguments_, const Array & params_)
|
|
|
|
: IAggregateFunctionHelper<AggregateFunctionState>(arguments_, params_)
|
|
|
|
, nested_func(nested_), arguments(arguments_), params(params_) {}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
String getName() const override
|
|
|
|
{
|
|
|
|
return nested_func->getName() + "State";
|
|
|
|
}
|
|
|
|
|
2017-05-03 19:46:41 +00:00
|
|
|
DataTypePtr getReturnType() const override;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
void create(AggregateDataPtr place) const override
|
|
|
|
{
|
|
|
|
nested_func->create(place);
|
|
|
|
}
|
|
|
|
|
|
|
|
void destroy(AggregateDataPtr place) const noexcept override
|
|
|
|
{
|
|
|
|
nested_func->destroy(place);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool hasTrivialDestructor() const override
|
|
|
|
{
|
|
|
|
return nested_func->hasTrivialDestructor();
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t sizeOfData() const override
|
|
|
|
{
|
|
|
|
return nested_func->sizeOfData();
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t alignOfData() const override
|
|
|
|
{
|
|
|
|
return nested_func->alignOfData();
|
|
|
|
}
|
|
|
|
|
|
|
|
void add(AggregateDataPtr place, const IColumn ** columns, size_t row_num, Arena * arena) const override
|
|
|
|
{
|
|
|
|
nested_func->add(place, columns, row_num, arena);
|
|
|
|
}
|
|
|
|
|
|
|
|
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs, Arena * arena) const override
|
|
|
|
{
|
|
|
|
nested_func->merge(place, rhs, arena);
|
|
|
|
}
|
|
|
|
|
|
|
|
void serialize(ConstAggregateDataPtr place, WriteBuffer & buf) const override
|
|
|
|
{
|
|
|
|
nested_func->serialize(place, buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
void deserialize(AggregateDataPtr place, ReadBuffer & buf, Arena * arena) const override
|
|
|
|
{
|
|
|
|
nested_func->deserialize(place, buf, arena);
|
|
|
|
}
|
|
|
|
|
|
|
|
void insertResultInto(ConstAggregateDataPtr place, IColumn & to) const override
|
|
|
|
{
|
2019-08-21 02:28:04 +00:00
|
|
|
assert_cast<ColumnAggregateFunction &>(to).getData().push_back(const_cast<AggregateDataPtr>(place));
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Aggregate function or aggregate function state.
|
|
|
|
bool isState() const override { return true; }
|
|
|
|
|
|
|
|
bool allocatesMemoryInArena() const override
|
|
|
|
{
|
|
|
|
return nested_func->allocatesMemoryInArena();
|
|
|
|
}
|
|
|
|
|
2017-12-20 07:36:30 +00:00
|
|
|
AggregateFunctionPtr getNestedFunction() const { return nested_func; }
|
2014-05-21 13:27:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|