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
|
|
|
{
|
2016-07-14 05:22:09 +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.
|
2016-07-14 05:22:09 +00:00
|
|
|
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();
|
2013-09-14 22:56:11 +00:00
|
|
|
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;
|
2013-09-14 22:56:11 +00:00
|
|
|
bool isAggregateFunctionName(const String & name, int recursion_level = 0) const;
|
2011-09-19 03:40:05 +00:00
|
|
|
|
2016-07-14 05:22:09 +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
|
|
|
{
|
2016-07-14 05:22:09 +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.
|
2016-07-14 05:22:09 +00:00
|
|
|
void registerFunction(const String & name, Creator creator, CaseSensitiveness case_sensitiveness = CaseSensitive);
|
2015-09-24 12:40:36 +00:00
|
|
|
|
2016-07-14 05:22:09 +00:00
|
|
|
AggregateFunctionFactory(const AggregateFunctionFactory &) = delete;
|
|
|
|
AggregateFunctionFactory & operator=(const AggregateFunctionFactory &) = delete;
|
2015-09-24 12:40:36 +00:00
|
|
|
|
|
|
|
private:
|
2016-07-12 13:02:52 +00:00
|
|
|
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;
|
2016-07-14 05:22:09 +00:00
|
|
|
|
|
|
|
/// 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
|
|
|
|
|
|
|
}
|