summaryrefslogtreecommitdiff
path: root/src/mongo/db/pipeline/expression.h
diff options
context:
space:
mode:
authorHana Pearlman <hana.pearlman@mongodb.com>2021-02-17 22:03:19 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-02-25 21:19:32 +0000
commitd2be4480c93b6cffa675c71ed2ddac97f2a22608 (patch)
tree6db019dd31186444beb9774b8af9aea71216b691 /src/mongo/db/pipeline/expression.h
parentec3a6420909baa5a48cdbc847f7f4e8178c03649 (diff)
downloadmongo-d2be4480c93b6cffa675c71ed2ddac97f2a22608.tar.gz
SERVER-54589: Extend MatchExpression renaming to support $match with $expr
Diffstat (limited to 'src/mongo/db/pipeline/expression.h')
-rw-r--r--src/mongo/db/pipeline/expression.h22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/mongo/db/pipeline/expression.h b/src/mongo/db/pipeline/expression.h
index ff9680769d4..b8e6b3261bb 100644
--- a/src/mongo/db/pipeline/expression.h
+++ b/src/mongo/db/pipeline/expression.h
@@ -1541,6 +1541,15 @@ public:
ComputedPaths getComputedPaths(const std::string& exprFieldPath,
Variables::Id renamingVar) const final;
+ /**
+ * Finds an applicable rename from 'renameList' and creates a copy of ExpressionFieldPath in
+ * which the the rename is substituted. If there is no applicable rename, returns nullptr. Each
+ * pair in 'renameList' specifies a path prefix that should be renamed (as the first element)
+ * and the path components that should replace the renamed prefix (as the second element).
+ */
+ std::unique_ptr<Expression> copyWithSubstitution(
+ const StringMap<std::string>& renameList) const;
+
void acceptVisitor(ExpressionVisitor* visitor) final {
return visitor->visit(this);
}
@@ -3318,4 +3327,17 @@ private:
const TimeZone& timezone) const override;
};
+struct SubstituteFieldPathWalker {
+ SubstituteFieldPathWalker(const StringMap<std::string>& renameList) : renameList(renameList) {}
+
+ auto postVisit(Expression* exp) {
+ if (auto fieldPathExpr = dynamic_cast<ExpressionFieldPath*>(exp)) {
+ return fieldPathExpr->copyWithSubstitution(renameList);
+ }
+ return std::unique_ptr<Expression>{};
+ }
+
+ const StringMap<std::string>& renameList;
+};
+
} // namespace mongo