ClickHouse/src/AggregateFunctions/AggregateFunctionCombinatorFactory.h
2021-05-26 14:58:31 +03:00

49 lines
1.3 KiB
C++

#pragma once
#include <AggregateFunctions/IAggregateFunctionCombinator.h>
#include <string>
#include <unordered_map>
namespace DB
{
struct Settings;
/** Create aggregate function combinator by matching suffix in aggregate function name.
*/
class AggregateFunctionCombinatorFactory final: private boost::noncopyable
{
private:
struct CombinatorPair
{
std::string name;
AggregateFunctionCombinatorPtr combinator_ptr;
bool operator==(const CombinatorPair & rhs) const { return name == rhs.name; }
/// Sort by the length of the combinator name for proper tryFindSuffix()
/// for combiners with common prefix (i.e. "State" and "SimpleState").
bool operator<(const CombinatorPair & rhs) const { return name.length() > rhs.name.length(); }
};
using Dict = std::vector<CombinatorPair>;
Dict dict;
public:
static AggregateFunctionCombinatorFactory & instance();
/// Not thread safe. You must register before using tryGet.
void registerCombinator(const AggregateFunctionCombinatorPtr & value);
/// Example: if the name is 'avgIf', it will return combinator -If.
AggregateFunctionCombinatorPtr tryFindSuffix(const std::string & name) const;
const Dict & getAllAggregateFunctionCombinators() const
{
return dict;
}
};
}