forked from ClickHouse/ClickHouse
-
Notifications
You must be signed in to change notification settings - Fork 1
/
DictionaryStructure.h
172 lines (152 loc) · 5.31 KB
/
DictionaryStructure.h
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#pragma once
#include <Core/Field.h>
#include <DataTypes/IDataType.h>
#include <IO/ReadBufferFromString.h>
#include <Interpreters/IExternalLoadable.h>
#include <Poco/Util/AbstractConfiguration.h>
#include <map>
#include <optional>
#include <string>
#include <vector>
namespace DB
{
enum class AttributeUnderlyingType
{
utUInt8,
utUInt16,
utUInt32,
utUInt64,
utUInt128,
utInt8,
utInt16,
utInt32,
utInt64,
utFloat32,
utFloat64,
utDecimal32,
utDecimal64,
utDecimal128,
utString
};
AttributeUnderlyingType getAttributeUnderlyingType(const std::string & type);
std::string toString(const AttributeUnderlyingType type);
/// Min and max lifetimes for a dictionary or it's entry
using DictionaryLifetime = ExternalLoadableLifetime;
/** Holds the description of a single dictionary attribute:
* - name, used for lookup into dictionary and source;
* - type, used in conjunction with DataTypeFactory and getAttributeUnderlyingTypeByname;
* - null_value, used as a default value for non-existent entries in the dictionary,
* decimal representation for numeric attributes;
* - hierarchical, whether this attribute defines a hierarchy;
* - injective, whether the mapping to parent is injective (can be used for optimization of GROUP BY?)
* - is_object_id, used in mongo dictionary, converts string key to objectid
*/
struct DictionaryAttribute final
{
const std::string name;
const AttributeUnderlyingType underlying_type;
const DataTypePtr type;
const DataTypePtr nested_type;
const std::string expression;
const Field null_value;
const bool hierarchical;
const bool injective;
const bool is_object_id;
const bool is_nullable;
const bool is_array;
};
template <typename Type>
struct DictionaryAttributeType
{
using AttributeType = Type;
};
template <typename F>
void callOnDictionaryAttributeType(AttributeUnderlyingType type, F&& func)
{
switch (type)
{
case AttributeUnderlyingType::utUInt8:
func(DictionaryAttributeType<UInt8>());
break;
case AttributeUnderlyingType::utUInt16:
func(DictionaryAttributeType<UInt16>());
break;
case AttributeUnderlyingType::utUInt32:
func(DictionaryAttributeType<UInt32>());
break;
case AttributeUnderlyingType::utUInt64:
func(DictionaryAttributeType<UInt64>());
break;
case AttributeUnderlyingType::utUInt128:
func(DictionaryAttributeType<UInt128>());
break;
case AttributeUnderlyingType::utInt8:
func(DictionaryAttributeType<Int8>());
break;
case AttributeUnderlyingType::utInt16:
func(DictionaryAttributeType<Int16>());
break;
case AttributeUnderlyingType::utInt32:
func(DictionaryAttributeType<Int32>());
break;
case AttributeUnderlyingType::utInt64:
func(DictionaryAttributeType<Int64>());
break;
case AttributeUnderlyingType::utFloat32:
func(DictionaryAttributeType<Float32>());
break;
case AttributeUnderlyingType::utFloat64:
func(DictionaryAttributeType<Float64>());
break;
case AttributeUnderlyingType::utString:
func(DictionaryAttributeType<String>());
break;
case AttributeUnderlyingType::utDecimal32:
func(DictionaryAttributeType<Decimal32>());
break;
case AttributeUnderlyingType::utDecimal64:
func(DictionaryAttributeType<Decimal64>());
break;
case AttributeUnderlyingType::utDecimal128:
func(DictionaryAttributeType<Decimal128>());
break;
}
};
struct DictionarySpecialAttribute final
{
const std::string name;
const std::string expression;
DictionarySpecialAttribute(const Poco::Util::AbstractConfiguration & config, const std::string & config_prefix);
};
struct DictionaryTypedSpecialAttribute final
{
const std::string name;
const std::string expression;
const DataTypePtr type;
};
/// Name of identifier plus list of attributes
struct DictionaryStructure final
{
std::optional<DictionarySpecialAttribute> id;
std::optional<std::vector<DictionaryAttribute>> key;
std::vector<DictionaryAttribute> attributes;
std::optional<DictionaryTypedSpecialAttribute> range_min;
std::optional<DictionaryTypedSpecialAttribute> range_max;
bool has_expressions = false;
bool access_to_key_from_attributes = false;
DictionaryStructure(const Poco::Util::AbstractConfiguration & config, const std::string & config_prefix);
void validateKeyTypes(const DataTypes & key_types) const;
const DictionaryAttribute & getAttribute(const String & attribute_name) const;
const DictionaryAttribute & getAttribute(const String & attribute_name, const DataTypePtr & type) const;
std::string getKeyDescription() const;
bool isKeySizeFixed() const;
size_t getKeySize() const;
private:
/// range_min and range_max have to be parsed before this function call
std::vector<DictionaryAttribute> getAttributes(
const Poco::Util::AbstractConfiguration & config,
const std::string & config_prefix,
const bool hierarchy_allowed = true,
const bool allow_null_values = true);
};
}