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

Function BuildBsonUpdateMetadata

pg_documentdb/src/update/bson_update.c:594–667  ·  view source on GitHub ↗

* Builds and sets metadata pertaining to the update based on the updateSpec and querySpec * into the metadata value provided. */

Source from the content-addressed store, hash-verified

592 * into the metadata value provided.
593 */
594static void
595BuildBsonUpdateMetadata(BsonUpdateMetadata *metadata, const bson_value_t *updateSpec,
596 const bson_value_t *querySpec, const bson_value_t *arrayFilters,
597 const bson_value_t *variableSpec, bool buildSourceDocOnUpsert)
598{
599 metadata->updateType = DetermineUpdateType(updateSpec);
600
601 /* BuildBsonDocumentFromQuery only gets called for upsert */
602 if (buildSourceDocOnUpsert)
603 {
604 pgbson *emptyDoc = PgbsonInitEmpty();
605 metadata->sourceDocOnUpsert = BuildBsonDocumentFromQuery(emptyDoc, querySpec,
606 metadata->updateType);
607 }
608
609 /* Build and cache any state pertaining to the update type */
610 switch (metadata->updateType)
611 {
612 case UpdateType_AggregationPipeline:
613 {
614 if (arrayFilters != NULL)
615 {
616 if (!IsBsonValueEmptyArray(arrayFilters))
617 {
618 ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE),
619 errmsg(
620 "Specifying arrayFilters is not allowed when performing pipeline-style updates")));
621 }
622 }
623
624 bool isReplaceStagePresent = false;
625 metadata->aggregationState = GetAggregationPipelineUpdateState(updateSpec,
626 variableSpec,
627 &
628 isReplaceStagePresent);
629
630 /*
631 * We materialize the documents after each stage so for update descriptions
632 * consider pipeline updates as replacements.
633 *
634 * TODO: Need to revisit this and see the feasibility of building more granular update descriptions.
635 */
636 metadata->commandUpdateType = CommandUpdateType_Replacement;
637 break;
638 }
639
640 case UpdateType_Operator:
641 {
642 metadata->operatorState = GetOperatorUpdateState(updateSpec, querySpec,
643 arrayFilters,
644 buildSourceDocOnUpsert);
645 metadata->commandUpdateType = CommandUpdateType_Update;
646 break;
647 }
648
649 case UpdateType_ReplaceDocument:
650 {
651 /* Simply validate the replace doc */

Callers 5

bson_update_documentFunction · 0.85
ValidateUpdateDocumentFunction · 0.85
BsonUpdateDocumentFunction · 0.85

Calls 7

DetermineUpdateTypeFunction · 0.85
PgbsonInitEmptyFunction · 0.85
IsBsonValueEmptyArrayFunction · 0.85
GetOperatorUpdateStateFunction · 0.85
BsonTypeNameFunction · 0.85

Tested by

no test coverage detected