ClickHouse

Форк
0
/
FunctionsExternalDictionaries.cpp 
134 строки · 9.9 Кб
1
#include <Functions/FunctionFactory.h>
2
#include <Functions/FunctionsExternalDictionaries.h>
3

4

5
namespace DB
6
{
7

8
REGISTER_FUNCTION(ExternalDictionaries)
9
{
10
    constexpr auto dict_get_description { R"(
11
Retrieves values from a dictionary.
12

13
Accepts 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

18
Returned value: value of the dictionary attribute parsed in the {} if key is found, otherwise <null_value> element specified in the dictionary configuration.
19

20
Throws an exception if cannot parse the value of the attribute or the value does not match the attribute data type.
21
)" };
22

23
    constexpr auto dict_get_or_default_description { R"(
24
Retrieves values from a dictionary.
25

26
Accepts 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

32
Returned value: value of the dictionary attribute parsed in the {} if key is found, otherwise default value.
33

34
Throws an exception if cannot parse the value of the attribute or the value does not match the attribute data type.
35
)" };
36

37
    constexpr auto dict_get_or_null_description { R"(
38
Retrieves values from a dictionary.
39

40
Accepts 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

45
Returned value: value of the dictionary attribute parsed in the attribute’s data type if key is found, otherwise NULL.
46

47
Throws an exception if cannot parse the value of the attribute or the value does not match the attribute data type.
48
)" };
49

50
    constexpr auto dict_get_all_description { R"(
51
Retrieves all values from a dictionary corresponding to the given key values.
52

53
Accepts 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

59
Returned value: array of dictionary attribute values parsed in the attribute's data type if key is found, otherwise empty array.
60

61
Throws 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

64
    factory.registerFunction<FunctionDictGetNoType<DictionaryGetFunctionType::get>>(FunctionDocumentation{ .description=fmt::format(dict_get_description, "attribute’s data type") });
65
    factory.registerFunction<FunctionDictGetNoType<DictionaryGetFunctionType::getOrDefault>>(FunctionDocumentation{ .description=fmt::format(dict_get_or_default_description, "attribute’s data type") });
66
    factory.registerFunction<FunctionDictGetOrNull>(FunctionDocumentation{ .description=dict_get_or_null_description });
67
    factory.registerFunction<FunctionDictGetNoType<DictionaryGetFunctionType::getAll>>(FunctionDocumentation{ .description=dict_get_all_description });
68

69
    factory.registerFunction<FunctionDictGetUInt8>(FunctionDocumentation{ .description=fmt::format(dict_get_description, "UInt8") });
70
    factory.registerFunction<FunctionDictGetUInt16>(FunctionDocumentation{ .description=fmt::format(dict_get_description, "UInt16") });
71
    factory.registerFunction<FunctionDictGetUInt32>(FunctionDocumentation{ .description=fmt::format(dict_get_description, "UInt32") });
72
    factory.registerFunction<FunctionDictGetUInt64>(FunctionDocumentation{ .description=fmt::format(dict_get_description, "UInt64") });
73
    factory.registerFunction<FunctionDictGetInt8>(FunctionDocumentation{ .description=fmt::format(dict_get_description, "Int8") });
74
    factory.registerFunction<FunctionDictGetInt16>(FunctionDocumentation{ .description=fmt::format(dict_get_description, "Int16") });
75
    factory.registerFunction<FunctionDictGetInt32>(FunctionDocumentation{ .description=fmt::format(dict_get_description, "Int32") });
76
    factory.registerFunction<FunctionDictGetInt64>(FunctionDocumentation{ .description=fmt::format(dict_get_description, "Int64") });
77
    factory.registerFunction<FunctionDictGetFloat32>(FunctionDocumentation{ .description=fmt::format(dict_get_description, "Float32") });
78
    factory.registerFunction<FunctionDictGetFloat64>(FunctionDocumentation{ .description=fmt::format(dict_get_description, "Float64") });
79
    factory.registerFunction<FunctionDictGetDate>(FunctionDocumentation{ .description=fmt::format(dict_get_description, "Date") });
80
    factory.registerFunction<FunctionDictGetDateTime>(FunctionDocumentation{ .description=fmt::format(dict_get_description, "DateTime") });
81
    factory.registerFunction<FunctionDictGetUUID>(FunctionDocumentation{ .description=fmt::format(dict_get_description, "UUID") });
82
    factory.registerFunction<FunctionDictGetIPv4>(FunctionDocumentation{ .description=fmt::format(dict_get_description, "IPv4") });
83
    factory.registerFunction<FunctionDictGetIPv6>(FunctionDocumentation{ .description=fmt::format(dict_get_description, "IPv6") });
84
    factory.registerFunction<FunctionDictGetString>(FunctionDocumentation{ .description=fmt::format(dict_get_description, "String") });
85

86
    factory.registerFunction<FunctionDictGetUInt8OrDefault>(FunctionDocumentation{ .description=fmt::format(dict_get_or_default_description, "UInt8") });
87
    factory.registerFunction<FunctionDictGetUInt16OrDefault>(FunctionDocumentation{ .description=fmt::format(dict_get_or_default_description, "UInt16") });
88
    factory.registerFunction<FunctionDictGetUInt32OrDefault>(FunctionDocumentation{ .description=fmt::format(dict_get_or_default_description, "UInt32") });
89
    factory.registerFunction<FunctionDictGetUInt64OrDefault>(FunctionDocumentation{ .description=fmt::format(dict_get_or_default_description, "UInt64") });
90
    factory.registerFunction<FunctionDictGetInt8OrDefault>(FunctionDocumentation{ .description=fmt::format(dict_get_or_default_description, "Int8") });
91
    factory.registerFunction<FunctionDictGetInt16OrDefault>(FunctionDocumentation{ .description=fmt::format(dict_get_or_default_description, "Int16") });
92
    factory.registerFunction<FunctionDictGetInt32OrDefault>(FunctionDocumentation{ .description=fmt::format(dict_get_or_default_description, "Int32") });
93
    factory.registerFunction<FunctionDictGetInt64OrDefault>(FunctionDocumentation{ .description=fmt::format(dict_get_or_default_description, "Int64") });
94
    factory.registerFunction<FunctionDictGetFloat32OrDefault>(FunctionDocumentation{ .description=fmt::format(dict_get_or_default_description, "Float32") });
95
    factory.registerFunction<FunctionDictGetFloat64OrDefault>(FunctionDocumentation{ .description=fmt::format(dict_get_or_default_description, "Float64") });
96
    factory.registerFunction<FunctionDictGetDateOrDefault>(FunctionDocumentation{ .description=fmt::format(dict_get_or_default_description, "Date") });
97
    factory.registerFunction<FunctionDictGetDateTimeOrDefault>(FunctionDocumentation{ .description=fmt::format(dict_get_or_default_description, "DateTime") });
98
    factory.registerFunction<FunctionDictGetUUIDOrDefault>(FunctionDocumentation{ .description=fmt::format(dict_get_or_default_description, "UUID") });
99
    factory.registerFunction<FunctionDictGetIPv4OrDefault>(FunctionDocumentation{ .description=fmt::format(dict_get_or_default_description, "IPv4") });
100
    factory.registerFunction<FunctionDictGetIPv6OrDefault>(FunctionDocumentation{ .description=fmt::format(dict_get_or_default_description, "IPv6") });
101
    factory.registerFunction<FunctionDictGetStringOrDefault>(FunctionDocumentation{ .description=fmt::format(dict_get_or_default_description, "String") });
102

103
    factory.registerFunction<FunctionDictHas>(FunctionDocumentation{ .description=R"(
104
Checks whether a key is present in a dictionary.
105
Accepts 2 parameters: name of the dictionary, key value - expression returning dictionary key-type value or tuple-type value - depending on the dictionary configuration.
106
Returned value: 0 if there is no key, 1 if there is a key, type of UInt8
107
)"});
108

109
    factory.registerFunction<FunctionDictGetHierarchy>(FunctionDocumentation{ .description=R"(
110
Creates an array, containing all the parents of a key in the hierarchical dictionary.
111
Accepts 2 parameters: name of the dictionary, key value - expression returning a UInt64-type value.
112
Returned value: parents for the key, type of Array(UInt64)
113
)"});
114

115
    factory.registerFunction<FunctionDictIsIn>(FunctionDocumentation{ .description=R"(
116
Checks the ancestor of a key through the whole hierarchical chain in the dictionary.
117
Accepts 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.
118
Returned 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

121
    factory.registerFunction<FunctionDictGetChildrenOverloadResolver>(FunctionDocumentation{ .description=R"(
122
Returns first-level children as an array of indexes. It is the inverse transformation for dictGetHierarchy.
123
Accepts 2 parameters: name of the dictionary, key value - expression returning a UInt64-type value.
124
Returned value: first-level descendants for the key, type of Array(UInt64)
125
)"});
126

127
    factory.registerFunction<FunctionDictGetDescendantsOverloadResolver>(FunctionDocumentation{ .description=R"(
128
Returns all descendants as if dictGetChildren function was applied level times recursively.
129
Accepts 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
130
Returned value: descendants for the key, type of Array(UInt64)
131
)"});
132
}
133

134
}
135

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.