blob: cb9c84eb7b7a08ebd1b8f2176edb7a8fcaefebba (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
#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;
}
};
}
|