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/document_source_lookup_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/document_source_lookup_test.cpp')
-rw-r--r-- | src/mongo/db/pipeline/document_source_lookup_test.cpp | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/src/mongo/db/pipeline/document_source_lookup_test.cpp b/src/mongo/db/pipeline/document_source_lookup_test.cpp index 0f54e3741c4..9da414ec6f6 100644 --- a/src/mongo/db/pipeline/document_source_lookup_test.cpp +++ b/src/mongo/db/pipeline/document_source_lookup_test.cpp @@ -54,6 +54,10 @@ using std::vector; using DocumentSourceLookUpTest = AggregationContextFixture; TEST_F(DocumentSourceLookUpTest, ShouldTruncateOutputSortOnAsField) { + auto expCtx = getExpCtx(); + NamespaceString fromNs("test", "a"); + expCtx->setResolvedNamespace(fromNs, {fromNs, std::vector<BSONObj>{}}); + intrusive_ptr<DocumentSourceMock> source = DocumentSourceMock::create(); source->sorts = {BSON("a" << 1 << "d.e" << 1 << "c" << 1)}; auto lookup = DocumentSourceLookUp::createFromBson(Document{{"$lookup", @@ -63,7 +67,7 @@ TEST_F(DocumentSourceLookUpTest, ShouldTruncateOutputSortOnAsField) { {"as", "d.e"_sd}}}} .toBson() .firstElement(), - getExpCtx()); + expCtx); lookup->setSource(source.get()); BSONObjSet outputSort = lookup->getOutputSorts(); @@ -73,6 +77,10 @@ TEST_F(DocumentSourceLookUpTest, ShouldTruncateOutputSortOnAsField) { } TEST_F(DocumentSourceLookUpTest, ShouldTruncateOutputSortOnSuffixOfAsField) { + auto expCtx = getExpCtx(); + NamespaceString fromNs("test", "a"); + expCtx->setResolvedNamespace(fromNs, {fromNs, std::vector<BSONObj>{}}); + intrusive_ptr<DocumentSourceMock> source = DocumentSourceMock::create(); source->sorts = {BSON("a" << 1 << "d.e" << 1 << "c" << 1)}; auto lookup = DocumentSourceLookUp::createFromBson(Document{{"$lookup", @@ -82,7 +90,7 @@ TEST_F(DocumentSourceLookUpTest, ShouldTruncateOutputSortOnSuffixOfAsField) { {"as", "d"_sd}}}} .toBson() .firstElement(), - getExpCtx()); + expCtx); lookup->setSource(source.get()); BSONObjSet outputSort = lookup->getOutputSorts(); @@ -158,7 +166,6 @@ public: } pipeline.getValue()->addInitialSource(DocumentSourceMock::create(_mockResults)); - pipeline.getValue()->injectExpressionContext(expCtx); pipeline.getValue()->optimizePipeline(); return pipeline; @@ -171,7 +178,7 @@ private: TEST_F(DocumentSourceLookUpTest, ShouldPropagatePauses) { auto expCtx = getExpCtx(); NamespaceString fromNs("test", "foreign"); - expCtx->resolvedNamespaces[fromNs.coll()] = {fromNs, std::vector<BSONObj>{}}; + expCtx->setResolvedNamespace(fromNs, {fromNs, std::vector<BSONObj>{}}); // Set up the $lookup stage. auto lookupSpec = Document{{"$lookup", @@ -191,7 +198,6 @@ TEST_F(DocumentSourceLookUpTest, ShouldPropagatePauses) { DocumentSource::GetNextResult::makePauseExecution()}); lookup->setSource(mockLocalSource.get()); - lookup->injectExpressionContext(expCtx); // Mock out the foreign collection. deque<DocumentSource::GetNextResult> mockForeignContents{Document{{"_id", 0}}, @@ -222,7 +228,7 @@ TEST_F(DocumentSourceLookUpTest, ShouldPropagatePauses) { TEST_F(DocumentSourceLookUpTest, ShouldPropagatePausesWhileUnwinding) { auto expCtx = getExpCtx(); NamespaceString fromNs("test", "foreign"); - expCtx->resolvedNamespaces[fromNs.coll()] = {fromNs, std::vector<BSONObj>{}}; + expCtx->setResolvedNamespace(fromNs, {fromNs, std::vector<BSONObj>{}}); // Set up the $lookup stage. auto lookupSpec = Document{{"$lookup", @@ -247,8 +253,6 @@ TEST_F(DocumentSourceLookUpTest, ShouldPropagatePausesWhileUnwinding) { DocumentSource::GetNextResult::makePauseExecution()}); lookup->setSource(mockLocalSource.get()); - lookup->injectExpressionContext(expCtx); - // Mock out the foreign collection. deque<DocumentSource::GetNextResult> mockForeignContents{Document{{"_id", 0}}, Document{{"_id", 1}}}; @@ -276,7 +280,7 @@ TEST_F(DocumentSourceLookUpTest, ShouldPropagatePausesWhileUnwinding) { TEST_F(DocumentSourceLookUpTest, LookupReportsAsFieldIsModified) { auto expCtx = getExpCtx(); NamespaceString fromNs("test", "foreign"); - expCtx->resolvedNamespaces[fromNs.coll()] = {fromNs, std::vector<BSONObj>{}}; + expCtx->setResolvedNamespace(fromNs, {fromNs, std::vector<BSONObj>{}}); // Set up the $lookup stage. auto lookupSpec = Document{{"$lookup", @@ -297,7 +301,7 @@ TEST_F(DocumentSourceLookUpTest, LookupReportsAsFieldIsModified) { TEST_F(DocumentSourceLookUpTest, LookupReportsFieldsModifiedByAbsorbedUnwind) { auto expCtx = getExpCtx(); NamespaceString fromNs("test", "foreign"); - expCtx->resolvedNamespaces[fromNs.coll()] = {fromNs, std::vector<BSONObj>{}}; + expCtx->setResolvedNamespace(fromNs, {fromNs, std::vector<BSONObj>{}}); // Set up the $lookup stage. auto lookupSpec = Document{{"$lookup", |