Called for each field read from a document in lexicographic order. Returns INCLUDE_ALL if the entire field should be included, INCLUDE_PARTIAL if the field should be partially included (e.g. for an array, the array will be included but not all of its elements will), and EXCLUDE if the field should be excluded.
| 318 | // included, INCLUDE_PARTIAL if the field should be partially included (e.g. for an array, the array will be included |
| 319 | // but not all of its elements will), and EXCLUDE if the field should be excluded. |
| 320 | Projector::IncludeType Projector::includeNextField(int depth, std::string fieldName, bool isSimple, bool inArray) { |
| 321 | // This is the case if no projection was supplied |
| 322 | if (projectionStack.empty()) { |
| 323 | return INCLUDE_ALL; |
| 324 | } |
| 325 | |
| 326 | Reference<Projection> currentProjection; |
| 327 | if (projectionStack.size() >= depth) { |
| 328 | projectionStack.resize(depth); |
| 329 | currentProjection = projectionStack.back().second; |
| 330 | |
| 331 | // Projection specifications can match through arrays (e.g. {'A': [{'B':'c'}]} is included by the projection |
| 332 | // {'A.B':1}) Therefore, when descending into an array, we can just duplicate the previous projection |
| 333 | if (inArray) { |
| 334 | projectionStack.push_back(projectionStack.back()); |
| 335 | } |
| 336 | |
| 337 | // Otherwise, check if the current projection has the current field. If so, add its projection to the stack |
| 338 | else { |
| 339 | auto itr = currentProjection->fields.find(fieldName); |
| 340 | if (itr != currentProjection->fields.end()) { |
| 341 | projectionStack.emplace_back(fieldName, itr->second); |
| 342 | } |
| 343 | } |
| 344 | } |
| 345 | |
| 346 | currentProjection = projectionStack.back().second; |
| 347 | |
| 348 | IncludeType result = EXCLUDE; |
| 349 | if (currentProjection->included) { |
| 350 | result = INCLUDE_ALL; |
| 351 | } |
| 352 | |
| 353 | // If we are projecting an object or array and we haven't reached the end of the current field specification (e.g. |
| 354 | // we are at 'A.B' and the projection specified 'A.B.C'), then we partially include the object or array. |
| 355 | else if (!isSimple && projectionStack.size() == depth + 1 && !currentProjection->fields.empty()) { |
| 356 | result = INCLUDE_PARTIAL; |
| 357 | } |
| 358 | |
| 359 | return result; |
| 360 | } |
| 361 | |
| 362 | ACTOR Future<Void> getArrayStream(Reference<IReadWriteContext> document, |
| 363 | Standalone<StringRef> arrayField, |
no test coverage detected