diff options
Diffstat (limited to 'src/mongo/db/query/canonical_query_test.cpp')
| -rw-r--r-- | src/mongo/db/query/canonical_query_test.cpp | 55 |
1 files changed, 8 insertions, 47 deletions
diff --git a/src/mongo/db/query/canonical_query_test.cpp b/src/mongo/db/query/canonical_query_test.cpp index 5cba0bcc3f4..dbb2fd929da 100644 --- a/src/mongo/db/query/canonical_query_test.cpp +++ b/src/mongo/db/query/canonical_query_test.cpp @@ -279,52 +279,11 @@ TEST(CanonicalQueryTest, CanonicalizeFromBaseQuery) { assertGet(CanonicalQuery::canonicalize(opCtx.get(), std::move(findCommand), isExplain)); MatchExpression* firstClauseExpr = baseCq->root()->getChild(0); - auto childCq = assertGet(CanonicalQuery::makeForSubplanner(opCtx.get(), *baseCq, 0)); + auto childCq = assertGet(CanonicalQuery::canonicalize(opCtx.get(), *baseCq, firstClauseExpr)); - ASSERT_BSONOBJ_EQ(childCq->getFindCommandRequest().getFilter(), firstClauseExpr->serialize()); - - ASSERT_BSONOBJ_EQ(childCq->getFindCommandRequest().getProjection(), - baseCq->getFindCommandRequest().getProjection()); - ASSERT_BSONOBJ_EQ(childCq->getFindCommandRequest().getSort(), - baseCq->getFindCommandRequest().getSort()); - ASSERT_TRUE(childCq->getExplain()); -} - -TEST(CanonicalQueryTest, CanonicalizeFromBaseQueryWithSpecialFeature) { - // Like the above test, but use $text which is a 'special feature' not always allowed. This is - // meant to reproduce SERVER-XYZ. - QueryTestServiceContext serviceContext; - auto opCtx = serviceContext.makeOperationContext(); - - const bool isExplain = true; - const std::string cmdStr = R"({ - find:'bogusns', - filter: { - $or:[ - {a: 'foo'}, - {$text: {$search: 'bar'}} - ] - }, - projection: {a:1}, - sort: {b:1}, - $db: 'test' - })"; - auto findCommand = query_request_helper::makeFromFindCommandForTests(fromjson(cmdStr)); - auto baseCq = - assertGet(CanonicalQuery::canonicalize(opCtx.get(), - std::move(findCommand), - isExplain, - nullptr, - ExtensionsCallbackNoop(), - MatchExpressionParser::kAllowAllSpecialFeatures)); - - // Note: be sure to use the second child to get $text, since we 'normalize' and sort the - // MatchExpression tree as part of canonicalization. This will put the text search clause - // second. - MatchExpression* secondClauseExpr = baseCq->root()->getChild(1); - auto childCq = assertGet(CanonicalQuery::makeForSubplanner(opCtx.get(), *baseCq, 1)); - - ASSERT_BSONOBJ_EQ(childCq->getFindCommandRequest().getFilter(), secondClauseExpr->serialize()); + BSONObjBuilder expectedFilter; + firstClauseExpr->serialize(&expectedFilter); + ASSERT_BSONOBJ_EQ(childCq->getFindCommandRequest().getFilter(), expectedFilter.obj()); ASSERT_BSONOBJ_EQ(childCq->getFindCommandRequest().getProjection(), baseCq->getFindCommandRequest().getProjection()); @@ -361,7 +320,8 @@ TEST(CanonicalQueryTest, CanonicalQueryFromBaseQueryWithNoCollation) { auto findCommand = std::make_unique<FindCommandRequest>(nss); findCommand->setFilter(fromjson("{$or:[{a:1,b:1},{a:1,c:1}]}")); auto baseCq = assertGet(CanonicalQuery::canonicalize(opCtx.get(), std::move(findCommand))); - auto childCq = assertGet(CanonicalQuery::makeForSubplanner(opCtx.get(), *baseCq, 0)); + MatchExpression* firstClauseExpr = baseCq->root()->getChild(0); + auto childCq = assertGet(CanonicalQuery::canonicalize(opCtx.get(), *baseCq, firstClauseExpr)); ASSERT_TRUE(baseCq->getCollator() == nullptr); ASSERT_TRUE(childCq->getCollator() == nullptr); } @@ -375,7 +335,8 @@ TEST(CanonicalQueryTest, CanonicalQueryFromBaseQueryWithCollation) { findCommand->setCollation(BSON("locale" << "reverse")); auto baseCq = assertGet(CanonicalQuery::canonicalize(opCtx.get(), std::move(findCommand))); - auto childCq = assertGet(CanonicalQuery::makeForSubplanner(opCtx.get(), *baseCq, 0)); + MatchExpression* firstClauseExpr = baseCq->root()->getChild(0); + auto childCq = assertGet(CanonicalQuery::canonicalize(opCtx.get(), *baseCq, firstClauseExpr)); ASSERT(baseCq->getCollator()); ASSERT(childCq->getCollator()); ASSERT_TRUE(*(childCq->getCollator()) == *(baseCq->getCollator())); |
