mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-04 05:22:17 +00:00
119 lines
3.2 KiB
C++
119 lines
3.2 KiB
C++
#pragma once
|
|
|
|
#include <DataTypes/DataTypeAggregateFunction.h>
|
|
#include <AggregateFunctions/IAggregateFunction.h>
|
|
#include <Columns/ColumnAggregateFunction.h>
|
|
#include <Common/assert_cast.h>
|
|
|
|
|
|
namespace DB
|
|
{
|
|
struct Settings;
|
|
|
|
|
|
/** 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.
|
|
*/
|
|
|
|
class AggregateFunctionState final : public IAggregateFunctionHelper<AggregateFunctionState>
|
|
{
|
|
private:
|
|
AggregateFunctionPtr nested_func;
|
|
|
|
public:
|
|
AggregateFunctionState(AggregateFunctionPtr nested_, const DataTypes & arguments_, const Array & params_)
|
|
: IAggregateFunctionHelper<AggregateFunctionState>(arguments_, params_)
|
|
, nested_func(nested_)
|
|
{}
|
|
|
|
String getName() const override
|
|
{
|
|
return nested_func->getName() + "State";
|
|
}
|
|
|
|
DataTypePtr getReturnType() const override
|
|
{
|
|
return getStateType();
|
|
}
|
|
|
|
DataTypePtr getStateType() const override
|
|
{
|
|
return nested_func->getStateType();
|
|
}
|
|
|
|
bool isVersioned() const override
|
|
{
|
|
return nested_func->isVersioned();
|
|
}
|
|
|
|
size_t getDefaultVersion() const override
|
|
{
|
|
return nested_func->getDefaultVersion();
|
|
}
|
|
|
|
size_t getVersionFromRevision(size_t revision) const override { return nested_func->getVersionFromRevision(revision); }
|
|
|
|
void create(AggregateDataPtr __restrict place) const override
|
|
{
|
|
nested_func->create(place);
|
|
}
|
|
|
|
void destroy(AggregateDataPtr __restrict 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 __restrict place, const IColumn ** columns, size_t row_num, Arena * arena) const override
|
|
{
|
|
nested_func->add(place, columns, row_num, arena);
|
|
}
|
|
|
|
void merge(AggregateDataPtr __restrict place, ConstAggregateDataPtr rhs, Arena * arena) const override
|
|
{
|
|
nested_func->merge(place, rhs, arena);
|
|
}
|
|
|
|
void serialize(ConstAggregateDataPtr __restrict place, WriteBuffer & buf, std::optional<size_t> version) const override
|
|
{
|
|
nested_func->serialize(place, buf, version);
|
|
}
|
|
|
|
void deserialize(AggregateDataPtr __restrict place, ReadBuffer & buf, std::optional<size_t> version, Arena * arena) const override
|
|
{
|
|
nested_func->deserialize(place, buf, version, arena);
|
|
}
|
|
|
|
void insertResultInto(AggregateDataPtr __restrict place, IColumn & to, Arena *) const override
|
|
{
|
|
assert_cast<ColumnAggregateFunction &>(to).getData().push_back(place);
|
|
}
|
|
|
|
/// Aggregate function or aggregate function state.
|
|
bool isState() const override { return true; }
|
|
|
|
bool allocatesMemoryInArena() const override
|
|
{
|
|
return nested_func->allocatesMemoryInArena();
|
|
}
|
|
|
|
AggregateFunctionPtr getNestedFunction() const override { return nested_func; }
|
|
};
|
|
|
|
}
|