| 308 | |
| 309 | |
| 310 | Block MongoDBBlockInputStream::readImpl() |
| 311 | { |
| 312 | if (all_read) |
| 313 | return {}; |
| 314 | |
| 315 | MutableColumns columns(description.sample_block.columns()); |
| 316 | const size_t size = columns.size(); |
| 317 | |
| 318 | for (const auto i : collections::range(0, size)) |
| 319 | columns[i] = description.sample_block.getByPosition(i).column->cloneEmpty(); |
| 320 | |
| 321 | size_t num_rows = 0; |
| 322 | while (num_rows < max_block_size) |
| 323 | { |
| 324 | Poco::MongoDB::ResponseMessage & response = cursor->next(*connection); |
| 325 | |
| 326 | for (auto & document : response.documents()) |
| 327 | { |
| 328 | ++num_rows; |
| 329 | |
| 330 | for (const auto idx : collections::range(0, size)) |
| 331 | { |
| 332 | const auto & name = description.sample_block.getByPosition(idx).name; |
| 333 | |
| 334 | if (strict_check_names && !document->exists(name)) |
| 335 | throw Exception(fmt::format("Column {} is absent in MongoDB collection", backQuote(name)), ErrorCodes::NOT_FOUND_COLUMN_IN_BLOCK); |
| 336 | |
| 337 | const Poco::MongoDB::Element::Ptr value = document->get(name); |
| 338 | |
| 339 | if (value.isNull() || value->type() == Poco::MongoDB::ElementTraits<Poco::MongoDB::NullValue>::TypeId) |
| 340 | insertDefaultValue(*columns[idx], *description.sample_block.getByPosition(idx).column); |
| 341 | else |
| 342 | { |
| 343 | if (description.types[idx].second) |
| 344 | { |
| 345 | ColumnNullable & column_nullable = assert_cast<ColumnNullable &>(*columns[idx]); |
| 346 | insertValue(column_nullable.getNestedColumn(), description.types[idx].first, *value, name); |
| 347 | column_nullable.getNullMapData().emplace_back(0); |
| 348 | } |
| 349 | else |
| 350 | insertValue(*columns[idx], description.types[idx].first, *value, name); |
| 351 | } |
| 352 | } |
| 353 | } |
| 354 | |
| 355 | if (response.cursorID() == 0) |
| 356 | { |
| 357 | all_read = true; |
| 358 | break; |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | if (num_rows == 0) |
| 363 | return {}; |
| 364 | |
| 365 | return description.sample_block.cloneWithColumns(std::move(columns)); |
| 366 | } |
| 367 |
nothing calls this directly
no test coverage detected