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

Function BuildDeletionSpec

pg_documentdb/src/commands/delete.c:493–591  ·  view source on GitHub ↗

* BuildDeletionSpec builds a DeletionSpec from the BSON of a single delete * operation. */

Source from the content-addressed store, hash-verified

491 * operation.
492 */
493static DeletionSpec *
494BuildDeletionSpec(bson_iter_t *deletionIter, const bson_value_t *variableSpec)
495{
496 bson_value_t *query = NULL;
497 int64 limit = -1;
498
499 char collationString[MAX_ICU_COLLATION_LENGTH] = "\0";
500 while (bson_iter_next(deletionIter))
501 {
502 const char *field = bson_iter_key(deletionIter);
503
504 if (strcmp(field, "q") == 0)
505 {
506 EnsureTopLevelFieldType("delete.deletes.q", deletionIter, BSON_TYPE_DOCUMENT);
507
508 query = CreateBsonValueCopy(bson_iter_value(deletionIter));
509 }
510 else if (strcmp(field, "limit") == 0)
511 {
512 if (!BSON_ITER_HOLDS_NUMBER(deletionIter))
513 {
514 /* we treats arbitrary types as valid limit 0 */
515 limit = 0;
516 }
517 else
518 {
519 limit = bson_iter_as_int64(deletionIter);
520 if (limit != 0 && limit != 1)
521 {
522 ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_FAILEDTOPARSE),
523 errmsg("The limit field in delete objects must be 0 "
524 "or 1. Got " INT64_FORMAT, limit)));
525 }
526 }
527 }
528 else if (strcmp(field, "collation") == 0)
529 {
530 ReportFeatureUsage(FEATURE_COLLATION);
531
532 if (EnableCollation)
533 {
534 EnsureTopLevelFieldType("delete.collation", deletionIter,
535 BSON_TYPE_DOCUMENT);
536
537 const bson_value_t *collationValue = bson_iter_value(deletionIter);
538 ParseAndGetCollationString(collationValue,
539 collationString);
540 }
541 else
542 {
543 ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_COMMANDNOTSUPPORTED),
544 errmsg("BSON field 'delete.deletes.collation' is not yet "
545 "supported")));
546 }
547 }
548 else if (strcmp(field, "hint") == 0)
549 {
550 /* We ignore this for now (TODO Support this?) */

Callers 2

BuildDeletionSpecListFunction · 0.85

Calls 4

EnsureTopLevelFieldTypeFunction · 0.85
CreateBsonValueCopyFunction · 0.85
ReportFeatureUsageFunction · 0.85

Tested by

no test coverage detected