mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-10-01 14:10:50 +00:00
5f4e833925
* Switch to std::function to allow more complex creator logic * Cleanup headers
79 lines
2.0 KiB
C++
79 lines
2.0 KiB
C++
#pragma once
|
|
|
|
#include <AggregateFunctions/IAggregateFunction.h>
|
|
|
|
#include <ext/singleton.h>
|
|
|
|
#include <functional>
|
|
#include <memory>
|
|
#include <string>
|
|
#include <unordered_map>
|
|
#include <vector>
|
|
|
|
|
|
namespace DB
|
|
{
|
|
|
|
class Context;
|
|
class IDataType;
|
|
|
|
using DataTypePtr = std::shared_ptr<IDataType>;
|
|
using DataTypes = std::vector<DataTypePtr>;
|
|
|
|
|
|
/** Creates an aggregate function by name.
|
|
*/
|
|
class AggregateFunctionFactory final : public ext::singleton<AggregateFunctionFactory>
|
|
{
|
|
friend class StorageSystemFunctions;
|
|
|
|
public:
|
|
using Creator = std::function<AggregateFunctionPtr(const String &, const DataTypes &, const Array &)>;
|
|
|
|
/// For compatibility with SQL, it's possible to specify that certain aggregate function name is case insensitive.
|
|
enum CaseSensitiveness
|
|
{
|
|
CaseSensitive,
|
|
CaseInsensitive
|
|
};
|
|
|
|
/// 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;
|
|
|
|
private:
|
|
AggregateFunctionPtr getImpl(
|
|
const String & name,
|
|
const DataTypes & argument_types,
|
|
const Array & parameters,
|
|
int recursion_level) const;
|
|
|
|
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;
|
|
};
|
|
|
|
}
|