From 8e5680998271781fe04d9f3c87ca5e09fd2dae86 Mon Sep 17 00:00:00 2001 From: Ridhwaan Anayetullah Date: Mon, 14 Jun 2021 12:38:47 +0000 Subject: SERVER-57332 Create skeleton InternalDocumentSourceDensify --- src/mongo/db/pipeline/document_source_densify.cpp | 4 ++ src/mongo/db/pipeline/document_source_densify.h | 45 ++++++++++++++++++++++- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/src/mongo/db/pipeline/document_source_densify.cpp b/src/mongo/db/pipeline/document_source_densify.cpp index 7f537a6a9b6..c7d8b122c31 100644 --- a/src/mongo/db/pipeline/document_source_densify.cpp +++ b/src/mongo/db/pipeline/document_source_densify.cpp @@ -141,4 +141,8 @@ bool DocumentSourceInternalDensify::DocGenerator::done() const { return _state == GeneratorState::kDone; } +DocumentSource::GetNextResult DocumentSourceInternalDensify::doGetNext() { + return pSource->getNext(); +} + } // namespace mongo diff --git a/src/mongo/db/pipeline/document_source_densify.h b/src/mongo/db/pipeline/document_source_densify.h index b25c482f9fe..ffc921d4714 100644 --- a/src/mongo/db/pipeline/document_source_densify.h +++ b/src/mongo/db/pipeline/document_source_densify.h @@ -31,6 +31,7 @@ #include "mongo/db/exec/document_value/document.h" #include "mongo/db/exec/document_value/value.h" +#include "mongo/db/pipeline/document_source.h" #include "mongo/db/pipeline/field_path.h" #include "mongo/db/query/datetime/date_time_support.h" #include "mongo/util/time_support.h" @@ -42,14 +43,17 @@ namespace document_source_densify { } // TODO SERVER-57332 This should inherit from DocumentSource. -class DocumentSourceInternalDensify { +class DocumentSourceInternalDensify final : public DocumentSource { public: + static constexpr StringData kStageName = "$_internalDensify"_sd; + using DensifyValueType = stdx::variant; struct StepSpec { double step; boost::optional unit; boost::optional tz; }; + class DocGenerator { public: DocGenerator(DensifyValueType min, @@ -85,5 +89,42 @@ public: GeneratorState _state = GeneratorState::kGeneratingDocuments; }; + + static boost::intrusive_ptr create(const boost::intrusive_ptr& pExpCtx); + + static boost::intrusive_ptr createFromBson( + BSONElement elem, const boost::intrusive_ptr& pExpCtx); + + StageConstraints constraints(Pipeline::SplitState pipeState) const final { + return {StreamType::kStreaming, + PositionRequirement::kNone, + HostTypeRequirement::kNone, + DiskUseRequirement::kNoDiskUse, + FacetRequirement::kAllowed, + TransactionRequirement::kAllowed, + LookupRequirement::kAllowed, + UnionRequirement::kAllowed}; + } + + const char* getSourceName() const final { + return kStageName.rawData(); + } + Pipeline::SourceContainer::iterator doOptimizeAt(Pipeline::SourceContainer::iterator itr, + Pipeline::SourceContainer* container) final; + Value serialize(boost::optional explain = boost::none) const final; + + DepsTracker::State getDependencies(DepsTracker* deps) const final { + return DepsTracker::State::SEE_NEXT; // This doesn't affect needed fields + } + + boost::optional distributedPlanLogic() final { + // Running this stage on the shards is an optimization, but is not strictly necessary in + // order to produce correct pipeline output. + // {shardsStage, mergingStage, sortPattern} + return DistributedPlanLogic{nullptr, this, boost::none}; + } + + DocumentSourceInternalDensify(const boost::intrusive_ptr& pExpCtx); + GetNextResult doGetNext() final; }; -} // namespace mongo +}; -- cgit v1.2.1