| 163 | |
| 164 | template <class PolygonDictionary> |
| 165 | DictionaryPtr createLayout(const std::string & , |
| 166 | const DictionaryStructure & dict_struct, |
| 167 | const Poco::Util::AbstractConfiguration & config, |
| 168 | const std::string & config_prefix, |
| 169 | DictionarySourcePtr source_ptr, |
| 170 | ContextPtr /* context */, |
| 171 | bool /*created_from_ddl*/) |
| 172 | { |
| 173 | const String database = config.getString(config_prefix + ".database", ""); |
| 174 | const String name = config.getString(config_prefix + ".name"); |
| 175 | |
| 176 | if (!dict_struct.key) |
| 177 | throw Exception(ErrorCodes::BAD_ARGUMENTS, "'key' is required for a polygon dictionary"); |
| 178 | if (dict_struct.key->size() != 1) |
| 179 | throw Exception(ErrorCodes::BAD_ARGUMENTS, |
| 180 | "The 'key' should consist of a single attribute for a polygon dictionary"); |
| 181 | |
| 182 | IPolygonDictionary::InputType input_type; |
| 183 | IPolygonDictionary::PointType point_type; |
| 184 | const auto key_type = (*dict_struct.key)[0].type; |
| 185 | const auto f64 = std::make_shared<DataTypeFloat64>(); |
| 186 | const auto multi_polygon_array = DataTypeArray(std::make_shared<DataTypeArray>(std::make_shared<DataTypeArray>(std::make_shared<DataTypeArray>(f64)))); |
| 187 | const auto multi_polygon_tuple = DataTypeArray(std::make_shared<DataTypeArray>(std::make_shared<DataTypeArray>(std::make_shared<DataTypeTuple>(std::vector<DataTypePtr>{f64, f64})))); |
| 188 | const auto simple_polygon_array = DataTypeArray(std::make_shared<DataTypeArray>(f64)); |
| 189 | const auto simple_polygon_tuple = DataTypeArray(std::make_shared<DataTypeTuple>(std::vector<DataTypePtr>{f64, f64})); |
| 190 | if (key_type->equals(multi_polygon_array)) |
| 191 | { |
| 192 | input_type = IPolygonDictionary::InputType::MultiPolygon; |
| 193 | point_type = IPolygonDictionary::PointType::Array; |
| 194 | } |
| 195 | else if (key_type->equals(multi_polygon_tuple)) |
| 196 | { |
| 197 | input_type = IPolygonDictionary::InputType::MultiPolygon; |
| 198 | point_type = IPolygonDictionary::PointType::Tuple; |
| 199 | } |
| 200 | else if (key_type->equals(simple_polygon_array)) |
| 201 | { |
| 202 | input_type = IPolygonDictionary::InputType::SimplePolygon; |
| 203 | point_type = IPolygonDictionary::PointType::Array; |
| 204 | } |
| 205 | else if (key_type->equals(simple_polygon_tuple)) |
| 206 | { |
| 207 | input_type = IPolygonDictionary::InputType::SimplePolygon; |
| 208 | point_type = IPolygonDictionary::PointType::Tuple; |
| 209 | } |
| 210 | else |
| 211 | throw Exception(ErrorCodes::BAD_ARGUMENTS, |
| 212 | "The key type {} is not one of the following allowed types for a polygon dictionary: {} {} {} {} ", |
| 213 | key_type->getName(), |
| 214 | multi_polygon_array.getName(), |
| 215 | multi_polygon_tuple.getName(), |
| 216 | simple_polygon_array.getName(), |
| 217 | simple_polygon_tuple.getName()); |
| 218 | |
| 219 | if (dict_struct.range_min || dict_struct.range_max) |
| 220 | throw Exception(ErrorCodes::BAD_ARGUMENTS, |
| 221 | "{}: elements range_min and range_max should be defined only " |
| 222 | "for a dictionary of layout 'range_hashed'", |