ClickHouse/dbms/AggregateFunctions/AggregateFunctionFactory.h

84 lines
2.5 KiB
C++
Raw Normal View History

2011-09-19 03:40:05 +00:00
#pragma once
#include <AggregateFunctions/IAggregateFunction.h>
#include <Common/IFactoryWithAliases.h>
2016-12-29 23:17:05 +00:00
#include <functional>
#include <memory>
#include <string>
#include <unordered_map>
#include <vector>
2011-09-19 03:40:05 +00:00
namespace DB
{
class Context;
class IDataType;
using DataTypePtr = std::shared_ptr<const IDataType>;
using DataTypes = std::vector<DataTypePtr>;
/** Creator have arguments: name of aggregate function, types of arguments, values of parameters.
* Parameters are for "parametric" aggregate functions.
* For example, in quantileWeighted(0.9)(x, weight), 0.9 is "parameter" and x, weight are "arguments".
*/
using AggregateFunctionCreator = std::function<AggregateFunctionPtr(const String &, const DataTypes &, const Array &)>;
2016-08-05 15:44:19 +00:00
/** Creates an aggregate function by name.
2011-09-19 03:40:05 +00:00
*/
class AggregateFunctionFactory final : private boost::noncopyable, public IFactoryWithAliases<AggregateFunctionCreator>
2011-09-19 03:40:05 +00:00
{
public:
static AggregateFunctionFactory & instance();
/// Register a function by its name.
/// No locking, you must register all functions before usage of get.
void registerFunction(
const String & name,
Creator creator,
CaseSensitiveness case_sensitiveness = CaseSensitive);
/// Throws an exception if not found.
AggregateFunctionPtr get(
const String & name,
const DataTypes & argument_types,
const Array & parameters = {},
int recursion_level = 0) const;
/// Returns nullptr if not found.
AggregateFunctionPtr tryGet(
const String & name,
const DataTypes & argument_types,
const Array & parameters = {}) 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
private:
AggregateFunctionPtr getImpl(
const String & name,
const DataTypes & argument_types,
const Array & parameters,
int recursion_level) const;
2015-09-24 12:40:36 +00:00
private:
using AggregateFunctions = std::unordered_map<String, Creator>;
AggregateFunctions aggregate_functions;
/// Case insensitive aggregate functions will be additionally added here with lowercased name.
AggregateFunctions case_insensitive_aggregate_functions;
const AggregateFunctions & getCreatorMap() const override { return aggregate_functions; }
const AggregateFunctions & getCaseInsensitiveCreatorMap() const override { return case_insensitive_aggregate_functions; }
String getFactoryName() const override { return "AggregateFunctionFactory"; }
2015-09-24 12:40:36 +00:00
};
2011-09-19 03:40:05 +00:00
}