| 247 | } |
| 248 | |
| 249 | void SerializationInfoByName::readJSON(ReadBuffer & in) |
| 250 | { |
| 251 | String json_str; |
| 252 | readString(json_str, in); |
| 253 | |
| 254 | Poco::JSON::Parser parser; |
| 255 | auto object = parser.parse(json_str).extract<Poco::JSON::Object::Ptr>(); |
| 256 | |
| 257 | if (!object->has(KEY_VERSION)) |
| 258 | throw Exception(ErrorCodes::CORRUPTED_DATA, "Missed version of serialization infos"); |
| 259 | |
| 260 | if (object->getValue<size_t>(KEY_VERSION) > SERIALIZATION_INFO_VERSION) |
| 261 | throw Exception(ErrorCodes::CORRUPTED_DATA, |
| 262 | "Unknown version of serialization infos ({}). Should be less or equal than {}", |
| 263 | object->getValue<size_t>(KEY_VERSION), SERIALIZATION_INFO_VERSION); |
| 264 | |
| 265 | if (object->has(KEY_COLUMNS)) |
| 266 | { |
| 267 | auto array = object->getArray(KEY_COLUMNS); |
| 268 | for (const auto & elem : *array) |
| 269 | { |
| 270 | auto elem_object = elem.extract<Poco::JSON::Object::Ptr>(); |
| 271 | |
| 272 | if (!elem_object->has(KEY_NAME)) |
| 273 | throw Exception(ErrorCodes::CORRUPTED_DATA, |
| 274 | "Missed field '{}' in SerializationInfo of columns", KEY_NAME); |
| 275 | |
| 276 | auto name = elem_object->getValue<String>(KEY_NAME); |
| 277 | if (auto it = find(name); it != end()) |
| 278 | it->second->fromJSON(*elem_object); |
| 279 | } |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | } |