ClickHouse/dbms/include/DB/Columns/ColumnAggregateFunction.h

123 lines
3.5 KiB
C
Raw Normal View History

2011-09-19 01:42:16 +00:00
#pragma once
#include <DB/Common/Arena.h>
2011-09-19 01:42:16 +00:00
#include <DB/AggregateFunctions/IAggregateFunction.h>
#include <DB/Columns/ColumnVector.h>
namespace DB
{
2011-09-19 01:42:16 +00:00
/** Столбец, хранящий состояния агрегатных функций.
* Состояния агрегатных функций хранятся в пуле (arena),
* (возможно, в нескольких)
* а в массиве (ColumnVector) хранятся указатели на них.
* Столбец захватывает владение пулом и всеми агрегатными функциями,
* которые в него переданы (уничтожает их в дестркуторе).
2011-09-19 01:42:16 +00:00
*/
class ColumnAggregateFunction : public ColumnVectorBase<AggregateDataPtr>
2011-09-19 01:42:16 +00:00
{
private:
AggregateFunctionPtr func; /// Используется только для уничтожения состояний.
Arenas arenas;
2011-09-19 01:42:16 +00:00
public:
ColumnAggregateFunction(const AggregateFunctionPtr & func_)
: func(func_)
{
}
ColumnAggregateFunction(const AggregateFunctionPtr & func_, const Arenas & arenas_)
: func(func_), arenas(arenas_)
{
}
void set(const AggregateFunctionPtr & func_)
{
func = func_;
}
/// Захватить владение ареной.
void addArena(ArenaPtr arena_)
{
arenas.push_back(arena_);
}
~ColumnAggregateFunction()
{
for (size_t i = 0, s = data.size(); i < s; ++i)
func->destroy(data[i]);
}
2011-09-19 01:42:16 +00:00
std::string getName() const { return "ColumnAggregateFunction"; }
ColumnPtr cloneEmpty() const { return new ColumnAggregateFunction(func, arenas); };
2012-05-30 03:30:29 +00:00
2011-09-19 01:42:16 +00:00
bool isNumeric() const { return false; }
Field operator[](size_t n) const
{
throw Exception("Method operator[] is not supported for ColumnAggregateFunction. You must access underlying vector directly.", ErrorCodes::NOT_IMPLEMENTED);;
2011-09-19 01:42:16 +00:00
}
void get(size_t n, Field & res) const
{
throw Exception("Method get is not supported for ColumnAggregateFunction. You must access underlying vector directly.", ErrorCodes::NOT_IMPLEMENTED);;
}
StringRef getDataAt(size_t n) const
{
throw Exception("Method getDataAt is not supported for ColumnAggregateFunction. You must access underlying vector directly.", ErrorCodes::NOT_IMPLEMENTED);
}
void insertData(const char * pos, size_t length)
{
throw Exception("Method insertData is not supported for " + getName(), ErrorCodes::NOT_IMPLEMENTED);
}
2011-09-19 01:42:16 +00:00
2013-05-03 05:23:14 +00:00
ColumnPtr cut(size_t start, size_t length) const
{
throw Exception("Method cut is not supported for ColumnAggregateFunction.", ErrorCodes::NOT_IMPLEMENTED);
}
ColumnPtr filter(const Filter & filter) const
{
throw Exception("Method filter is not supported for ColumnAggregateFunction.", ErrorCodes::NOT_IMPLEMENTED);
}
ColumnPtr permute(const Permutation & perm) const
{
throw Exception("Method permute is not supported for ColumnAggregateFunction.", ErrorCodes::NOT_IMPLEMENTED);
}
ColumnPtr replicate(const Offsets_t & offsets) const
{
throw Exception("Method replicate is not supported for ColumnAggregateFunction.", ErrorCodes::NOT_IMPLEMENTED);
}
2011-09-19 01:42:16 +00:00
void insert(const Field & x)
{
throw Exception("Method insert is not supported for ColumnAggregateFunction. You must access underlying vector directly.",
ErrorCodes::NOT_IMPLEMENTED);
2011-09-19 01:42:16 +00:00
}
int compareAt(size_t n, size_t m, const IColumn & rhs_) const
{
return 0;
}
2011-09-26 11:05:38 +00:00
Permutation getPermutation() const
2011-09-26 11:05:38 +00:00
{
size_t s = data.size();
Permutation res(s);
2011-09-26 11:05:38 +00:00
for (size_t i = 0; i < s; ++i)
res[i] = i;
return res;
2011-09-26 11:05:38 +00:00
}
2011-09-19 01:42:16 +00:00
};
}