MCPcopy Create free account
hub / github.com/documentdb/documentdb / BsonUnwindEmptyArray

Function BsonUnwindEmptyArray

pg_documentdb/src/aggregation/bson_unwind.c:495–524  ·  view source on GitHub ↗

* BsonUnwindEmptyArray produces the output document when an empty array is found * at the unwind target * document -> source document * path -> path being unwound * indexFieldName -> optional name for the index field to be added */

Source from the content-addressed store, hash-verified

493 * indexFieldName -> optional name for the index field to be added
494 */
495static pgbson *
496BsonUnwindEmptyArray(pgbson *document, char *path, char *indexFieldName)
497{
498 pgbson_writer projectSpecWriter;
499 PgbsonWriterInit(&projectSpecWriter);
500
501 bool value = false;
502 PgbsonWriterAppendBool(&projectSpecWriter, path, strlen(path),
503 value);
504
505 if (indexFieldName != NULL)
506 {
507 /* Single elements have null index */
508 PgbsonWriterAppendNull(&projectSpecWriter, indexFieldName, strlen(
509 indexFieldName));
510 }
511
512 bson_iter_t projectSpec;
513 PgbsonWriterGetIterator(&projectSpecWriter, &projectSpec);
514
515 bool forceProjectId = true;
516 bool allowInclusionExclusion = true;
517
518 pgbson *variableSpec = NULL;
519 const BsonProjectionQueryState *projectionState =
520 GetProjectionStateForBsonProject(&projectSpec,
521 forceProjectId, allowInclusionExclusion,
522 variableSpec);
523 return ProjectDocumentWithState(document, projectionState);
524}
525
526
527/*

Callers 1

BsonUnwindArrayFunction · 0.85

Calls 6

PgbsonWriterInitFunction · 0.85
PgbsonWriterAppendBoolFunction · 0.85
PgbsonWriterAppendNullFunction · 0.85
PgbsonWriterGetIteratorFunction · 0.85
ProjectDocumentWithStateFunction · 0.85

Tested by

no test coverage detected