| 3098 | |
| 3099 | |
| 3100 | static void |
| 3101 | DeserializeUpsertedResult(bson_iter_t *responseIter, int updateIndex, |
| 3102 | BatchUpdateResult *result) |
| 3103 | { |
| 3104 | bson_iter_t writerErrorsIter; |
| 3105 | if (!bson_iter_recurse(responseIter, &writerErrorsIter)) |
| 3106 | { |
| 3107 | ereport(ERROR, (errmsg("Could not recurse into the update upserted documents"))); |
| 3108 | } |
| 3109 | |
| 3110 | /* It's an array of upserts */ |
| 3111 | while (bson_iter_next(&writerErrorsIter)) |
| 3112 | { |
| 3113 | bson_iter_t singleUpsert; |
| 3114 | if (!bson_iter_recurse(&writerErrorsIter, &singleUpsert)) |
| 3115 | { |
| 3116 | ereport(ERROR, (errmsg("Could not recurse into the update upsert entity"))); |
| 3117 | } |
| 3118 | |
| 3119 | int32_t index = -1; |
| 3120 | bson_value_t upsertId = { 0 }; |
| 3121 | while (bson_iter_next(&singleUpsert)) |
| 3122 | { |
| 3123 | const char *key = bson_iter_key(&singleUpsert); |
| 3124 | if (strcmp(key, "index") == 0) |
| 3125 | { |
| 3126 | index = (int32_t) bson_iter_as_int64(&singleUpsert); |
| 3127 | } |
| 3128 | else if (strcmp(key, "_id") == 0) |
| 3129 | { |
| 3130 | upsertId = *bson_iter_value(&singleUpsert); |
| 3131 | } |
| 3132 | else |
| 3133 | { |
| 3134 | ereport(ERROR, (errmsg("Unknown worker upserted field %s", key))); |
| 3135 | } |
| 3136 | } |
| 3137 | |
| 3138 | if (index < 0 || upsertId.value_type == BSON_TYPE_EOD) |
| 3139 | { |
| 3140 | ereport(ERROR, (errmsg("upserted should have index, and id"))); |
| 3141 | } |
| 3142 | |
| 3143 | MemoryContext oldContext = MemoryContextSwitchTo(result->resultMemoryContext); |
| 3144 | UpsertResult *error = palloc(sizeof(UpsertResult)); |
| 3145 | error->index = index + updateIndex; |
| 3146 | error->objectId = BsonValueToDocumentPgbson(&upsertId); |
| 3147 | result->upserted = lappend(result->upserted, error); |
| 3148 | MemoryContextSwitchTo(oldContext); |
| 3149 | } |
| 3150 | } |
| 3151 | |
| 3152 | |
| 3153 | static void |
no test coverage detected