MCPcopy Create free account
hub / github.com/ByConity/ByConity / DictionaryStructure

Method DictionaryStructure

src/Dictionaries/DictionaryStructure.cpp:112–201  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

110
111
112DictionaryStructure::DictionaryStructure(const Poco::Util::AbstractConfiguration & config, const std::string & config_prefix)
113{
114 std::string structure_prefix = config_prefix + ".structure";
115
116 const auto has_id = config.has(structure_prefix + ".id");
117 const auto has_key = config.has(structure_prefix + ".key");
118
119 if (has_key && has_id)
120 throw Exception(ErrorCodes::BAD_ARGUMENTS, "Only one of 'id' and 'key' should be specified");
121
122 if (has_id)
123 id.emplace(config, structure_prefix + ".id");
124 else if (has_key)
125 {
126 key.emplace(getAttributes(config, structure_prefix + ".key", /*complex_key_attributes =*/ true));
127 if (key->empty())
128 throw Exception(ErrorCodes::BAD_ARGUMENTS, "Empty 'key' supplied");
129 }
130 else
131 throw Exception(ErrorCodes::BAD_ARGUMENTS, "Dictionary structure should specify either 'id' or 'key'");
132
133 if (id)
134 {
135 if (id->name.empty())
136 throw Exception(ErrorCodes::BAD_ARGUMENTS, "'id' cannot be empty");
137
138 const char * range_default_type = "Date";
139 if (config.has(structure_prefix + ".range_min"))
140 range_min.emplace(makeDictionaryTypedSpecialAttribute(config, structure_prefix + ".range_min", range_default_type));
141
142 if (config.has(structure_prefix + ".range_max"))
143 range_max.emplace(makeDictionaryTypedSpecialAttribute(config, structure_prefix + ".range_max", range_default_type));
144
145 if (range_min.has_value() != range_max.has_value())
146 {
147 throw Exception(ErrorCodes::BAD_ARGUMENTS,
148 "Dictionary structure should have both 'range_min' and 'range_max' either specified or not.");
149 }
150
151 if (range_min && range_max && !range_min->type->equals(*range_max->type))
152 {
153 throw Exception(ErrorCodes::BAD_ARGUMENTS,
154 "Dictionary structure 'range_min' and 'range_max' should have same type, "
155 "'range_min' type: {},"
156 "'range_max' type: {}",
157 range_min->type->getName(),
158 range_max->type->getName());
159 }
160
161 if (range_min)
162 {
163 if (!range_min->type->isValueRepresentedByInteger())
164 throw Exception(ErrorCodes::BAD_ARGUMENTS,
165 "Dictionary structure type of 'range_min' and 'range_max' should be an integer, Date, DateTime, or Enum."
166 " Actual 'range_min' and 'range_max' type is {}",
167 range_min->type->getName());
168 }
169

Callers

nothing calls this directly

Calls 12

has_valueMethod · 0.80
toStringFunction · 0.70
ExceptionClass · 0.50
hasMethod · 0.45
emplaceMethod · 0.45
emptyMethod · 0.45
equalsMethod · 0.45
getNameMethod · 0.45
sizeMethod · 0.45
getBoolMethod · 0.45

Tested by

no test coverage detected