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

Function bson_dollar_all

pg_documentdb/src/query/bson_dollar_operators.c:705–749  ·  view source on GitHub ↗

* Traverses the document for a given dot-path notation * When a matching path is found, then returns true if the * element meets the $all operator criteria. Returns false * otherwise. */

Source from the content-addressed store, hash-verified

703 * otherwise.
704 */
705Datum
706bson_dollar_all(PG_FUNCTION_ARGS)
707{
708 pgbson *document = PG_GETARG_PGBSON(0);
709 TraverseAllValidateState validationState = {
710 .elementState =
711 {
712 .filter = NULL,
713 .traverseState = { 0 }
714 },
715 .matchState = NULL,
716 .arrayHasOnlyNulls = false,
717 .evalStateArray = NULL,
718 .crePcreData = NULL
719 };
720
721 pgbsonelement filterElement = { 0 };
722 PopulateDollarAllValidationState(fcinfo, &validationState, &filterElement);
723
724 /* an empty array for $all doesn't match any elements */
725 if (validationState.matchState == NULL)
726 {
727 PG_RETURN_BOOL(false);
728 }
729
730 const TraverseBsonExecutionFuncs *execFuncs = &CompareExecutionFuncs;
731 if (validationState.evalStateArray != NULL)
732 {
733 execFuncs = &CompareTopLevelFieldExecutionFuncs;
734 }
735
736 bson_iter_t documentIterator;
737 PgbsonInitIterator(document, &documentIterator);
738 TraverseBson(&documentIterator, filterElement.path,
739 &validationState.elementState.traverseState,
740 execFuncs);
741 pfree(validationState.matchState);
742
743 /* if path was not found and the $all array only contains null,
744 * ([null], or [null,null,null]) we have a match. */
745 IsQueryFilterNullFunc isNullFilterEquality = IsQueryFilterNullForDollarAll;
746 PG_RETURN_BOOL(ProcessQueryResultAndGetMatch(isNullFilterEquality,
747 &validationState.elementState.
748 traverseState));
749}
750
751
752/*

Callers

nothing calls this directly

Calls 4

PgbsonInitIteratorFunction · 0.85
TraverseBsonFunction · 0.85

Tested by

no test coverage detected