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

Function ParseCreateIndexesArg

pg_documentdb/src/commands/create_indexes.c:1307–1457  ·  view source on GitHub ↗

* ParseCreateIndexesArg returns a CreateIndexesArg object by parsing given * pgbson object that represents the "arg" document passed to * dbCommand/createIndexes. */

Source from the content-addressed store, hash-verified

1305 * dbCommand/createIndexes.
1306 */
1307CreateIndexesArg
1308ParseCreateIndexesArg(Datum *dbNameDatum, pgbson *arg, bool buildAsUniqueForPrepareUnique)
1309{
1310 CreateIndexesArg createIndexesArg = { 0 };
1311
1312 /*
1313 * Distinguish "indexes: []" from not specifying "indexes" field at all,
1314 * for a more suitable error message.
1315 */
1316 bool gotIndexesArray = false;
1317
1318 bson_iter_t argIter;
1319 PgbsonInitIterator(arg, &argIter);
1320
1321 StringView ignoreUnknownIndexOptionsStr = {
1322 .string = "ignoreUnknownIndexOptions",
1323 .length = 25
1324 };
1325 createIndexesArg.blocking = false;
1326 createIndexesArg.ignoreUnknownIndexOptions = false;
1327 if (bson_iter_find_string_view(&argIter, &ignoreUnknownIndexOptionsStr))
1328 {
1329 if (EnsureTopLevelFieldIsBooleanLikeNullOk(
1330 "createIndexes.ignoreUnknownIndexOptions", &argIter))
1331 {
1332 createIndexesArg.ignoreUnknownIndexOptions = BsonValueAsBool(
1333 bson_iter_value(&argIter));
1334 }
1335 }
1336
1337 PgbsonInitIterator(arg, &argIter);
1338 while (bson_iter_next(&argIter))
1339 {
1340 const char *argKey = bson_iter_key(&argIter);
1341
1342 if (strcmp(argKey, "createIndexes") == 0)
1343 {
1344 if (!BSON_ITER_HOLDS_UTF8(&argIter))
1345 {
1346 ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE),
1347 errmsg("Collection name contains an invalid data type %s",
1348 BsonIterTypeName(&argIter))));
1349 }
1350
1351 uint32_t strLength = 0;
1352 createIndexesArg.collectionName = pstrdup(bson_iter_utf8(&argIter,
1353 &strLength));
1354
1355 if (strlen(createIndexesArg.collectionName) != (size_t) strLength)
1356 {
1357 ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INVALIDNAMESPACE),
1358 errmsg(
1359 "Namespaces are not allowed to contain any embedded null characters")));
1360 }
1361 }
1362 else if (strcmp(argKey, "indexes") == 0)
1363 {
1364 EnsureTopLevelFieldType("createIndexes.indexes", &argIter, BSON_TYPE_ARRAY);

Calls 11

PgbsonInitIteratorFunction · 0.85
BsonValueAsBoolFunction · 0.85
BsonIterTypeNameFunction · 0.85
EnsureTopLevelFieldTypeFunction · 0.85
ParseIndexDefDocumentFunction · 0.85
ReportFeatureUsageFunction · 0.85
IsCommonSpecIgnoredFieldFunction · 0.85

Tested by

no test coverage detected