* Builds and sets metadata pertaining to the update based on the updateSpec and querySpec * into the metadata value provided. */
| 592 | * into the metadata value provided. |
| 593 | */ |
| 594 | static void |
| 595 | BuildBsonUpdateMetadata(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 */ |
no test coverage detected