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
|
|
|
|
{
|
|
|
|
|
2013-02-08 19:34:44 +00:00
|
|
|
|
|
|
|
struct AggregateFunctionAnyLastData
|
|
|
|
{
|
|
|
|
Field value;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-09-26 04:00:46 +00:00
|
|
|
/// Берёт последнее попавшееся значение
|
2013-02-08 19:34:44 +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;
|
|
|
|
}
|
|
|
|
|
2013-02-08 19:34:44 +00:00
|
|
|
|
|
|
|
void addOne(AggregateDataPtr place, const Field & value_) const
|
2011-09-26 04:00:46 +00:00
|
|
|
{
|
2013-02-08 19:34:44 +00:00
|
|
|
data(place).value = value_;
|
2011-09-26 04:00:46 +00:00
|
|
|
}
|
|
|
|
|
2013-02-08 19:34:44 +00:00
|
|
|
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs) const
|
2011-09-26 04:00:46 +00:00
|
|
|
{
|
2013-02-08 19:34:44 +00:00
|
|
|
data(place).value = data(rhs).value;
|
2011-09-26 04:00:46 +00:00
|
|
|
}
|
|
|
|
|
2013-02-08 19:34:44 +00:00
|
|
|
void serialize(ConstAggregateDataPtr place, WriteBuffer & buf) const
|
2011-09-26 04:00:46 +00:00
|
|
|
{
|
2013-02-08 19:34:44 +00:00
|
|
|
type->serializeBinary(data(place).value, buf);
|
2011-09-26 04:00:46 +00:00
|
|
|
}
|
|
|
|
|
2013-02-08 19:34:44 +00:00
|
|
|
void deserializeMerge(AggregateDataPtr place, ReadBuffer & buf) const
|
2011-09-26 04:00:46 +00:00
|
|
|
{
|
2013-02-08 19:34:44 +00:00
|
|
|
type->deserializeBinary(data(place).value, buf);
|
2011-09-26 04:00:46 +00:00
|
|
|
}
|
|
|
|
|
2013-02-08 19:34:44 +00:00
|
|
|
Field getResult(ConstAggregateDataPtr place) const
|
2011-09-26 04:00:46 +00:00
|
|
|
{
|
2013-02-08 19:34:44 +00:00
|
|
|
return data(place).value;
|
2011-09-26 04:00:46 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|