diff options
author | Charlie Swanson <charlie.swanson@mongodb.com> | 2016-12-13 10:15:08 -0500 |
---|---|---|
committer | Charlie Swanson <charlie.swanson@mongodb.com> | 2016-12-16 16:24:32 -0500 |
commit | 37e720678f6e468726c6cc775a5dc898d080f0f3 (patch) | |
tree | 4bd6b4932cc0ac436c0d7c949f7e37df613684d2 /src/mongo/db/pipeline/parsed_inclusion_projection_test.cpp | |
parent | 0cd2bf29d5798a395a07e67ae79ede9a5cefd411 (diff) | |
download | mongo-37e720678f6e468726c6cc775a5dc898d080f0f3.tar.gz |
SERVER-25535 Remove injectExpressionContext().
These methods were formally used to propagate a new ExpressionContext to
stages, accumulators, or expressions which potentially needed to
comparisons. Originally, this was necessary since Pipeline parsing
happened outside of the collection lock and thus could not determine if
there was a default collation on the collection. This meant that the
collation could change after parsing and any operators that might
compare strings would need to know about it.
We have since moved parsing within the lock, so the collation can be
known at parse time and the ExpressionContext should not change. This
patch requires an ExpressionContext at construction time, and disallows
changing the collation on an ExpressionContext.
Diffstat (limited to 'src/mongo/db/pipeline/parsed_inclusion_projection_test.cpp')
-rw-r--r-- | src/mongo/db/pipeline/parsed_inclusion_projection_test.cpp | 133 |
1 files changed, 90 insertions, 43 deletions
diff --git a/src/mongo/db/pipeline/parsed_inclusion_projection_test.cpp b/src/mongo/db/pipeline/parsed_inclusion_projection_test.cpp index 611f5367e9a..c2610418a40 100644 --- a/src/mongo/db/pipeline/parsed_inclusion_projection_test.cpp +++ b/src/mongo/db/pipeline/parsed_inclusion_projection_test.cpp @@ -38,6 +38,7 @@ #include "mongo/db/pipeline/dependencies.h" #include "mongo/db/pipeline/document.h" #include "mongo/db/pipeline/document_value_test_util.h" +#include "mongo/db/pipeline/expression_context_for_test.h" #include "mongo/db/pipeline/value.h" #include "mongo/unittest/unittest.h" @@ -53,19 +54,23 @@ BSONObj wrapInLiteral(const T& arg) { TEST(InclusionProjection, ShouldThrowWhenParsingInvalidExpression) { ParsedInclusionProjection inclusion; - ASSERT_THROWS(inclusion.parse(BSON("a" << BSON("$gt" << BSON("bad" + const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); + ASSERT_THROWS(inclusion.parse(expCtx, + BSON("a" << BSON("$gt" << BSON("bad" << "arguments")))), UserException); } TEST(InclusionProjection, ShouldRejectProjectionWithNoOutputFields) { ParsedInclusionProjection inclusion; - ASSERT_THROWS(inclusion.parse(BSON("_id" << false)), UserException); + const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); + ASSERT_THROWS(inclusion.parse(expCtx, BSON("_id" << false)), UserException); } TEST(InclusionProjection, ShouldAddIncludedFieldsToDependencies) { ParsedInclusionProjection inclusion; - inclusion.parse(BSON("_id" << false << "a" << true << "x.y" << true)); + const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); + inclusion.parse(expCtx, BSON("_id" << false << "a" << true << "x.y" << true)); DepsTracker deps; inclusion.addDependencies(&deps); @@ -78,7 +83,8 @@ TEST(InclusionProjection, ShouldAddIncludedFieldsToDependencies) { TEST(InclusionProjection, ShouldAddIdToDependenciesIfNotSpecified) { ParsedInclusionProjection inclusion; - inclusion.parse(BSON("a" << true)); + const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); + inclusion.parse(expCtx, BSON("a" << true)); DepsTracker deps; inclusion.addDependencies(&deps); @@ -90,7 +96,9 @@ TEST(InclusionProjection, ShouldAddIdToDependenciesIfNotSpecified) { TEST(InclusionProjection, ShouldAddDependenciesOfComputedFields) { ParsedInclusionProjection inclusion; - inclusion.parse(BSON("a" + const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); + inclusion.parse(expCtx, + BSON("a" << "$a" << "x" << "$z")); @@ -106,7 +114,9 @@ TEST(InclusionProjection, ShouldAddDependenciesOfComputedFields) { TEST(InclusionProjection, ShouldAddPathToDependenciesForNestedComputedFields) { ParsedInclusionProjection inclusion; - inclusion.parse(BSON("x.y" + const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); + inclusion.parse(expCtx, + BSON("x.y" << "$z")); DepsTracker deps; @@ -123,7 +133,8 @@ TEST(InclusionProjection, ShouldAddPathToDependenciesForNestedComputedFields) { TEST(InclusionProjection, ShouldSerializeToEquivalentProjection) { ParsedInclusionProjection inclusion; - inclusion.parse(fromjson("{a: {$add: ['$a', 2]}, b: {d: 3}, 'x.y': {$literal: 4}}")); + const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); + inclusion.parse(expCtx, fromjson("{a: {$add: ['$a', 2]}, b: {d: 3}, 'x.y': {$literal: 4}}")); // Adds implicit "_id" inclusion, converts numbers to bools, serializes expressions. auto expectedSerialization = Document(fromjson( @@ -136,7 +147,8 @@ TEST(InclusionProjection, ShouldSerializeToEquivalentProjection) { TEST(InclusionProjection, ShouldSerializeExplicitExclusionOfId) { ParsedInclusionProjection inclusion; - inclusion.parse(BSON("_id" << false << "a" << true)); + const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); + inclusion.parse(expCtx, BSON("_id" << false << "a" << true)); // Adds implicit "_id" inclusion, converts numbers to bools, serializes expressions. auto expectedSerialization = Document{{"_id", false}, {"a", true}}; @@ -149,7 +161,8 @@ TEST(InclusionProjection, ShouldSerializeExplicitExclusionOfId) { TEST(InclusionProjection, ShouldOptimizeTopLevelExpressions) { ParsedInclusionProjection inclusion; - inclusion.parse(BSON("a" << BSON("$add" << BSON_ARRAY(1 << 2)))); + const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); + inclusion.parse(expCtx, BSON("a" << BSON("$add" << BSON_ARRAY(1 << 2)))); inclusion.optimize(); @@ -162,7 +175,8 @@ TEST(InclusionProjection, ShouldOptimizeTopLevelExpressions) { TEST(InclusionProjection, ShouldOptimizeNestedExpressions) { ParsedInclusionProjection inclusion; - inclusion.parse(BSON("a.b" << BSON("$add" << BSON_ARRAY(1 << 2)))); + const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); + inclusion.parse(expCtx, BSON("a.b" << BSON("$add" << BSON_ARRAY(1 << 2)))); inclusion.optimize(); @@ -176,10 +190,13 @@ TEST(InclusionProjection, ShouldOptimizeNestedExpressions) { TEST(InclusionProjection, ShouldReportThatAllExceptIncludedFieldsAreModified) { ParsedInclusionProjection inclusion; - inclusion.parse(BSON( - "a" << wrapInLiteral("computedVal") << "b.c" << wrapInLiteral("computedVal") << "d" << true - << "e.f" - << true)); + const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); + inclusion.parse( + expCtx, + BSON("a" << wrapInLiteral("computedVal") << "b.c" << wrapInLiteral("computedVal") << "d" + << true + << "e.f" + << true)); auto modifiedPaths = inclusion.getModifiedPaths(); ASSERT(modifiedPaths.type == DocumentSource::GetModPathsReturn::Type::kAllExcept); @@ -195,7 +212,9 @@ TEST(InclusionProjection, ShouldReportThatAllExceptIncludedFieldsAreModified) { TEST(InclusionProjection, ShouldReportThatAllExceptIncludedFieldsAreModifiedWithIdExclusion) { ParsedInclusionProjection inclusion; - inclusion.parse(BSON("_id" << false << "a" << wrapInLiteral("computedVal") << "b.c" + const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); + inclusion.parse(expCtx, + BSON("_id" << false << "a" << wrapInLiteral("computedVal") << "b.c" << wrapInLiteral("computedVal") << "d" << true @@ -222,7 +241,8 @@ TEST(InclusionProjection, ShouldReportThatAllExceptIncludedFieldsAreModifiedWith TEST(InclusionProjectionExecutionTest, ShouldIncludeTopLevelField) { ParsedInclusionProjection inclusion; - inclusion.parse(BSON("a" << true)); + const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); + inclusion.parse(expCtx, BSON("a" << true)); // More than one field in document. auto result = inclusion.applyProjection(Document{{"a", 1}, {"b", 2}}); @@ -247,7 +267,8 @@ TEST(InclusionProjectionExecutionTest, ShouldIncludeTopLevelField) { TEST(InclusionProjectionExecutionTest, ShouldAddComputedTopLevelField) { ParsedInclusionProjection inclusion; - inclusion.parse(BSON("newField" << wrapInLiteral("computedVal"))); + const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); + inclusion.parse(expCtx, BSON("newField" << wrapInLiteral("computedVal"))); auto result = inclusion.applyProjection(Document{}); auto expectedResult = Document{{"newField", "computedVal"_sd}}; ASSERT_DOCUMENT_EQ(result, expectedResult); @@ -260,7 +281,8 @@ TEST(InclusionProjectionExecutionTest, ShouldAddComputedTopLevelField) { TEST(InclusionProjectionExecutionTest, ShouldApplyBothInclusionsAndComputedFields) { ParsedInclusionProjection inclusion; - inclusion.parse(BSON("a" << true << "newField" << wrapInLiteral("computedVal"))); + const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); + inclusion.parse(expCtx, BSON("a" << true << "newField" << wrapInLiteral("computedVal"))); auto result = inclusion.applyProjection(Document{{"a", 1}}); auto expectedResult = Document{{"a", 1}, {"newField", "computedVal"_sd}}; ASSERT_DOCUMENT_EQ(result, expectedResult); @@ -268,7 +290,8 @@ TEST(InclusionProjectionExecutionTest, ShouldApplyBothInclusionsAndComputedField TEST(InclusionProjectionExecutionTest, ShouldIncludeFieldsInOrderOfInputDoc) { ParsedInclusionProjection inclusion; - inclusion.parse(BSON("first" << true << "second" << true << "third" << true)); + const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); + inclusion.parse(expCtx, BSON("first" << true << "second" << true << "third" << true)); auto inputDoc = Document{{"second", 1}, {"first", 0}, {"third", 2}}; auto result = inclusion.applyProjection(inputDoc); ASSERT_DOCUMENT_EQ(result, inputDoc); @@ -276,7 +299,9 @@ TEST(InclusionProjectionExecutionTest, ShouldIncludeFieldsInOrderOfInputDoc) { TEST(InclusionProjectionExecutionTest, ShouldApplyComputedFieldsInOrderSpecified) { ParsedInclusionProjection inclusion; - inclusion.parse(BSON("firstComputed" << wrapInLiteral("FIRST") << "secondComputed" + const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); + inclusion.parse(expCtx, + BSON("firstComputed" << wrapInLiteral("FIRST") << "secondComputed" << wrapInLiteral("SECOND"))); auto result = inclusion.applyProjection(Document{{"first", 0}, {"second", 1}, {"third", 2}}); auto expectedResult = Document{{"firstComputed", "FIRST"_sd}, {"secondComputed", "SECOND"_sd}}; @@ -285,7 +310,8 @@ TEST(InclusionProjectionExecutionTest, ShouldApplyComputedFieldsInOrderSpecified TEST(InclusionProjectionExecutionTest, ShouldImplicitlyIncludeId) { ParsedInclusionProjection inclusion; - inclusion.parse(BSON("a" << true)); + const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); + inclusion.parse(expCtx, BSON("a" << true)); auto result = inclusion.applyProjection(Document{{"_id", "ID"_sd}, {"a", 1}, {"b", 2}}); auto expectedResult = Document{{"_id", "ID"_sd}, {"a", 1}}; ASSERT_DOCUMENT_EQ(result, expectedResult); @@ -298,7 +324,8 @@ TEST(InclusionProjectionExecutionTest, ShouldImplicitlyIncludeId) { TEST(InclusionProjectionExecutionTest, ShouldImplicitlyIncludeIdWithComputedFields) { ParsedInclusionProjection inclusion; - inclusion.parse(BSON("newField" << wrapInLiteral("computedVal"))); + const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); + inclusion.parse(expCtx, BSON("newField" << wrapInLiteral("computedVal"))); auto result = inclusion.applyProjection(Document{{"_id", "ID"_sd}, {"a", 1}}); auto expectedResult = Document{{"_id", "ID"_sd}, {"newField", "computedVal"_sd}}; ASSERT_DOCUMENT_EQ(result, expectedResult); @@ -306,7 +333,8 @@ TEST(InclusionProjectionExecutionTest, ShouldImplicitlyIncludeIdWithComputedFiel TEST(InclusionProjectionExecutionTest, ShouldIncludeIdIfExplicitlyIncluded) { ParsedInclusionProjection inclusion; - inclusion.parse(BSON("a" << true << "_id" << true << "b" << true)); + const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); + inclusion.parse(expCtx, BSON("a" << true << "_id" << true << "b" << true)); auto result = inclusion.applyProjection(Document{{"_id", "ID"_sd}, {"a", 1}, {"b", 2}, {"c", 3}}); auto expectedResult = Document{{"_id", "ID"_sd}, {"a", 1}, {"b", 2}}; @@ -315,7 +343,8 @@ TEST(InclusionProjectionExecutionTest, ShouldIncludeIdIfExplicitlyIncluded) { TEST(InclusionProjectionExecutionTest, ShouldExcludeIdIfExplicitlyExcluded) { ParsedInclusionProjection inclusion; - inclusion.parse(BSON("a" << true << "_id" << false)); + const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); + inclusion.parse(expCtx, BSON("a" << true << "_id" << false)); auto result = inclusion.applyProjection(Document{{"a", 1}, {"b", 2}, {"_id", "ID"_sd}}); auto expectedResult = Document{{"a", 1}}; ASSERT_DOCUMENT_EQ(result, expectedResult); @@ -323,7 +352,8 @@ TEST(InclusionProjectionExecutionTest, ShouldExcludeIdIfExplicitlyExcluded) { TEST(InclusionProjectionExecutionTest, ShouldReplaceIdWithComputedId) { ParsedInclusionProjection inclusion; - inclusion.parse(BSON("_id" << wrapInLiteral("newId"))); + const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); + inclusion.parse(expCtx, BSON("_id" << wrapInLiteral("newId"))); auto result = inclusion.applyProjection(Document{{"a", 1}, {"b", 2}, {"_id", "ID"_sd}}); auto expectedResult = Document{{"_id", "newId"_sd}}; ASSERT_DOCUMENT_EQ(result, expectedResult); @@ -335,7 +365,8 @@ TEST(InclusionProjectionExecutionTest, ShouldReplaceIdWithComputedId) { TEST(InclusionProjectionExecutionTest, ShouldIncludeSimpleDottedFieldFromSubDoc) { ParsedInclusionProjection inclusion; - inclusion.parse(BSON("a.b" << true)); + const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); + inclusion.parse(expCtx, BSON("a.b" << true)); // More than one field in sub document. auto result = inclusion.applyProjection(Document{{"a", Document{{"b", 1}, {"c", 2}}}}); @@ -360,7 +391,8 @@ TEST(InclusionProjectionExecutionTest, ShouldIncludeSimpleDottedFieldFromSubDoc) TEST(InclusionProjectionExecutionTest, ShouldNotCreateSubDocIfDottedIncludedFieldDoesNotExist) { ParsedInclusionProjection inclusion; - inclusion.parse(BSON("sub.target" << true)); + const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); + inclusion.parse(expCtx, BSON("sub.target" << true)); // Should not add the path if it doesn't exist. auto result = inclusion.applyProjection(Document{}); @@ -375,7 +407,8 @@ TEST(InclusionProjectionExecutionTest, ShouldNotCreateSubDocIfDottedIncludedFiel TEST(InclusionProjectionExecutionTest, ShouldApplyDottedInclusionToEachElementInArray) { ParsedInclusionProjection inclusion; - inclusion.parse(BSON("a.b" << true)); + const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); + inclusion.parse(expCtx, BSON("a.b" << true)); vector<Value> nestedValues = {Value(1), Value(Document{}), @@ -399,7 +432,8 @@ TEST(InclusionProjectionExecutionTest, ShouldApplyDottedInclusionToEachElementIn TEST(InclusionProjectionExecutionTest, ShouldAddComputedDottedFieldToSubDocument) { ParsedInclusionProjection inclusion; - inclusion.parse(BSON("sub.target" << wrapInLiteral("computedVal"))); + const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); + inclusion.parse(expCtx, BSON("sub.target" << wrapInLiteral("computedVal"))); // Other fields exist in sub document, one of which is the specified field. auto result = inclusion.applyProjection(Document{{"sub", Document{{"target", 1}, {"c", 2}}}}); @@ -419,7 +453,8 @@ TEST(InclusionProjectionExecutionTest, ShouldAddComputedDottedFieldToSubDocument TEST(InclusionProjectionExecutionTest, ShouldCreateSubDocIfDottedComputedFieldDoesntExist) { ParsedInclusionProjection inclusion; - inclusion.parse(BSON("sub.target" << wrapInLiteral("computedVal"))); + const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); + inclusion.parse(expCtx, BSON("sub.target" << wrapInLiteral("computedVal"))); // Should add the path if it doesn't exist. auto result = inclusion.applyProjection(Document{}); @@ -433,7 +468,8 @@ TEST(InclusionProjectionExecutionTest, ShouldCreateSubDocIfDottedComputedFieldDo TEST(InclusionProjectionExecutionTest, ShouldCreateNestedSubDocumentsAllTheWayToComputedField) { ParsedInclusionProjection inclusion; - inclusion.parse(BSON("a.b.c.d" << wrapInLiteral("computedVal"))); + const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); + inclusion.parse(expCtx, BSON("a.b.c.d" << wrapInLiteral("computedVal"))); // Should add the path if it doesn't exist. auto result = inclusion.applyProjection(Document{}); @@ -448,7 +484,8 @@ TEST(InclusionProjectionExecutionTest, ShouldCreateNestedSubDocumentsAllTheWayTo TEST(InclusionProjectionExecutionTest, ShouldAddComputedDottedFieldToEachElementInArray) { ParsedInclusionProjection inclusion; - inclusion.parse(BSON("a.b" << wrapInLiteral("COMPUTED"))); + const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); + inclusion.parse(expCtx, BSON("a.b" << wrapInLiteral("COMPUTED"))); vector<Value> nestedValues = {Value(1), Value(Document{}), @@ -471,7 +508,8 @@ TEST(InclusionProjectionExecutionTest, ShouldAddComputedDottedFieldToEachElement TEST(InclusionProjectionExecutionTest, ShouldApplyInclusionsAndAdditionsToEachElementInArray) { ParsedInclusionProjection inclusion; - inclusion.parse(BSON("a.inc" << true << "a.comp" << wrapInLiteral("COMPUTED"))); + const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); + inclusion.parse(expCtx, BSON("a.inc" << true << "a.comp" << wrapInLiteral("COMPUTED"))); vector<Value> nestedValues = {Value(1), Value(Document{}), @@ -498,7 +536,8 @@ TEST(InclusionProjectionExecutionTest, ShouldApplyInclusionsAndAdditionsToEachEl TEST(InclusionProjectionExecutionTest, ShouldAddOrIncludeSubFieldsOfId) { ParsedInclusionProjection inclusion; - inclusion.parse(BSON("_id.X" << true << "_id.Z" << wrapInLiteral("NEW"))); + const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); + inclusion.parse(expCtx, BSON("_id.X" << true << "_id.Z" << wrapInLiteral("NEW"))); auto result = inclusion.applyProjection(Document{{"_id", Document{{"X", 1}, {"Y", 2}}}}); auto expectedResult = Document{{"_id", Document{{"X", 1}, {"Z", "NEW"_sd}}}}; ASSERT_DOCUMENT_EQ(result, expectedResult); @@ -506,13 +545,16 @@ TEST(InclusionProjectionExecutionTest, ShouldAddOrIncludeSubFieldsOfId) { TEST(InclusionProjectionExecutionTest, ShouldAllowMixedNestedAndDottedFields) { ParsedInclusionProjection inclusion; + const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); // Include all of "a.b", "a.c", "a.d", and "a.e". // Add new computed fields "a.W", "a.X", "a.Y", and "a.Z". - inclusion.parse(BSON( - "a.b" << true << "a.c" << true << "a.W" << wrapInLiteral("W") << "a.X" << wrapInLiteral("X") - << "a" - << BSON("d" << true << "e" << true << "Y" << wrapInLiteral("Y") << "Z" - << wrapInLiteral("Z")))); + inclusion.parse( + expCtx, + BSON("a.b" << true << "a.c" << true << "a.W" << wrapInLiteral("W") << "a.X" + << wrapInLiteral("X") + << "a" + << BSON("d" << true << "e" << true << "Y" << wrapInLiteral("Y") << "Z" + << wrapInLiteral("Z")))); auto result = inclusion.applyProjection(Document{ {"a", Document{{"b", "b"_sd}, {"c", "c"_sd}, {"d", "d"_sd}, {"e", "e"_sd}, {"f", "f"_sd}}}}); @@ -530,7 +572,9 @@ TEST(InclusionProjectionExecutionTest, ShouldAllowMixedNestedAndDottedFields) { TEST(InclusionProjectionExecutionTest, ShouldApplyNestedComputedFieldsInOrderSpecified) { ParsedInclusionProjection inclusion; - inclusion.parse(BSON("a" << wrapInLiteral("FIRST") << "b.c" << wrapInLiteral("SECOND"))); + const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); + inclusion.parse(expCtx, + BSON("a" << wrapInLiteral("FIRST") << "b.c" << wrapInLiteral("SECOND"))); auto result = inclusion.applyProjection(Document{}); auto expectedResult = Document{{"a", "FIRST"_sd}, {"b", Document{{"c", "SECOND"_sd}}}}; ASSERT_DOCUMENT_EQ(result, expectedResult); @@ -538,7 +582,8 @@ TEST(InclusionProjectionExecutionTest, ShouldApplyNestedComputedFieldsInOrderSpe TEST(InclusionProjectionExecutionTest, ShouldApplyComputedFieldsAfterAllInclusions) { ParsedInclusionProjection inclusion; - inclusion.parse(BSON("b.c" << wrapInLiteral("NEW") << "a" << true)); + const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); + inclusion.parse(expCtx, BSON("b.c" << wrapInLiteral("NEW") << "a" << true)); auto result = inclusion.applyProjection(Document{{"a", 1}}); auto expectedResult = Document{{"a", 1}, {"b", Document{{"c", "NEW"_sd}}}}; ASSERT_DOCUMENT_EQ(result, expectedResult); @@ -557,7 +602,8 @@ TEST(InclusionProjectionExecutionTest, ShouldApplyComputedFieldsAfterAllInclusio TEST(InclusionProjectionExecutionTest, ComputedFieldReplacingExistingShouldAppearAfterInclusions) { ParsedInclusionProjection inclusion; - inclusion.parse(BSON("b" << wrapInLiteral("NEW") << "a" << true)); + const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); + inclusion.parse(expCtx, BSON("b" << wrapInLiteral("NEW") << "a" << true)); auto result = inclusion.applyProjection(Document{{"b", 1}, {"a", 1}}); auto expectedResult = Document{{"a", 1}, {"b", "NEW"_sd}}; ASSERT_DOCUMENT_EQ(result, expectedResult); @@ -572,7 +618,8 @@ TEST(InclusionProjectionExecutionTest, ComputedFieldReplacingExistingShouldAppea TEST(InclusionProjectionExecutionTest, ShouldAlwaysKeepMetadataFromOriginalDoc) { ParsedInclusionProjection inclusion; - inclusion.parse(BSON("a" << true)); + const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); + inclusion.parse(expCtx, BSON("a" << true)); MutableDocument inputDocBuilder(Document{{"a", 1}}); inputDocBuilder.setRandMetaField(1.0); |