ClickHouse
134 строки · 9.9 Кб
1#include <Functions/FunctionFactory.h>
2#include <Functions/FunctionsExternalDictionaries.h>
3
4
5namespace DB
6{
7
8REGISTER_FUNCTION(ExternalDictionaries)
9{
10constexpr auto dict_get_description { R"(
11Retrieves values from a dictionary.
12
13Accepts 3 parameters:
14-- name of the dictionary;
15-- name of the column of the dictionary or tuple of column names;
16-- key value - expression returning dictionary key-type value or tuple-type value - depending on the dictionary configuration;
17
18Returned value: value of the dictionary attribute parsed in the {} if key is found, otherwise <null_value> element specified in the dictionary configuration.
19
20Throws an exception if cannot parse the value of the attribute or the value does not match the attribute data type.
21)" };
22
23constexpr auto dict_get_or_default_description { R"(
24Retrieves values from a dictionary.
25
26Accepts 4 parameters:
27-- name of the dictionary;
28-- name of the column of the dictionary or tuple of column names;
29-- key value - expression returning dictionary key-type value or tuple-type value - depending on the dictionary configuration;
30-- default values returned if the dictionary does not contain a row with the key value;
31
32Returned value: value of the dictionary attribute parsed in the {} if key is found, otherwise default value.
33
34Throws an exception if cannot parse the value of the attribute or the value does not match the attribute data type.
35)" };
36
37constexpr auto dict_get_or_null_description { R"(
38Retrieves values from a dictionary.
39
40Accepts 3 parameters:
41-- name of the dictionary;
42-- name of the column of the dictionary or tuple of column names;
43-- key value - expression returning dictionary key-type value or tuple-type value - depending on the dictionary configuration;
44
45Returned value: value of the dictionary attribute parsed in the attribute’s data type if key is found, otherwise NULL.
46
47Throws an exception if cannot parse the value of the attribute or the value does not match the attribute data type.
48)" };
49
50constexpr auto dict_get_all_description { R"(
51Retrieves all values from a dictionary corresponding to the given key values.
52
53Accepts 3 or 4 parameters:
54-- name of the dictionary;
55-- name of the column of the dictionary or tuple of column names;
56-- key value - expression returning dictionary key-type value or tuple-type value - depending on the dictionary configuration;
57-- [optional] maximum number of values to return for each attribute;
58
59Returned value: array of dictionary attribute values parsed in the attribute's data type if key is found, otherwise empty array.
60
61Throws an exception if cannot parse the value of the attribute, the value does not match the attribute data type, or the dictionary doesn't support this function.
62)" };
63
64factory.registerFunction<FunctionDictGetNoType<DictionaryGetFunctionType::get>>(FunctionDocumentation{ .description=fmt::format(dict_get_description, "attribute’s data type") });
65factory.registerFunction<FunctionDictGetNoType<DictionaryGetFunctionType::getOrDefault>>(FunctionDocumentation{ .description=fmt::format(dict_get_or_default_description, "attribute’s data type") });
66factory.registerFunction<FunctionDictGetOrNull>(FunctionDocumentation{ .description=dict_get_or_null_description });
67factory.registerFunction<FunctionDictGetNoType<DictionaryGetFunctionType::getAll>>(FunctionDocumentation{ .description=dict_get_all_description });
68
69factory.registerFunction<FunctionDictGetUInt8>(FunctionDocumentation{ .description=fmt::format(dict_get_description, "UInt8") });
70factory.registerFunction<FunctionDictGetUInt16>(FunctionDocumentation{ .description=fmt::format(dict_get_description, "UInt16") });
71factory.registerFunction<FunctionDictGetUInt32>(FunctionDocumentation{ .description=fmt::format(dict_get_description, "UInt32") });
72factory.registerFunction<FunctionDictGetUInt64>(FunctionDocumentation{ .description=fmt::format(dict_get_description, "UInt64") });
73factory.registerFunction<FunctionDictGetInt8>(FunctionDocumentation{ .description=fmt::format(dict_get_description, "Int8") });
74factory.registerFunction<FunctionDictGetInt16>(FunctionDocumentation{ .description=fmt::format(dict_get_description, "Int16") });
75factory.registerFunction<FunctionDictGetInt32>(FunctionDocumentation{ .description=fmt::format(dict_get_description, "Int32") });
76factory.registerFunction<FunctionDictGetInt64>(FunctionDocumentation{ .description=fmt::format(dict_get_description, "Int64") });
77factory.registerFunction<FunctionDictGetFloat32>(FunctionDocumentation{ .description=fmt::format(dict_get_description, "Float32") });
78factory.registerFunction<FunctionDictGetFloat64>(FunctionDocumentation{ .description=fmt::format(dict_get_description, "Float64") });
79factory.registerFunction<FunctionDictGetDate>(FunctionDocumentation{ .description=fmt::format(dict_get_description, "Date") });
80factory.registerFunction<FunctionDictGetDateTime>(FunctionDocumentation{ .description=fmt::format(dict_get_description, "DateTime") });
81factory.registerFunction<FunctionDictGetUUID>(FunctionDocumentation{ .description=fmt::format(dict_get_description, "UUID") });
82factory.registerFunction<FunctionDictGetIPv4>(FunctionDocumentation{ .description=fmt::format(dict_get_description, "IPv4") });
83factory.registerFunction<FunctionDictGetIPv6>(FunctionDocumentation{ .description=fmt::format(dict_get_description, "IPv6") });
84factory.registerFunction<FunctionDictGetString>(FunctionDocumentation{ .description=fmt::format(dict_get_description, "String") });
85
86factory.registerFunction<FunctionDictGetUInt8OrDefault>(FunctionDocumentation{ .description=fmt::format(dict_get_or_default_description, "UInt8") });
87factory.registerFunction<FunctionDictGetUInt16OrDefault>(FunctionDocumentation{ .description=fmt::format(dict_get_or_default_description, "UInt16") });
88factory.registerFunction<FunctionDictGetUInt32OrDefault>(FunctionDocumentation{ .description=fmt::format(dict_get_or_default_description, "UInt32") });
89factory.registerFunction<FunctionDictGetUInt64OrDefault>(FunctionDocumentation{ .description=fmt::format(dict_get_or_default_description, "UInt64") });
90factory.registerFunction<FunctionDictGetInt8OrDefault>(FunctionDocumentation{ .description=fmt::format(dict_get_or_default_description, "Int8") });
91factory.registerFunction<FunctionDictGetInt16OrDefault>(FunctionDocumentation{ .description=fmt::format(dict_get_or_default_description, "Int16") });
92factory.registerFunction<FunctionDictGetInt32OrDefault>(FunctionDocumentation{ .description=fmt::format(dict_get_or_default_description, "Int32") });
93factory.registerFunction<FunctionDictGetInt64OrDefault>(FunctionDocumentation{ .description=fmt::format(dict_get_or_default_description, "Int64") });
94factory.registerFunction<FunctionDictGetFloat32OrDefault>(FunctionDocumentation{ .description=fmt::format(dict_get_or_default_description, "Float32") });
95factory.registerFunction<FunctionDictGetFloat64OrDefault>(FunctionDocumentation{ .description=fmt::format(dict_get_or_default_description, "Float64") });
96factory.registerFunction<FunctionDictGetDateOrDefault>(FunctionDocumentation{ .description=fmt::format(dict_get_or_default_description, "Date") });
97factory.registerFunction<FunctionDictGetDateTimeOrDefault>(FunctionDocumentation{ .description=fmt::format(dict_get_or_default_description, "DateTime") });
98factory.registerFunction<FunctionDictGetUUIDOrDefault>(FunctionDocumentation{ .description=fmt::format(dict_get_or_default_description, "UUID") });
99factory.registerFunction<FunctionDictGetIPv4OrDefault>(FunctionDocumentation{ .description=fmt::format(dict_get_or_default_description, "IPv4") });
100factory.registerFunction<FunctionDictGetIPv6OrDefault>(FunctionDocumentation{ .description=fmt::format(dict_get_or_default_description, "IPv6") });
101factory.registerFunction<FunctionDictGetStringOrDefault>(FunctionDocumentation{ .description=fmt::format(dict_get_or_default_description, "String") });
102
103factory.registerFunction<FunctionDictHas>(FunctionDocumentation{ .description=R"(
104Checks whether a key is present in a dictionary.
105Accepts 2 parameters: name of the dictionary, key value - expression returning dictionary key-type value or tuple-type value - depending on the dictionary configuration.
106Returned value: 0 if there is no key, 1 if there is a key, type of UInt8
107)"});
108
109factory.registerFunction<FunctionDictGetHierarchy>(FunctionDocumentation{ .description=R"(
110Creates an array, containing all the parents of a key in the hierarchical dictionary.
111Accepts 2 parameters: name of the dictionary, key value - expression returning a UInt64-type value.
112Returned value: parents for the key, type of Array(UInt64)
113)"});
114
115factory.registerFunction<FunctionDictIsIn>(FunctionDocumentation{ .description=R"(
116Checks the ancestor of a key through the whole hierarchical chain in the dictionary.
117Accepts 3 parameters: name of the dictionary, key to be checked - expression returning a UInt64-type value, alleged ancestor of the key - expression returning a UInt64-type.
118Returned value: 0 if key is not a child of the ancestor, 1 if key is a child of the ancestor or if key is the ancestor, type of UInt8
119)"});
120
121factory.registerFunction<FunctionDictGetChildrenOverloadResolver>(FunctionDocumentation{ .description=R"(
122Returns first-level children as an array of indexes. It is the inverse transformation for dictGetHierarchy.
123Accepts 2 parameters: name of the dictionary, key value - expression returning a UInt64-type value.
124Returned value: first-level descendants for the key, type of Array(UInt64)
125)"});
126
127factory.registerFunction<FunctionDictGetDescendantsOverloadResolver>(FunctionDocumentation{ .description=R"(
128Returns all descendants as if dictGetChildren function was applied level times recursively.
129Accepts 3 parameters: name of the dictionary, key value - expression returning a UInt64-type value, level — hierarchy level - If level = 0 returns all descendants to the end - UInt8
130Returned value: descendants for the key, type of Array(UInt64)
131)"});
132}
133
134}
135