diff options
author | Maddie Zechar <mez2113@columbia.edu> | 2022-02-25 23:01:00 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-02-25 23:58:50 +0000 |
commit | 3703e0ec90ebed2d332720b20dafa6a5bcb72a23 (patch) | |
tree | e2ff2aad6e20935579d11b3c89f571f5622a5dce /src/mongo/db/pipeline/document_source_set_variable_from_subpipeline.h | |
parent | ea9494f858b47088343198fe9a888d2d1dea1823 (diff) | |
download | mongo-3703e0ec90ebed2d332720b20dafa6a5bcb72a23.tar.gz |
SERVER-62529: Add DocumentSourceSetVariableFromSubPipeline
Diffstat (limited to 'src/mongo/db/pipeline/document_source_set_variable_from_subpipeline.h')
-rw-r--r-- | src/mongo/db/pipeline/document_source_set_variable_from_subpipeline.h | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/src/mongo/db/pipeline/document_source_set_variable_from_subpipeline.h b/src/mongo/db/pipeline/document_source_set_variable_from_subpipeline.h new file mode 100644 index 00000000000..3dd6df56bc4 --- /dev/null +++ b/src/mongo/db/pipeline/document_source_set_variable_from_subpipeline.h @@ -0,0 +1,100 @@ +/** + * Copyright (C) 2022-present MongoDB, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the Server Side Public License, version 1, + * as published by MongoDB, Inc. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Server Side Public License for more details. + * + * You should have received a copy of the Server Side Public License + * along with this program. If not, see + * <http://www.mongodb.com/licensing/server-side-public-license>. + * + * As a special exception, the copyright holders give permission to link the + * code of portions of this program with the OpenSSL library under certain + * conditions as described in each individual source file and distribute + * linked combinations including the program with the OpenSSL library. You + * must comply with the Server Side Public License in all respects for + * all of the code used other than as permitted herein. If you modify file(s) + * with this exception, you may extend this exception to your version of the + * file(s), but you are not obligated to do so. If you do not wish to do so, + * delete this exception statement from your version. If you delete this + * exception statement from all source files in the program, then also delete + * it in the license file. + */ + +#pragma once + +#include "mongo/db/pipeline/document_source.h" + +namespace mongo { + + +class DocumentSourceSetVariableFromSubPipeline final : public DocumentSource { +public: + static constexpr StringData kStageName = "$setVariableFromSubPipeline"_sd; + + static boost::intrusive_ptr<DocumentSource> createFromBson( + BSONElement elem, const boost::intrusive_ptr<ExpressionContext>& expCtx); + + static boost::intrusive_ptr<DocumentSourceSetVariableFromSubPipeline> create( + const boost::intrusive_ptr<ExpressionContext>& expCtx, + std::unique_ptr<Pipeline, PipelineDeleter> subpipeline, + Variables::Id varID); + + ~DocumentSourceSetVariableFromSubPipeline() = default; + + boost::optional<DistributedPlanLogic> distributedPlanLogic() final { + // {shardsStage, mergingStage, sortPattern} + return DistributedPlanLogic{nullptr, this, boost::none}; + } + const char* getSourceName() const final { + return kStageName.rawData(); + } + StageConstraints constraints(Pipeline::SplitState) const final { + StageConstraints setVariableConstraints(StreamType::kStreaming, + PositionRequirement::kNone, + HostTypeRequirement::kAnyShard, + DiskUseRequirement::kNoDiskUse, + FacetRequirement::kNotAllowed, + TransactionRequirement::kNotAllowed, + LookupRequirement::kAllowed, + UnionRequirement::kAllowed); + + // The constraints of the sub-pipeline determine the constraints of the + // $setVariableFromSubPipeline. We want to forward the strictest requirements of the stages + // in the sub-pipeline. + setVariableConstraints = StageConstraints::getStrictestConstraints( + _subPipeline->getSources(), setVariableConstraints); + return setVariableConstraints; + } + + DepsTracker::State getDependencies(DepsTracker* deps) const final; + +protected: + /** + * Attempts to swap with a subsequent sharding only stage. + */ + Pipeline::SourceContainer::iterator doOptimizeAt(Pipeline::SourceContainer::iterator itr, + Pipeline::SourceContainer* container) final; + DocumentSourceSetVariableFromSubPipeline(const boost::intrusive_ptr<ExpressionContext>& expCtx, + std::unique_ptr<Pipeline, PipelineDeleter> subpipeline, + Variables::Id varID) + : DocumentSource(kStageName, expCtx), + _subPipeline(std::move(subpipeline)), + _variableID(varID) {} + +private: + GetNextResult doGetNext() final; + Value serialize(boost::optional<ExplainOptions::Verbosity> explain = boost::none) const final; + std::unique_ptr<Pipeline, PipelineDeleter> _subPipeline; + Variables::Id _variableID; + // $setVariableFromSubPipeline sets the value of $$SEARCH_META only on the first call to + // doGetNext(). + bool _firstCallForInput = true; +}; +} // namespace mongo |