ClickHouse/dbms/include/DB/AggregateFunctions/AggregateFunctionCount.h

68 lines
1.1 KiB
C
Raw Normal View History

2011-09-19 03:40:05 +00:00
#pragma once
#include <DB/IO/WriteHelpers.h>
#include <DB/IO/ReadHelpers.h>
#include <DB/DataTypes/DataTypesNumberVariable.h>
#include <DB/AggregateFunctions/INullaryAggregateFunction.h>
namespace DB
{
/// Просто считает, сколько раз её вызвали
class AggregateFunctionCount : public INullaryAggregateFunction
{
private:
UInt64 count;
public:
AggregateFunctionCount() : count(0) {}
String getName() const { return "count"; }
2011-09-25 05:07:47 +00:00
String getTypeID() const { return "count"; }
2011-09-19 03:40:05 +00:00
2011-12-19 08:06:31 +00:00
AggregateFunctionPlainPtr cloneEmpty() const
2011-09-19 03:40:05 +00:00
{
return new AggregateFunctionCount;
}
DataTypePtr getReturnType() const
{
return new DataTypeVarUInt;
}
void addZero() { ++count; }
void merge(const IAggregateFunction & rhs)
{
count += static_cast<const AggregateFunctionCount &>(rhs).count;
}
void serialize(WriteBuffer & buf) const
{
writeVarUInt(count, buf);
}
void deserializeMerge(ReadBuffer & buf)
{
UInt64 tmp;
readVarUInt(tmp, buf);
count += tmp;
}
Field getResult() const
{
return count;
}
2012-07-15 23:13:08 +00:00
/// Для оптимизации
void addDelta(UInt64 x)
{
count += x;
}
2011-09-19 03:40:05 +00:00
};
}