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

51 lines
1.6 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>
2016-12-29 23:17:05 +00:00
2011-09-19 03:40:05 +00:00
namespace DB
{
2016-08-05 15:44:19 +00:00
/** Creates an 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:
2016-08-05 15:44:19 +00:00
/// No std::function, for smaller 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
};
2016-08-05 15:44:19 +00:00
/// Register an aggregate function by 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:
AggregateFunctionPtr getImpl(const String & name, const DataTypes & argument_types, int recursion_level) const;
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
}