summaryrefslogtreecommitdiff
path: root/src/mongo/db/pipeline/parsed_add_fields.h
diff options
context:
space:
mode:
authorJames Wahlin <james.wahlin@10gen.com>2017-04-05 09:59:54 -0400
committerJames Wahlin <james.wahlin@10gen.com>2017-04-29 09:21:00 -0400
commit5273c2bad7df58c44afdd677609b8656f399a906 (patch)
tree0257684f5555293d72e07179c6b058081c247019 /src/mongo/db/pipeline/parsed_add_fields.h
parent2e8e60bfef83ac9c7bf494b0f80977686cb1b772 (diff)
downloadmongo-5273c2bad7df58c44afdd677609b8656f399a906.tar.gz
SERVER-28651 Move agg var ownership to ExpressionContext
Diffstat (limited to 'src/mongo/db/pipeline/parsed_add_fields.h')
-rw-r--r--src/mongo/db/pipeline/parsed_add_fields.h32
1 files changed, 8 insertions, 24 deletions
diff --git a/src/mongo/db/pipeline/parsed_add_fields.h b/src/mongo/db/pipeline/parsed_add_fields.h
index f4c1b535f63..261dbb903aa 100644
--- a/src/mongo/db/pipeline/parsed_add_fields.h
+++ b/src/mongo/db/pipeline/parsed_add_fields.h
@@ -51,7 +51,8 @@ namespace parsed_aggregation_projection {
*/
class ParsedAddFields : public ParsedAggregationProjection {
public:
- ParsedAddFields() : ParsedAggregationProjection(), _root(new InclusionNode()) {}
+ ParsedAddFields(const boost::intrusive_ptr<ExpressionContext>& expCtx)
+ : ParsedAggregationProjection(expCtx), _root(new InclusionNode()) {}
/**
* Creates the data needed to perform an AddFields.
@@ -68,12 +69,7 @@ public:
/**
* Parses the addFields specification given by 'spec', populating internal data structures.
*/
- void parse(const boost::intrusive_ptr<ExpressionContext>& expCtx, const BSONObj& spec) final {
- VariablesIdGenerator idGenerator;
- VariablesParseState variablesParseState(&idGenerator);
- parse(expCtx, spec, variablesParseState);
- _variables = stdx::make_unique<Variables>(idGenerator.getIdCount());
- }
+ void parse(const BSONObj& spec) final;
Document serialize(boost::optional<ExplainOptions::Verbosity> explain) const final {
MutableDocument output;
@@ -115,21 +111,15 @@ public:
* with {"0": "hello"}. See SERVER-25200 for more details.
*/
Document applyProjection(Document inputDoc) const final {
- _variables->setRoot(inputDoc);
- return applyProjection(inputDoc, _variables.get());
+ auto& variables = _expCtx->variables;
+ variables.setRoot(inputDoc);
+ return applyProjection(inputDoc, &variables);
}
Document applyProjection(Document inputDoc, Variables* vars) const;
private:
/**
- * Parses 'spec' to determine which fields to add.
- */
- void parse(const boost::intrusive_ptr<ExpressionContext>& expCtx,
- const BSONObj& spec,
- const VariablesParseState& variablesParseState);
-
- /**
* Attempts to parse 'objSpec' as an expression like {$add: [...]}. Adds a computed field to
* '_root' and returns true if it was successfully parsed as an expression. Returns false if it
* was not an expression specification.
@@ -137,8 +127,7 @@ private:
* Throws an error if it was determined to be an expression specification, but failed to parse
* as a valid expression.
*/
- bool parseObjectAsExpression(const boost::intrusive_ptr<ExpressionContext>& expCtx,
- StringData pathToObject,
+ bool parseObjectAsExpression(StringData pathToObject,
const BSONObj& objSpec,
const VariablesParseState& variablesParseState);
@@ -146,17 +135,12 @@ private:
* Traverses 'subObj' and parses each field. Adds any computed fields at this level
* to 'node'.
*/
- void parseSubObject(const boost::intrusive_ptr<ExpressionContext>& expCtx,
- const BSONObj& subObj,
+ void parseSubObject(const BSONObj& subObj,
const VariablesParseState& variablesParseState,
InclusionNode* node);
// The InclusionNode tree does most of the execution work once constructed.
std::unique_ptr<InclusionNode> _root;
-
- // This is needed to give the expressions knowledge about the context in which they are being
- // executed.
- std::unique_ptr<Variables> _variables;
};
} // namespace parsed_aggregation_projection
} // namespace mongo