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

67 lines
1.2 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
{
struct AggregateFunctionAnyLastData
{
Field value;
};
2011-09-26 04:00:46 +00:00
/// Берёт последнее попавшееся значение
class AggregateFunctionAnyLast : public IUnaryAggregateFunction<AggregateFunctionAnyLastData>
2011-09-26 04:00:46 +00:00
{
private:
DataTypePtr type;
public:
String getName() const { return "anyLast"; }
String getTypeID() const { return "anyLast"; }
DataTypePtr getReturnType() const
{
return type;
}
void setArgument(const DataTypePtr & argument)
{
type = argument;
}
void addOne(AggregateDataPtr place, const Field & value_) const
2011-09-26 04:00:46 +00:00
{
data(place).value = value_;
2011-09-26 04:00:46 +00:00
}
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs) const
2011-09-26 04:00:46 +00:00
{
data(place).value = data(rhs).value;
2011-09-26 04:00:46 +00:00
}
void serialize(ConstAggregateDataPtr place, WriteBuffer & buf) const
2011-09-26 04:00:46 +00:00
{
type->serializeBinary(data(place).value, buf);
2011-09-26 04:00:46 +00:00
}
void deserializeMerge(AggregateDataPtr place, ReadBuffer & buf) const
2011-09-26 04:00:46 +00:00
{
type->deserializeBinary(data(place).value, buf);
2011-09-26 04:00:46 +00:00
}
Field getResult(ConstAggregateDataPtr place) const
2011-09-26 04:00:46 +00:00
{
return data(place).value;
2011-09-26 04:00:46 +00:00
}
};
}