summaryrefslogtreecommitdiff
path: root/src/mongo/db/pipeline/document_source_redact.cpp
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/document_source_redact.cpp
parent2e8e60bfef83ac9c7bf494b0f80977686cb1b772 (diff)
downloadmongo-5273c2bad7df58c44afdd677609b8656f399a906.tar.gz
SERVER-28651 Move agg var ownership to ExpressionContext
Diffstat (limited to 'src/mongo/db/pipeline/document_source_redact.cpp')
-rw-r--r--src/mongo/db/pipeline/document_source_redact.cpp27
1 files changed, 14 insertions, 13 deletions
diff --git a/src/mongo/db/pipeline/document_source_redact.cpp b/src/mongo/db/pipeline/document_source_redact.cpp
index ae79729f2e0..738a55cc056 100644
--- a/src/mongo/db/pipeline/document_source_redact.cpp
+++ b/src/mongo/db/pipeline/document_source_redact.cpp
@@ -63,8 +63,9 @@ static const Value keepVal = Value("keep"_sd);
DocumentSource::GetNextResult DocumentSourceRedact::getNext() {
auto nextInput = pSource->getNext();
for (; nextInput.isAdvanced(); nextInput = pSource->getNext()) {
- _variables->setRoot(nextInput.getDocument());
- _variables->setValue(_currentId, Value(nextInput.releaseDocument()));
+ auto& variables = pExpCtx->variables;
+ variables.setRoot(nextInput.getDocument());
+ variables.setValue(_currentId, Value(nextInput.releaseDocument()));
if (boost::optional<Document> result = redactObject()) {
return std::move(*result);
}
@@ -99,7 +100,7 @@ Pipeline::SourceContainer::iterator DocumentSourceRedact::doOptimizeAt(
Value DocumentSourceRedact::redactValue(const Value& in) {
const BSONType valueType = in.getType();
if (valueType == Object) {
- _variables->setValue(_currentId, in);
+ pExpCtx->variables.setValue(_currentId, in);
const boost::optional<Document> result = redactObject();
if (result) {
return Value(*result);
@@ -127,22 +128,23 @@ Value DocumentSourceRedact::redactValue(const Value& in) {
}
boost::optional<Document> DocumentSourceRedact::redactObject() {
- const Value expressionResult = _expression->evaluate(_variables.get());
+ auto& variables = pExpCtx->variables;
+ const Value expressionResult = _expression->evaluate();
ValueComparator simpleValueCmp;
if (simpleValueCmp.evaluate(expressionResult == keepVal)) {
- return _variables->getDocument(_currentId);
+ return variables.getDocument(_currentId);
} else if (simpleValueCmp.evaluate(expressionResult == pruneVal)) {
return boost::optional<Document>();
} else if (simpleValueCmp.evaluate(expressionResult == descendVal)) {
- const Document in = _variables->getDocument(_currentId);
+ const Document in = variables.getDocument(_currentId);
MutableDocument out;
out.copyMetaDataFrom(in);
FieldIterator fields(in);
while (fields.more()) {
const Document::FieldPair field(fields.next());
- // This changes CURRENT so don't read from _variables after this
+ // This changes CURRENT so don't read from variables after this
const Value val = redactValue(field.second);
if (!val.missing()) {
out.addField(field.first, val);
@@ -169,8 +171,7 @@ Value DocumentSourceRedact::serialize(boost::optional<ExplainOptions::Verbosity>
intrusive_ptr<DocumentSource> DocumentSourceRedact::createFromBson(
BSONElement elem, const intrusive_ptr<ExpressionContext>& expCtx) {
- VariablesIdGenerator idGenerator;
- VariablesParseState vps(&idGenerator);
+ VariablesParseState vps = expCtx->variablesParseState;
Variables::Id currentId = vps.defineVariable("CURRENT"); // will differ from ROOT
Variables::Id decendId = vps.defineVariable("DESCEND");
Variables::Id pruneId = vps.defineVariable("PRUNE");
@@ -181,10 +182,10 @@ intrusive_ptr<DocumentSource> DocumentSourceRedact::createFromBson(
// TODO figure out how much of this belongs in constructor and how much here.
// Set up variables. Never need to reset DESCEND, PRUNE, or KEEP.
source->_currentId = currentId;
- source->_variables.reset(new Variables(idGenerator.getIdCount()));
- source->_variables->setValue(decendId, descendVal);
- source->_variables->setValue(pruneId, pruneVal);
- source->_variables->setValue(keepId, keepVal);
+ auto& variables = expCtx->variables;
+ variables.setValue(decendId, descendVal);
+ variables.setValue(pruneId, pruneVal);
+ variables.setValue(keepId, keepVal);
return source;