2011-09-19 03:40:05 +00:00
|
|
|
#pragma once
|
|
|
|
|
2016-12-29 23:17:05 +00:00
|
|
|
#include <DB/IO/VarInt.h>
|
2011-09-19 03:40:05 +00:00
|
|
|
|
2012-12-14 20:24:26 +00:00
|
|
|
#include <DB/DataTypes/DataTypesNumberFixed.h>
|
2011-09-19 03:40:05 +00:00
|
|
|
|
|
|
|
#include <DB/AggregateFunctions/INullaryAggregateFunction.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2013-02-08 19:34:44 +00:00
|
|
|
struct AggregateFunctionCountData
|
2011-09-19 03:40:05 +00:00
|
|
|
{
|
|
|
|
UInt64 count;
|
|
|
|
|
2013-02-08 19:34:44 +00:00
|
|
|
AggregateFunctionCountData() : count(0) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// Просто считает, сколько раз её вызвали
|
2014-06-04 01:00:09 +00:00
|
|
|
class AggregateFunctionCount final : public INullaryAggregateFunction<AggregateFunctionCountData, AggregateFunctionCount>
|
2013-02-08 19:34:44 +00:00
|
|
|
{
|
|
|
|
public:
|
2015-11-11 02:04:23 +00:00
|
|
|
String getName() const override { return "count"; }
|
2011-09-19 03:40:05 +00:00
|
|
|
|
2015-11-11 02:04:23 +00:00
|
|
|
DataTypePtr getReturnType() const override
|
2011-09-19 03:40:05 +00:00
|
|
|
{
|
2016-05-28 07:48:40 +00:00
|
|
|
return std::make_shared<DataTypeUInt64>();
|
2011-09-19 03:40:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-11-15 06:23:44 +00:00
|
|
|
void addImpl(AggregateDataPtr place) const
|
2013-02-08 19:34:44 +00:00
|
|
|
{
|
|
|
|
++data(place).count;
|
|
|
|
}
|
|
|
|
|
2016-09-23 23:33:17 +00:00
|
|
|
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs, Arena * arena) const override
|
2011-09-19 03:40:05 +00:00
|
|
|
{
|
2013-02-08 19:34:44 +00:00
|
|
|
data(place).count += data(rhs).count;
|
2011-09-19 03:40:05 +00:00
|
|
|
}
|
|
|
|
|
2015-11-11 02:04:23 +00:00
|
|
|
void serialize(ConstAggregateDataPtr place, WriteBuffer & buf) const override
|
2011-09-19 03:40:05 +00:00
|
|
|
{
|
2013-02-08 19:34:44 +00:00
|
|
|
writeVarUInt(data(place).count, buf);
|
2011-09-19 03:40:05 +00:00
|
|
|
}
|
|
|
|
|
2016-09-22 23:26:08 +00:00
|
|
|
void deserialize(AggregateDataPtr place, ReadBuffer & buf, Arena *) const override
|
2011-09-19 03:40:05 +00:00
|
|
|
{
|
2016-03-12 04:01:03 +00:00
|
|
|
readVarUInt(data(place).count, buf);
|
2011-09-19 03:40:05 +00:00
|
|
|
}
|
|
|
|
|
2015-11-11 02:04:23 +00:00
|
|
|
void insertResultInto(ConstAggregateDataPtr place, IColumn & to) const override
|
2011-09-19 03:40:05 +00:00
|
|
|
{
|
2013-06-30 11:38:46 +00:00
|
|
|
static_cast<ColumnUInt64 &>(to).getData().push_back(data(place).count);
|
2011-09-19 03:40:05 +00:00
|
|
|
}
|
2012-07-15 23:13:08 +00:00
|
|
|
|
|
|
|
/// Для оптимизации
|
2013-02-08 23:41:05 +00:00
|
|
|
void addDelta(AggregateDataPtr place, UInt64 x) const
|
2012-07-15 23:13:08 +00:00
|
|
|
{
|
2013-02-08 19:34:44 +00:00
|
|
|
data(place).count += x;
|
2012-07-15 23:13:08 +00:00
|
|
|
}
|
2011-09-19 03:40:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|