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

66 lines
2.1 KiB
C
Raw Normal View History

2011-09-19 03:40:05 +00:00
#pragma once
#include <DB/AggregateFunctions/IAggregateFunction.h>
2015-09-24 12:40:36 +00:00
#include <DB/DataTypes/IDataType.h>
#include <boost/iterator/transform_iterator.hpp>
2011-09-19 03:40:05 +00:00
namespace DB
{
/** Позволяет создать агрегатную функцию по её имени.
*/
2015-09-24 12:40:36 +00:00
class AggregateFunctionFactory final
2011-09-19 03:40:05 +00:00
{
2015-09-24 12:40:36 +00:00
private:
/// Не std::function, так как меньше indirection и размер объекта.
using Creator = AggregateFunctionPtr(*)(const std::string & name, const DataTypes & argument_types);
2015-04-24 15:49:30 +00:00
2011-09-19 03:40:05 +00:00
public:
AggregateFunctionFactory();
AggregateFunctionPtr get(const String & name, const DataTypes & argument_types, int recursion_level = 0) const;
2011-09-25 05:07:47 +00:00
AggregateFunctionPtr tryGet(const String & name, const DataTypes & argument_types) const;
bool isAggregateFunctionName(const String & name, int recursion_level = 0) const;
2011-09-19 03:40:05 +00:00
2015-09-24 12:40:36 +00:00
/// Зарегистрировать агрегатную функцию заданную по одному или нескольким названиям.
void registerFunction(const std::vector<std::string> & names, Creator creator);
AggregateFunctionFactory(const AggregateFunctionFactory &) = delete;
AggregateFunctionFactory & operator=(const AggregateFunctionFactory &) = delete;
private:
struct Descriptor
{
Creator creator;
bool is_alias;
};
using AggregateFunctions = std::unordered_map<std::string, Descriptor>;
public:
struct Details
{
std::string name;
bool is_alias;
};
private:
/// Вспомогательная функция для реализации итератора (см. ниже).
static Details getDetails(const AggregateFunctions::value_type & entry);
public:
/** Итератор над агрегатными функциями. Возвращает объект типа Details.
* Этот итератор нужен для таблицы system.functions.
*/
using const_iterator = boost::transform_iterator<decltype(&AggregateFunctionFactory::getDetails),
typename AggregateFunctions::const_iterator>;
public:
const_iterator begin() const;
const_iterator end() const;
private:
AggregateFunctions aggregate_functions;
};
2011-09-19 03:40:05 +00:00
}