ClickHouse
43 строки · 1.3 Кб
1#include "AggregateFunctionCombinatorFactory.h"
2
3#include <Common/StringUtils/StringUtils.h>
4
5namespace DB
6{
7
8namespace ErrorCodes
9{
10extern const int LOGICAL_ERROR;
11}
12
13void AggregateFunctionCombinatorFactory::registerCombinator(const AggregateFunctionCombinatorPtr & value)
14{
15CombinatorPair pair{
16.name = value->getName(),
17.combinator_ptr = value,
18};
19
20/// lower_bound() cannot be used since sort order of the dict is by length of the combinator
21/// but there are just a few combiners, so not a problem.
22if (std::find(dict.begin(), dict.end(), pair) != dict.end())
23throw Exception(ErrorCodes::LOGICAL_ERROR, "AggregateFunctionCombinatorFactory: the name '{}' is not unique",
24value->getName());
25dict.emplace(std::lower_bound(dict.begin(), dict.end(), pair), pair);
26}
27
28AggregateFunctionCombinatorPtr AggregateFunctionCombinatorFactory::tryFindSuffix(const std::string & name) const
29{
30/// O(N) is ok for just a few combinators.
31for (const auto & suffix_value : dict)
32if (endsWith(name, suffix_value.name))
33return suffix_value.combinator_ptr;
34return {};
35}
36
37AggregateFunctionCombinatorFactory & AggregateFunctionCombinatorFactory::instance()
38{
39static AggregateFunctionCombinatorFactory ret;
40return ret;
41}
42
43}
44