2019-11-23 07:48:22 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AggregateFunctions/AggregateFunctionAvg.h>
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
template <typename T, typename Data>
|
2019-12-15 13:36:44 +00:00
|
|
|
class AggregateFunctionAvgWeighted final : public AggregateFunctionAvgBase<T, Data, AggregateFunctionAvgWeighted<T, Data>>
|
2019-11-23 07:48:22 +00:00
|
|
|
{
|
|
|
|
public:
|
2019-12-15 13:36:44 +00:00
|
|
|
using AggregateFunctionAvgBase<T, Data, AggregateFunctionAvgWeighted<T, Data>>::AggregateFunctionAvgBase;
|
2019-11-23 07:48:22 +00:00
|
|
|
|
2019-11-23 07:55:41 +00:00
|
|
|
using ColVecType = std::conditional_t<IsDecimalNumber<T>, ColumnDecimal<T>, ColumnVector<T>>;
|
2019-11-23 07:48:22 +00:00
|
|
|
void add(AggregateDataPtr place, const IColumn ** columns, size_t row_num, Arena *) const override
|
|
|
|
{
|
|
|
|
const auto & values = static_cast<const ColVecType &>(*columns[0]);
|
|
|
|
const auto & weights = static_cast<const ColVecType &>(*columns[1]);
|
|
|
|
|
|
|
|
this->data(place).numerator += values.getData()[row_num] * weights.getData()[row_num];
|
|
|
|
this->data(place).denominator += weights.getData()[row_num];
|
|
|
|
}
|
|
|
|
|
|
|
|
String getName() const override { return "avgWeighted"; }
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|