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

Function DeserializeUpdateWorkerSpec

pg_documentdb/src/commands/update.c:2862–2953  ·  view source on GitHub ↗

Deserializes the pgbson representing the update worker spec. It can have the following shapes: * {"updateUnsharded": [{updateSpec1}, {updateSpec2}, { ... }]} * * or for sharded updates: * {"updateOne": {updateOneParams} } */

Source from the content-addressed store, hash-verified

2860 * {"updateOne": {updateOneParams} }
2861 */
2862static void
2863DeserializeUpdateWorkerSpec(pgbson *updateInternalSpec,
2864 WorkerUpdateParam *params)
2865{
2866 pgbsonelement singleElement;
2867 bson_iter_t internalIter;
2868
2869 params->shardKeyBson = NULL;
2870 params->isUpdateOne = false;
2871 params->bypassDocumentValidation = false;
2872
2873 /* The top level is a pgbsonelement describing a type of update
2874 * Right now the only supported mode is single doc update (updateOne)
2875 */
2876 PgbsonToSinglePgbsonElement(updateInternalSpec, &singleElement);
2877
2878 if (strcmp(singleElement.path, "updateUnsharded") == 0 &&
2879 singleElement.bsonValue.value_type == BSON_TYPE_DOCUMENT)
2880 {
2881 DeserializeUpdateUnshardedWorkerSpec(&singleElement.bsonValue, params);
2882 return;
2883 }
2884 else if (strcmp(singleElement.path, "updateOne") != 0 ||
2885 singleElement.bsonValue.value_type != BSON_TYPE_DOCUMENT)
2886 {
2887 ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INTERNALERROR), (errmsg(
2888 "Update worker only supports updateOne or updateUnsharded as a document"))));
2889 }
2890
2891 params->isUpdateOne = true;
2892 UpdateOneParams *updateOneParams = &params->param.updateOne;
2893 BsonValueInitIterator(&singleElement.bsonValue, &internalIter);
2894 while (bson_iter_next(&internalIter))
2895 {
2896 const char *key = bson_iter_key(&internalIter);
2897 if (strcmp(key, "shardKeyBson") == 0)
2898 {
2899 params->shardKeyBson = PgbsonInitFromDocumentBsonValue(bson_iter_value(
2900 &internalIter));
2901 }
2902 else if (strcmp(key, "isUpsert") == 0)
2903 {
2904 updateOneParams->isUpsert = bson_iter_bool(&internalIter);
2905 }
2906 else if (strcmp(key, "arrayFilters") == 0)
2907 {
2908 /* From a compat perspective, this is serialized as { "": value } */
2909 pgbsonelement arrayFilterElement;
2910 const bson_value_t *itervalue = bson_iter_value(&internalIter);
2911 BsonValueToPgbsonElement(itervalue, &arrayFilterElement);
2912 updateOneParams->arrayFilters = CreateBsonValueCopy(
2913 &arrayFilterElement.bsonValue);
2914 }
2915 else if (strcmp(key, "query") == 0)
2916 {
2917 updateOneParams->query = CreateBsonValueCopy(bson_iter_value(
2918 &internalIter));
2919 }

Callers 1

command_update_workerFunction · 0.85

Tested by

no test coverage detected