diff options
Diffstat (limited to 'src/mongo')
-rw-r--r-- | src/mongo/db/pipeline/document_source_redact.h | 10 | ||||
-rw-r--r-- | src/mongo/db/pipeline/document_source_redact_test.cpp | 21 |
2 files changed, 31 insertions, 0 deletions
diff --git a/src/mongo/db/pipeline/document_source_redact.h b/src/mongo/db/pipeline/document_source_redact.h index 10fcfc14f63..b566f2c7adf 100644 --- a/src/mongo/db/pipeline/document_source_redact.h +++ b/src/mongo/db/pipeline/document_source_redact.h @@ -72,6 +72,16 @@ public: return _expression; } + DepsTracker::State getDependencies(DepsTracker* deps) const final { + // Add the dependencies of the expression but all we really care about is variable + // references for correlation analysis. The field references may get populated but we'll + // still require the full document since the $redact may descend arbitrary levels of nested + // documents that is only known at runtime. + _expression->addDependencies(deps); + deps->needWholeDocument = true; + return DepsTracker::State::SEE_NEXT; + } + private: DocumentSourceRedact(const boost::intrusive_ptr<ExpressionContext>& expCtx, const boost::intrusive_ptr<Expression>& previsit); diff --git a/src/mongo/db/pipeline/document_source_redact_test.cpp b/src/mongo/db/pipeline/document_source_redact_test.cpp index 95d001e4dac..6605796138b 100644 --- a/src/mongo/db/pipeline/document_source_redact_test.cpp +++ b/src/mongo/db/pipeline/document_source_redact_test.cpp @@ -81,5 +81,26 @@ TEST_F(DocumentSourceRedactTest, ShouldPropagatePauses) { ASSERT_TRUE(redact->getNext().isEOF()); ASSERT_TRUE(redact->getNext().isEOF()); } + +TEST_F(DocumentSourceRedactTest, ReportsVariableDependencies) { + auto varId = getExpCtx()->variablesParseState.defineVariable("var"); + auto redactSpec = fromjson(R"({ + "$redact" : { + "$cond" : { + "if" : "$$var", + "then" : "$$PRUNE", + "else" : "$$DESCEND" + } + } + })"); + auto redact = DocumentSourceRedact::createFromBson(redactSpec.firstElement(), getExpCtx()); + + DepsTracker deps; + ASSERT_EQ(redact->getDependencies(&deps), DepsTracker::State::SEE_NEXT); + ASSERT_EQ(deps.needWholeDocument, true); + ASSERT_TRUE(deps.fields.empty()); + ASSERT_EQ(deps.vars.count(varId), 1); +} + } // namespace } // namespace mongo |