diff options
author | Nicholas Zolnierz <nicholas.zolnierz@mongodb.com> | 2022-07-25 13:04:05 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-07-25 19:34:13 +0000 |
commit | 56666ada8172906b106bbbf6ba9ace1b73e50e05 (patch) | |
tree | eac4d66019a8d8dfd808c86c7714e98ee3f4cd05 /src/mongo | |
parent | c75c69d234268c9b0758bc8ebb1057a73d1f64d4 (diff) | |
download | mongo-56666ada8172906b106bbbf6ba9ace1b73e50e05.tar.gz |
SERVER-66548 Add support for dependency tracking to $redact
(cherry picked from commit cc4968771221658d66ff42ed2fb861656c5683ca)
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 |