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

48 lines
1.5 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
{
/** Creates aggregate function by name.
2011-09-19 03:40:05 +00:00
*/
2015-09-24 12:40:36 +00:00
class AggregateFunctionFactory final
2011-09-19 03:40:05 +00:00
{
friend class StorageSystemFunctions;
2015-09-24 12:40:36 +00:00
private:
/// Not std::function, for lower object size and less indirection.
using Creator = AggregateFunctionPtr(*)(const String & name, const DataTypes & argument_types);
using AggregateFunctions = std::unordered_map<String, Creator>;
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
/// For compatibility with SQL, it's possible to specify that certain aggregate function name is case insensitive.
enum CaseSensitiveness
2015-09-24 12:40:36 +00:00
{
CaseSensitive,
CaseInsensitive
2015-09-24 12:40:36 +00:00
};
/// Register aggregate function with its name.
void registerFunction(const String & name, Creator creator, CaseSensitiveness case_sensitiveness = CaseSensitive);
2015-09-24 12:40:36 +00:00
AggregateFunctionFactory(const AggregateFunctionFactory &) = delete;
AggregateFunctionFactory & operator=(const AggregateFunctionFactory &) = delete;
2015-09-24 12:40:36 +00:00
private:
AggregateFunctions aggregate_functions;
/// Case insensitive aggregate functions will be additionally added here with lowercased name.
AggregateFunctions case_insensitive_aggregate_functions;
2015-09-24 12:40:36 +00:00
};
2011-09-19 03:40:05 +00:00
}