summaryrefslogtreecommitdiff
path: root/src/mongo/db/pipeline
diff options
context:
space:
mode:
authorJacob Evans <jacob.evans@10gen.com>2020-07-07 17:39:11 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-07-13 23:46:06 +0000
commit60e04b716c909497ab91f6bbadf332c36f007446 (patch)
treee8fd6ed5bae78c288d9ef94b6bd6e1939283d6bd /src/mongo/db/pipeline
parentc31cac2855eb84c9bc824852773265c8e0b60a4e (diff)
downloadmongo-60e04b716c909497ab91f6bbadf332c36f007446.tar.gz
SERVER-49043 Begin CST -> Pipeline translation
Diffstat (limited to 'src/mongo/db/pipeline')
-rw-r--r--src/mongo/db/pipeline/document_source_project.cpp12
-rw-r--r--src/mongo/db/pipeline/document_source_project.h19
2 files changed, 25 insertions, 6 deletions
diff --git a/src/mongo/db/pipeline/document_source_project.cpp b/src/mongo/db/pipeline/document_source_project.cpp
index 657350dc656..e5f048a8e3d 100644
--- a/src/mongo/db/pipeline/document_source_project.cpp
+++ b/src/mongo/db/pipeline/document_source_project.cpp
@@ -37,7 +37,6 @@
#include "mongo/db/exec/projection_executor.h"
#include "mongo/db/exec/projection_executor_builder.h"
#include "mongo/db/pipeline/lite_parsed_document_source.h"
-#include "mongo/db/query/projection_parser.h"
namespace mongo {
@@ -62,7 +61,9 @@ BSONObj buildExclusionProjectionSpecification(const std::vector<BSONElement>& un
} // namespace
intrusive_ptr<DocumentSource> DocumentSourceProject::create(
- BSONObj projectSpec, const intrusive_ptr<ExpressionContext>& expCtx, StringData specifiedName) {
+ projection_ast::Projection projection,
+ const intrusive_ptr<ExpressionContext>& expCtx,
+ StringData specifiedName) {
const bool isIndependentOfAnyCollection = false;
intrusive_ptr<DocumentSource> project(new DocumentSourceSingleDocumentTransformation(
expCtx,
@@ -72,8 +73,6 @@ intrusive_ptr<DocumentSource> DocumentSourceProject::create(
// here so we can add the name that was actually specified by the user, be it $project
// or an alias.
try {
- auto policies = ProjectionPolicies::aggregateProjectionPolicies();
- auto projection = projection_ast::parse(expCtx, projectSpec, policies);
// We won't optimize the executor on creation, and will do it as part of the
// pipeline optimization process when requested via the 'optimize()' method on
// 'DocumentSourceSingleDocumentTransformation', so we won't pass the
@@ -87,7 +86,10 @@ intrusive_ptr<DocumentSource> DocumentSourceProject::create(
projection_executor::kDefaultBuilderParams};
builderParams.reset(projection_executor::kOptimizeExecutor);
return projection_executor::buildProjectionExecutor(
- expCtx, &projection, policies, builderParams);
+ expCtx,
+ &projection,
+ ProjectionPolicies::aggregateProjectionPolicies(),
+ builderParams);
} catch (DBException& ex) {
ex.addContext("Invalid " + specifiedName.toString());
throw;
diff --git a/src/mongo/db/pipeline/document_source_project.h b/src/mongo/db/pipeline/document_source_project.h
index 43ee90fce0f..13d45282a75 100644
--- a/src/mongo/db/pipeline/document_source_project.h
+++ b/src/mongo/db/pipeline/document_source_project.h
@@ -30,6 +30,7 @@
#pragma once
#include "mongo/db/pipeline/document_source_single_document_transformation.h"
+#include "mongo/db/query/projection_parser.h"
namespace mongo {
@@ -45,12 +46,28 @@ public:
static constexpr StringData kAliasNameUnset = "$unset"_sd;
/**
+ * Method to create a $project stage from a Projection AST.
+ */
+ static boost::intrusive_ptr<DocumentSource> create(
+ projection_ast::Projection projection,
+ const boost::intrusive_ptr<ExpressionContext>& expCtx,
+ StringData specifiedName);
+
+ /**
* Convenience method to create a $project stage from 'projectSpec'.
*/
static boost::intrusive_ptr<DocumentSource> create(
BSONObj projectSpec,
const boost::intrusive_ptr<ExpressionContext>& expCtx,
- StringData specifiedName);
+ StringData specifiedName) try {
+ return create(projection_ast::parse(
+ expCtx, projectSpec, ProjectionPolicies::aggregateProjectionPolicies()),
+ expCtx,
+ specifiedName);
+ } catch (DBException& ex) {
+ ex.addContext("Invalid " + specifiedName.toString());
+ throw;
+ }
/**
* Parses a $project stage from the user-supplied BSON.