MCPcopy Create free account
hub / github.com/FoundationDB/fdb-document-layer / valueQueryToPredicates

Function valueQueryToPredicates

src/ExtMsg.actor.cpp:88–111  ·  view source on GitHub ↗

* Converts a `value_query` in the above grammar, with the given path, to a predicate * The predicate is returned by appending to `out_terms` zero or more predicates which, * anded together, have the semantics of the given value_query. */

Source from the content-addressed store, hash-verified

86 * anded together, have the semantics of the given value_query.
87 */
88void valueQueryToPredicates(bson::BSONObj const& value_query,
89 std::string const& path,
90 std::vector<Reference<IPredicate>>& out_terms) {
91 std::string regex_options; // hacky special handling of { $option, $regex }
92 for (auto it = value_query.begin(); it.more();) {
93 auto sub = it.next();
94 if (std::string(sub.fieldName()) == "$options") {
95 regex_options = sub.String();
96 } else {
97 out_terms.push_back(ExtValueOperator::toPredicate(sub.fieldName(), path, sub));
98 }
99 }
100
101 // $options is applied to "$regex" so we don't have to create a Value Operator for it
102 // but we still need to find the predicate that is RegEx and apply the options
103 for (auto itCur = out_terms.rbegin(); !(itCur == out_terms.rend()); ++itCur) {
104 if (auto pAnyPredicate = dynamic_cast<AnyPredicate*>(itCur->getPtr())) {
105 if (auto pRegExPredicate = dynamic_cast<RegExPredicate*>(pAnyPredicate->pred.getPtr())) {
106 pRegExPredicate->setOptions(regex_options);
107 break;
108 }
109 }
110 }
111}
112
113/**
114 * Converts a `value_query` in the above grammar, with the given path, to a predicate.

Callers 2

valueQueryToPredicateFunction · 0.85
queryToPredicateFunction · 0.85

Calls 2

beginMethod · 0.80
setOptionsMethod · 0.80

Tested by

no test coverage detected