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>
|
2017-12-20 07:36:30 +00:00
|
|
|
#include <DataTypes/DataTypeAggregateFunction.h>
|
2017-07-13 20:58:19 +00:00
|
|
|
#include <Common/typeid_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 `Merge` suffix accept `DataTypeAggregateFunction` as an argument
|
|
|
|
* (state of the aggregate function obtained earlier using the aggregate function with the `State` suffix)
|
|
|
|
* and combine them with aggregation.
|
2014-05-21 13:27:40 +00:00
|
|
|
*/
|
|
|
|
|
2017-12-20 07:36:30 +00:00
|
|
|
class AggregateFunctionMerge final : public IAggregateFunctionHelper<AggregateFunctionMerge>
|
2014-05-21 13:27:40 +00:00
|
|
|
{
|
|
|
|
private:
|
2017-12-20 07:36:30 +00:00
|
|
|
AggregateFunctionPtr nested_func;
|
2014-05-21 13:27:40 +00:00
|
|
|
|
|
|
|
public:
|
2017-12-20 07:36:30 +00:00
|
|
|
AggregateFunctionMerge(AggregateFunctionPtr nested_, const IDataType & argument)
|
|
|
|
: nested_func(nested_)
|
|
|
|
{
|
|
|
|
const DataTypeAggregateFunction * data_type = typeid_cast<const DataTypeAggregateFunction *>(&argument);
|
|
|
|
|
|
|
|
if (!data_type || data_type->getFunctionName() != nested_func->getName())
|
2017-12-20 08:14:33 +00:00
|
|
|
throw Exception("Illegal type " + argument.getName() + " of argument for aggregate function " + getName(),
|
2017-12-20 07:36:30 +00:00
|
|
|
ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
|
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
String getName() const override
|
|
|
|
{
|
|
|
|
return nested_func->getName() + "Merge";
|
|
|
|
}
|
|
|
|
|
|
|
|
DataTypePtr getReturnType() const override
|
|
|
|
{
|
|
|
|
return nested_func->getReturnType();
|
|
|
|
}
|
|
|
|
|
|
|
|
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->merge(place, static_cast<const ColumnAggregateFunction &>(*columns[0]).getData()[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
|
|
|
|
{
|
|
|
|
nested_func->insertResultInto(place, to);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool allocatesMemoryInArena() const override
|
|
|
|
{
|
|
|
|
return nested_func->allocatesMemoryInArena();
|
|
|
|
}
|
|
|
|
|
2017-09-17 20:22:39 +00:00
|
|
|
const char * getHeaderFilePath() const override { return __FILE__; }
|
2014-05-21 13:27:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|