diff options
author | Alya Berciu <alyacarina@gmail.com> | 2021-07-08 10:18:08 +0100 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-07-21 16:21:35 +0000 |
commit | 46cb6af3e5374a29b22abc705b5eb186ced9fc31 (patch) | |
tree | edf177f2d1f608626298da7a986eb033f3c980d9 /src/mongo/db/pipeline/pipeline.cpp | |
parent | 106d97102a267ec53fe596901997cb2516ce23a0 (diff) | |
download | mongo-46cb6af3e5374a29b22abc705b5eb186ced9fc31.tar.gz |
SERVER-32548 Add $lookup support for sharded views
Diffstat (limited to 'src/mongo/db/pipeline/pipeline.cpp')
-rw-r--r-- | src/mongo/db/pipeline/pipeline.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/mongo/db/pipeline/pipeline.cpp b/src/mongo/db/pipeline/pipeline.cpp index a8194b1f305..cf298b0a492 100644 --- a/src/mongo/db/pipeline/pipeline.cpp +++ b/src/mongo/db/pipeline/pipeline.cpp @@ -42,6 +42,7 @@ #include "mongo/db/pipeline/document_source_merge.h" #include "mongo/db/pipeline/document_source_out.h" #include "mongo/db/pipeline/expression_context.h" +#include "mongo/db/pipeline/lite_parsed_pipeline.h" #include "mongo/db/query/query_knobs_gen.h" #include "mongo/db/storage/storage_options.h" #include "mongo/util/fail_point.h" @@ -657,4 +658,32 @@ std::unique_ptr<Pipeline, PipelineDeleter> Pipeline::makePipeline( return pipeline; } + +std::unique_ptr<Pipeline, PipelineDeleter> Pipeline::makePipelineFromViewDefinition( + const boost::intrusive_ptr<ExpressionContext>& expCtx, + ExpressionContext::ResolvedNamespace resolvedNs, + std::vector<BSONObj> currentPipeline, + MakePipelineOptions opts) { + + // Copy the ExpressionContext of the base aggregation, using the inner namespace instead. + auto subPipelineExpCtx = expCtx->copyForSubPipeline(resolvedNs.ns); + + if (resolvedNs.pipeline.empty()) { + return Pipeline::makePipeline(std::move(currentPipeline), subPipelineExpCtx, opts); + } + auto resolvedPipeline = std::move(resolvedNs.pipeline); + + // When we get a resolved pipeline back, we may not yet have its namespaces available in the + // expression context, e.g. if the view's pipeline contains a $lookup on another collection. + LiteParsedPipeline liteParsedPipeline(resolvedNs.ns, resolvedPipeline); + subPipelineExpCtx->addResolvedNamespaces(liteParsedPipeline.getInvolvedNamespaces()); + + resolvedPipeline.reserve(currentPipeline.size() + resolvedPipeline.size()); + resolvedPipeline.insert(resolvedPipeline.end(), + std::make_move_iterator(currentPipeline.begin()), + std::make_move_iterator(currentPipeline.end())); + + return Pipeline::makePipeline(std::move(resolvedPipeline), subPipelineExpCtx, opts); +} + } // namespace mongo |