diff options
author | Justin Seyster <justin.seyster@mongodb.com> | 2017-10-23 11:38:06 -0400 |
---|---|---|
committer | Justin Seyster <justin.seyster@mongodb.com> | 2017-10-23 11:38:06 -0400 |
commit | c981f8578b30c3b8d86dc06605feb292264cebc2 (patch) | |
tree | b27b682942b1e631c1a9444576fc450467eeb2a5 /src/mongo/db/matcher/expression_with_placeholder.cpp | |
parent | aaf8430d5f311114cb758eb6731f87537f6fc9e6 (diff) | |
download | mongo-c981f8578b30c3b8d86dc06605feb292264cebc2.tar.gz |
SERVER-30751 Use optimized MatchExpressions in JSON parser test.
The JSON Schema parser tests check that the output of the parser
matches an expected MatchExpression. The initial output of the parser
often includes a lot of unnecessary $and and $or stages that make it
confusing to read. Optimizing this output and using that for the check
instead makes the test more readable and adds some additional testing
for the optimizer.
This patch also adds getOptimizer() logic to a few MatchExpression
classes that still needed it.
Diffstat (limited to 'src/mongo/db/matcher/expression_with_placeholder.cpp')
-rw-r--r-- | src/mongo/db/matcher/expression_with_placeholder.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/mongo/db/matcher/expression_with_placeholder.cpp b/src/mongo/db/matcher/expression_with_placeholder.cpp index 86287c18bf8..5593d9ac4c5 100644 --- a/src/mongo/db/matcher/expression_with_placeholder.cpp +++ b/src/mongo/db/matcher/expression_with_placeholder.cpp @@ -114,4 +114,18 @@ StatusWith<std::unique_ptr<ExpressionWithPlaceholder>> ExpressionWithPlaceholder return {std::move(exprWithPlaceholder)}; } +void ExpressionWithPlaceholder::optimizeFilter() { + _filter = MatchExpression::optimize(std::move(_filter)); + + auto newPlaceholder = parseTopLevelFieldName(_filter.get()); + invariantOK(newPlaceholder.getStatus()); + + if (newPlaceholder.getValue()) { + _placeholder = newPlaceholder.getValue()->toString(); + dassert(std::regex_match(*_placeholder, placeholderRegex)); + } else { + _placeholder = boost::none; + } +} + } // namespace mongo |