2011-09-19 01:42:16 +00:00
|
|
|
|
#pragma once
|
|
|
|
|
|
2013-02-08 19:34:44 +00:00
|
|
|
|
#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
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/** Столбец, хранящий состояния агрегатных функций.
|
2013-02-08 20:34:30 +00:00
|
|
|
|
* Состояния агрегатных функций хранятся в пуле (arena),
|
|
|
|
|
* (возможно, в нескольких)
|
|
|
|
|
* а в массиве (ColumnVector) хранятся указатели на них.
|
2013-02-08 19:34:44 +00:00
|
|
|
|
* Столбец захватывает владение пулом и всеми агрегатными функциями,
|
|
|
|
|
* которые в него переданы (уничтожает их в дестркуторе).
|
2011-09-19 01:42:16 +00:00
|
|
|
|
*/
|
2013-02-08 19:34:44 +00:00
|
|
|
|
class ColumnAggregateFunction : public ColumnVector<AggregateDataPtr>
|
2011-09-19 01:42:16 +00:00
|
|
|
|
{
|
2013-02-08 19:34:44 +00:00
|
|
|
|
private:
|
2013-02-08 20:34:30 +00:00
|
|
|
|
typedef SharedPtr<Arena> ArenaPtr;
|
|
|
|
|
typedef std::vector<ArenaPtr> Arenas;
|
|
|
|
|
|
2013-02-08 19:34:44 +00:00
|
|
|
|
const AggregateFunctionPtr func;
|
2013-02-08 20:34:30 +00:00
|
|
|
|
Arenas arenas;
|
2011-09-19 01:42:16 +00:00
|
|
|
|
public:
|
2013-02-08 20:34:30 +00:00
|
|
|
|
ColumnAggregateFunction(AggregateFunctionPtr & func_)
|
2013-02-08 19:34:44 +00:00
|
|
|
|
{
|
2013-02-08 20:34:30 +00:00
|
|
|
|
set(func_);
|
2013-02-08 19:34:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-02-08 20:34:30 +00:00
|
|
|
|
void set(AggregateFunctionPtr & func_)
|
2013-02-08 19:34:44 +00:00
|
|
|
|
{
|
|
|
|
|
func = func_;
|
2013-02-08 20:34:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Захватить владение ареной.
|
|
|
|
|
void addArena(ArenaPtr & arena_)
|
|
|
|
|
{
|
|
|
|
|
arenas.push_back(arena_);
|
2013-02-08 19:34:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-02-03 23:11:21 +00:00
|
|
|
|
~ColumnAggregateFunction()
|
|
|
|
|
{
|
|
|
|
|
for (size_t i = 0, s = data.size(); i < s; ++i)
|
2013-02-08 19:34:44 +00:00
|
|
|
|
func->destroy(data[i]);
|
2013-02-03 23:11:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-09-19 01:42:16 +00:00
|
|
|
|
std::string getName() const { return "ColumnAggregateFunction"; }
|
|
|
|
|
|
2012-05-30 03:30:29 +00:00
|
|
|
|
ColumnPtr cloneEmpty() const { return new ColumnAggregateFunction; };
|
|
|
|
|
|
2011-09-19 01:42:16 +00:00
|
|
|
|
bool isNumeric() const { return false; }
|
|
|
|
|
|
|
|
|
|
Field operator[](size_t n) const
|
|
|
|
|
{
|
|
|
|
|
return data[n];
|
|
|
|
|
}
|
2012-10-07 06:30:10 +00:00
|
|
|
|
|
2013-01-07 06:47:15 +00:00
|
|
|
|
void get(size_t n, Field & res) const
|
|
|
|
|
{
|
|
|
|
|
res = data[n];
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-07 06:30:10 +00:00
|
|
|
|
StringRef getDataAt(size_t n) const
|
|
|
|
|
{
|
|
|
|
|
throw Exception("Method getDataAt is not supported for " + getName(), ErrorCodes::NOT_IMPLEMENTED);
|
|
|
|
|
}
|
2011-09-19 01:42:16 +00:00
|
|
|
|
|
|
|
|
|
void cut(size_t start, size_t length)
|
|
|
|
|
{
|
2012-09-20 18:40:58 +00:00
|
|
|
|
if (start + length > data.size())
|
2011-09-19 01:42:16 +00:00
|
|
|
|
throw Exception("Parameters start = "
|
|
|
|
|
+ Poco::NumberFormatter::format(start) + ", length = "
|
|
|
|
|
+ Poco::NumberFormatter::format(length) + " are out of bound in IColumnVector<T>::cut() method"
|
|
|
|
|
" (data.size() = " + Poco::NumberFormatter::format(data.size()) + ").",
|
|
|
|
|
ErrorCodes::PARAMETER_OUT_OF_BOUND);
|
|
|
|
|
|
|
|
|
|
if (start == 0)
|
|
|
|
|
data.resize(length);
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Container_t tmp(data.begin() + start, data.begin() + start + length);
|
|
|
|
|
tmp.swap(data);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void insert(const Field & x)
|
|
|
|
|
{
|
2013-02-08 19:34:44 +00:00
|
|
|
|
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
|
|
|
|
|
2013-01-21 06:43:38 +00:00
|
|
|
|
Permutation getPermutation() const
|
2011-09-26 11:05:38 +00:00
|
|
|
|
{
|
|
|
|
|
size_t s = data.size();
|
2013-01-21 06:43:38 +00:00
|
|
|
|
Permutation res(s);
|
2011-09-26 11:05:38 +00:00
|
|
|
|
for (size_t i = 0; i < s; ++i)
|
|
|
|
|
res[i] = i;
|
2013-01-21 06:43:38 +00:00
|
|
|
|
return res;
|
2011-09-26 11:05:38 +00:00
|
|
|
|
}
|
2011-09-19 01:42:16 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|