diff options
author | Svilen Mihaylov <svilen.mihaylov@mongodb.com> | 2022-11-09 15:45:20 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-11-09 16:27:00 +0000 |
commit | 805f480d33180f92e6f6d5fe77bec3d0da10b6df (patch) | |
tree | 24ac8a1cb97eb97efd246a66459b43c105c70b1c /src/mongo/db/pipeline/abt/document_source_visitor.cpp | |
parent | 7981ec64d28c49dd2f41d466f7b6bfaccad66fa9 (diff) | |
download | mongo-805f480d33180f92e6f6d5fe77bec3d0da10b6df.tar.gz |
SERVER-70965 [CQF] Strong alias for ProjectionNames and FieldNames
Diffstat (limited to 'src/mongo/db/pipeline/abt/document_source_visitor.cpp')
-rw-r--r-- | src/mongo/db/pipeline/abt/document_source_visitor.cpp | 65 |
1 files changed, 34 insertions, 31 deletions
diff --git a/src/mongo/db/pipeline/abt/document_source_visitor.cpp b/src/mongo/db/pipeline/abt/document_source_visitor.cpp index fef377ca443..32727852f3f 100644 --- a/src/mongo/db/pipeline/abt/document_source_visitor.cpp +++ b/src/mongo/db/pipeline/abt/document_source_visitor.cpp @@ -132,7 +132,7 @@ public: std::vector<FieldNameType> groupByFieldNames; for (const auto& [fieldName, expr] : idFields) { - groupByFieldNames.push_back(fieldName); + groupByFieldNames.push_back(FieldNameType{fieldName}); } const bool isSingleIdField = groupByFieldNames.size() == 1 && groupByFieldNames.front() == "_id"; @@ -147,7 +147,7 @@ public: groupByProjNames.push_back(groupByProjName); ABT groupByExpr = generateAggExpression( - idFields.at(fieldName).get(), entry._rootProjection, groupByProjName); + idFields.at(fieldName.value()).get(), entry._rootProjection, groupByProjName); _ctx.setNode<EvaluationNode>(entry._rootProjection, groupByProjName, @@ -157,7 +157,7 @@ public: } // Fields corresponding to each accumulator - ProjectionNameVector aggProjFieldNames; + std::vector<FieldNameType> aggProjFieldNames; // Projection names corresponding to each high-level accumulator ($avg can be broken down // into sum and count.). ProjectionNameVector aggOutputProjNames; @@ -177,10 +177,10 @@ public: std::vector<AvgProjNames> avgProjNames; for (const AccumulationStatement& stmt : accumulatedFields) { - const FieldNameType& fieldName = stmt.fieldName; + const FieldNameType fieldName{stmt.fieldName}; aggProjFieldNames.push_back(fieldName); - ProjectionName aggOutputProjName = _ctx.getNextId(fieldName + "_agg"); + ProjectionName aggOutputProjName{_ctx.getNextId(str::stream() << fieldName << "_agg")}; ABT aggInputExpr = generateAggExpression( stmt.expr.argument.get(), entry._rootProjection, aggOutputProjName); @@ -199,9 +199,11 @@ public: aggOutputProjNames.push_back(aggOutputProjName); if (stmt.makeAccumulator()->getOpName() == "$avg"_sd) { // Express $avg as sum / count. - ProjectionName sumProjName = _ctx.getNextId(fieldName + "_sum_agg"); + ProjectionName sumProjName{ + _ctx.getNextId(str::stream() << fieldName << "_sum_agg")}; aggLowLevelOutputProjNames.push_back(sumProjName); - ProjectionName countProjName = _ctx.getNextId(fieldName + "_count_agg"); + ProjectionName countProjName{ + _ctx.getNextId(str::stream() << fieldName << "_count_agg")}; aggLowLevelOutputProjNames.push_back(countProjName); avgProjNames.emplace_back(AvgProjNames{std::move(aggOutputProjName), std::move(sumProjName), @@ -237,14 +239,14 @@ public: ABT integrationPath = make<PathIdentity>(); for (size_t i = 0; i < groupByFieldNames.size(); i++) { - std::string fieldName = std::move(groupByFieldNames.at(i)); + std::string fieldName = groupByFieldNames.at(i).value().toString(); if (!isSingleIdField) { // Erase '_id.' prefix. fieldName = fieldName.substr(strlen("_id.")); } maybeComposePath(integrationPath, - make<PathField>(std::move(fieldName), + make<PathField>(FieldNameType{std::move(fieldName)}, make<PathConstant>(make<Variable>( std::move(groupByProjNames.at(i)))))); } @@ -260,7 +262,7 @@ public: } entry = _ctx.getNode(); - const std::string& mergeProject = _ctx.getNextId("agg_project"); + const ProjectionName mergeProject{_ctx.getNextId("agg_project")}; _ctx.setNode<EvaluationNode>( mergeProject, mergeProject, @@ -331,9 +333,9 @@ public: ABT localPathGet = translateFieldPath( *localPath, make<PathIdentity>(), - [](const std::string& fieldName, const bool isLastElement, ABT input) { + [](FieldNameType fieldName, const bool isLastElement, ABT input) { return make<PathGet>( - fieldName, + std::move(fieldName), isLastElement ? std::move(input) : make<PathTraverse>(std::move(input), PathTraverse::kUnlimited)); }); @@ -360,9 +362,10 @@ public: ABT foreignSimplePath = translateFieldPath( *foreignPath, make<PathCompare>(Operations::EqMember, make<Variable>(localProjName)), - [](const std::string& fieldName, const bool /*isLastElement*/, ABT input) { + [](FieldNameType fieldName, const bool /*isLastElement*/, ABT input) { return make<PathGet>( - fieldName, make<PathTraverse>(std::move(input), PathTraverse::kSingleLevel)); + std::move(fieldName), + make<PathTraverse>(std::move(input), PathTraverse::kSingleLevel)); }); // Retain only the top-level get into foreignSimplePath. @@ -398,11 +401,11 @@ public: ABT resultPath = translateFieldPath( source->getAsField(), make<PathConstant>(make<Variable>(foreignFoldedProjName)), - [](const std::string& fieldName, const bool isLastElement, ABT input) { + [](FieldNameType fieldName, const bool isLastElement, ABT input) { if (!isLastElement) { input = make<PathTraverse>(std::move(input), PathTraverse::kUnlimited); } - return make<PathField>(fieldName, std::move(input)); + return make<PathField>(std::move(fieldName), std::move(input)); }); const ProjectionName& resultProjName = _ctx.getNextId("result"); @@ -579,8 +582,8 @@ public: const FieldPath& unwindFieldPath = source->getUnwindPath(); const bool preserveNullAndEmpty = source->preserveNullAndEmptyArrays(); - const std::string pidProjName = _ctx.getNextId("unwoundPid"); - const std::string unwoundProjName = _ctx.getNextId("unwoundProj"); + const ProjectionName pidProjName{_ctx.getNextId("unwoundPid")}; + const ProjectionName unwoundProjName{_ctx.getNextId("unwoundProj")}; const auto generatePidGteZeroTest = [&pidProjName](ABT thenCond, ABT elseCond) { return make<If>( @@ -591,7 +594,7 @@ public: ABT embedPath = make<Variable>(unwoundProjName); if (preserveNullAndEmpty) { - const std::string unwindLambdaVarName = _ctx.getNextId("unwoundLambdaVarName"); + const ProjectionName unwindLambdaVarName{_ctx.getNextId("unwoundLambdaVarName")}; embedPath = make<PathLambda>(make<LambdaAbstraction>( unwindLambdaVarName, generatePidGteZeroTest(std::move(embedPath), make<Variable>(unwindLambdaVarName)))); @@ -601,19 +604,19 @@ public: embedPath = translateFieldPath( unwindFieldPath, std::move(embedPath), - [](const std::string& fieldName, const bool isLastElement, ABT input) { + [](FieldNameType fieldName, const bool isLastElement, ABT input) { return make<PathField>( - fieldName, + std::move(fieldName), isLastElement ? std::move(input) : make<PathTraverse>(std::move(input), PathTraverse::kUnlimited)); }); - ABT unwoundPath = translateFieldPath( - unwindFieldPath, - make<PathIdentity>(), - [](const std::string& fieldName, const bool isLastElement, ABT input) { - return make<PathGet>(fieldName, std::move(input)); - }); + ABT unwoundPath = + translateFieldPath(unwindFieldPath, + make<PathIdentity>(), + [](FieldNameType fieldName, const bool isLastElement, ABT input) { + return make<PathGet>(std::move(fieldName), std::move(input)); + }); auto entry = _ctx.getNode(); _ctx.setNode<EvaluationNode>( @@ -630,7 +633,7 @@ public: std::move(entry._node)); entry = _ctx.getNode(); - const std::string embedProjName = _ctx.getNextId("embedProj"); + const ProjectionName embedProjName{_ctx.getNextId("embedProj")}; _ctx.setNode<EvaluationNode>( embedProjName, embedProjName, @@ -644,12 +647,12 @@ public: indexFieldPath, make<PathConstant>( generatePidGteZeroTest(make<Variable>(pidProjName), Constant::null())), - [](const std::string& fieldName, const bool isLastElement, ABT input) { - return make<PathField>(fieldName, std::move(input)); + [](FieldNameType fieldName, const bool /*isLastElement*/, ABT input) { + return make<PathField>(std::move(fieldName), std::move(input)); }); entry = _ctx.getNode(); - const std::string embedPidProjName = _ctx.getNextId("embedPidProj"); + const ProjectionName embedPidProjName{_ctx.getNextId("embedPidProj")}; _ctx.setNode<EvaluationNode>( embedPidProjName, embedPidProjName, |