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

69 lines
1.1 KiB
C
Raw Normal View History

2011-09-26 04:00:46 +00:00
#pragma once
#include <DB/IO/WriteHelpers.h>
#include <DB/IO/ReadHelpers.h>
#include <DB/AggregateFunctions/IUnaryAggregateFunction.h>
namespace DB
{
/// Берёт последнее попавшееся значение
class AggregateFunctionAnyLast : public IUnaryAggregateFunction
{
private:
Field value;
DataTypePtr type;
public:
AggregateFunctionAnyLast() {}
String getName() const { return "anyLast"; }
String getTypeID() const { return "anyLast"; }
2011-12-19 08:06:31 +00:00
AggregateFunctionPlainPtr cloneEmpty() const
2011-09-26 04:00:46 +00:00
{
AggregateFunctionAnyLast * res = new AggregateFunctionAnyLast;
res->type = type;
return res;
}
DataTypePtr getReturnType() const
{
return type;
}
void setArgument(const DataTypePtr & argument)
{
type = argument;
}
void addOne(const Field & value_)
{
value = value_;
}
void merge(const IAggregateFunction & rhs)
{
2012-09-03 06:32:38 +00:00
value = static_cast<const AggregateFunctionAnyLast &>(rhs).value;
2011-09-26 04:00:46 +00:00
}
void serialize(WriteBuffer & buf) const
{
type->serializeBinary(value, buf);
}
void deserializeMerge(ReadBuffer & buf)
{
type->deserializeBinary(value, buf);
}
Field getResult() const
{
return value;
}
};
}