| 1392 | |
| 1393 | |
| 1394 | static void |
| 1395 | GenerateTermPath(bson_iter_t *bsonIter, const char *basePath, |
| 1396 | uint32_t basePathLength, bool inArrayContext, |
| 1397 | bool isArrayTerm, GenerateTermsContext *context, |
| 1398 | bool isCheckForArrayTermsWithNestedDocument, |
| 1399 | StringInfo pathStringInfo) |
| 1400 | { |
| 1401 | const char *pathToInsert; |
| 1402 | uint32_t pathtoInsertLength; |
| 1403 | |
| 1404 | /* if array of array has not document inside it , we will not be generating parent path term */ |
| 1405 | if (isCheckForArrayTermsWithNestedDocument && !BSON_ITER_HOLDS_DOCUMENT(bsonIter)) |
| 1406 | { |
| 1407 | return; |
| 1408 | } |
| 1409 | |
| 1410 | const char *fieldName = bson_iter_key(bsonIter); |
| 1411 | uint32_t fieldNameLength = bson_iter_key_len(bsonIter); |
| 1412 | |
| 1413 | if (isArrayTerm) |
| 1414 | { |
| 1415 | /* if isArrayTerm is true (because we're inside an array context and we're generating */ |
| 1416 | /* and we're building the non array-index based terms, then just use the base path) */ |
| 1417 | /* this is because we can filter on array entries based on the array index (a.b.0 / a.b.1) */ |
| 1418 | /* or simply on the array path itself (a.b) */ |
| 1419 | pathToInsert = basePath; |
| 1420 | pathtoInsertLength = basePathLength; |
| 1421 | } |
| 1422 | else if (basePathLength == 0) |
| 1423 | { |
| 1424 | /* if we're at the root, simply use the field path. */ |
| 1425 | pathToInsert = fieldName; |
| 1426 | pathtoInsertLength = fieldNameLength; |
| 1427 | } |
| 1428 | else |
| 1429 | { |
| 1430 | /* otherwise build the path to insert. We use 'base.field' for the path */ |
| 1431 | /* since dot paths are illegal in field names. */ |
| 1432 | uint32_t fieldPathLength = fieldNameLength; |
| 1433 | uint32_t pathToInsertAllocLength; |
| 1434 | |
| 1435 | /* the length includes the two fields + the extra dot. */ |
| 1436 | pathtoInsertLength = fieldPathLength + basePathLength + 1; |
| 1437 | |
| 1438 | /* need one more character for the \0 */ |
| 1439 | pathToInsertAllocLength = pathtoInsertLength + 1; |
| 1440 | |
| 1441 | if (pathStringInfo->len == 0) |
| 1442 | { |
| 1443 | /* if there's no temp buffer create one */ |
| 1444 | enlargeStringInfo(pathStringInfo, pathToInsertAllocLength); |
| 1445 | } |
| 1446 | else if (pathStringInfo->len < (int) pathToInsertAllocLength) |
| 1447 | { |
| 1448 | /* if there's not enough space in the temp buffer, realloc to ensure enough length. */ |
| 1449 | enlargeStringInfo(pathStringInfo, pathToInsertAllocLength); |
| 1450 | } |
| 1451 |
no test coverage detected