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

79 lines
1.3 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 AggregateFunctionAnyData
{
Field value;
};
2011-09-26 04:00:46 +00:00
/// Берёт первое попавшееся значение
class AggregateFunctionAny : public IUnaryAggregateFunction<AggregateFunctionAnyData>
2011-09-26 04:00:46 +00:00
{
private:
DataTypePtr type;
public:
String getName() const { return "any"; }
DataTypePtr getReturnType() const
{
return type;
}
void setArgument(const DataTypePtr & argument)
{
type = argument;
}
void addOne(AggregateDataPtr place, const IColumn & column, size_t row_num) const
2011-09-26 04:00:46 +00:00
{
Data & d = data(place);
if (!d.value.isNull())
2011-09-26 04:00:46 +00:00
return;
column.get(row_num, d.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 & d = data(place);
if (d.value.isNull())
d.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
{
Data & d = data(place);
2012-10-24 19:09:42 +00:00
Field tmp;
type->deserializeBinary(tmp, buf);
if (d.value.isNull())
d.value = tmp;
2011-09-26 04:00:46 +00:00
}
void insertResultInto(ConstAggregateDataPtr place, IColumn & to) const
2011-09-26 04:00:46 +00:00
{
to.insert(data(place).value);
2011-09-26 04:00:46 +00:00
}
};
}