* BuildBatchInsertionSpec validates the insert command BSON and builds * a BatchInsertionSpec. */
| 285 | * a BatchInsertionSpec. |
| 286 | */ |
| 287 | static BatchInsertionSpec * |
| 288 | BuildBatchInsertionSpec(bson_iter_t *insertCommandIter, pgbsonsequence *insertDocs, |
| 289 | Datum *databaseNameDatum) |
| 290 | { |
| 291 | const char *collectionName = NULL; |
| 292 | List *documents = NIL; |
| 293 | bool isOrdered = true; |
| 294 | bool hasDocuments = false; |
| 295 | bool hasSkippedDocuments = false; |
| 296 | bool bypassDocumentValidation = false; |
| 297 | |
| 298 | while (bson_iter_next(insertCommandIter)) |
| 299 | { |
| 300 | const char *field = bson_iter_key(insertCommandIter); |
| 301 | |
| 302 | if (strcmp(field, "insert") == 0) |
| 303 | { |
| 304 | if (!BSON_ITER_HOLDS_UTF8(insertCommandIter)) |
| 305 | { |
| 306 | ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), |
| 307 | errmsg("Collection name contains an invalid data type %s", |
| 308 | BsonIterTypeName(insertCommandIter)))); |
| 309 | } |
| 310 | |
| 311 | collectionName = bson_iter_utf8(insertCommandIter, NULL); |
| 312 | } |
| 313 | else if (strcmp(field, "documents") == 0) |
| 314 | { |
| 315 | EnsureTopLevelFieldType("insert.documents", insertCommandIter, |
| 316 | BSON_TYPE_ARRAY); |
| 317 | |
| 318 | /* if both docs and spec are provided, fail */ |
| 319 | if (insertDocs != NULL) |
| 320 | { |
| 321 | ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_FAILEDTOPARSE), |
| 322 | errmsg( |
| 323 | "Both 'documents' and 'insert.documents' cannot be specified."))); |
| 324 | } |
| 325 | |
| 326 | bson_iter_t insertArrayIter; |
| 327 | bson_iter_recurse(insertCommandIter, &insertArrayIter); |
| 328 | |
| 329 | documents = BuildInsertionList(&insertArrayIter, &hasSkippedDocuments); |
| 330 | hasDocuments = true; |
| 331 | } |
| 332 | else if (strcmp(field, "ordered") == 0) |
| 333 | { |
| 334 | EnsureTopLevelFieldType("insert.ordered", insertCommandIter, BSON_TYPE_BOOL); |
| 335 | |
| 336 | isOrdered = bson_iter_bool(insertCommandIter); |
| 337 | } |
| 338 | else if (strcmp(field, "bypassDocumentValidation") == 0) |
| 339 | { |
| 340 | /* TODO: unsupport by default */ |
| 341 | if (!EnableBypassDocumentValidation) |
| 342 | { |
| 343 | continue; |
| 344 | } |
no test coverage detected