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
|
|
|
/// Берёт последнее попавшееся значение
|
2014-06-04 01:00:09 +00:00
|
|
|
class AggregateFunctionAnyLast final : public IUnaryAggregateFunction<AggregateFunctionAnyLastData, AggregateFunctionAnyLast>
|
2011-09-26 04:00:46 +00:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
DataTypePtr type;
|
|
|
|
|
|
|
|
public:
|
|
|
|
String getName() const { return "anyLast"; }
|
|
|
|
|
|
|
|
DataTypePtr getReturnType() const
|
|
|
|
{
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setArgument(const DataTypePtr & argument)
|
|
|
|
{
|
|
|
|
type = argument;
|
|
|
|
}
|
|
|
|
|
2013-02-08 19:34:44 +00:00
|
|
|
|
2013-06-25 08:06:40 +00:00
|
|
|
void addOne(AggregateDataPtr place, const IColumn & column, size_t row_num) const
|
2011-09-26 04:00:46 +00:00
|
|
|
{
|
2013-06-25 08:06:40 +00:00
|
|
|
column.get(row_num, data(place).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
|
|
|
{
|
2014-02-17 23:46:27 +00:00
|
|
|
if (!data(rhs).value.isNull())
|
|
|
|
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
|
|
|
{
|
2014-02-17 23:46:27 +00:00
|
|
|
const Data & d = data(place);
|
|
|
|
|
|
|
|
if (unlikely(d.value.isNull()))
|
|
|
|
{
|
|
|
|
writeBinary(false, buf);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
writeBinary(true, buf);
|
|
|
|
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
|
|
|
{
|
2014-02-17 23:46:27 +00:00
|
|
|
bool is_not_null = false;
|
|
|
|
readBinary(is_not_null, buf);
|
|
|
|
|
|
|
|
if (is_not_null)
|
|
|
|
type->deserializeBinary(data(place).value, buf);
|
2011-09-26 04:00:46 +00:00
|
|
|
}
|
|
|
|
|
2013-06-30 11:38:46 +00:00
|
|
|
void insertResultInto(ConstAggregateDataPtr place, IColumn & to) const
|
2011-09-26 04:00:46 +00:00
|
|
|
{
|
2013-09-14 22:18:56 +00:00
|
|
|
if (unlikely(data(place).value.isNull()))
|
|
|
|
to.insertDefault();
|
|
|
|
else
|
|
|
|
to.insert(data(place).value);
|
2011-09-26 04:00:46 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|