diff options
-rw-r--r-- | src/mongo/db/pipeline/document_source_list_local_sessions.cpp | 4 | ||||
-rw-r--r-- | src/mongo/db/pipeline/document_source_sort.cpp | 18 | ||||
-rw-r--r-- | src/mongo/db/pipeline/document_source_sort.h | 31 | ||||
-rw-r--r-- | src/mongo/db/pipeline/pipeline_d.cpp | 2 |
4 files changed, 32 insertions, 23 deletions
diff --git a/src/mongo/db/pipeline/document_source_list_local_sessions.cpp b/src/mongo/db/pipeline/document_source_list_local_sessions.cpp index 774a2ddc737..53beab31a77 100644 --- a/src/mongo/db/pipeline/document_source_list_local_sessions.cpp +++ b/src/mongo/db/pipeline/document_source_list_local_sessions.cpp @@ -160,12 +160,12 @@ mongo::ListSessionsSpec mongo::listSessionsParseSpec(StringData stageName, uassert( 31106, str::stream() << "The " << DocumentSourceListLocalSessions::kStageName - << "stage is not allowed in this context :: missing an AuthorizationManager", + << " stage is not allowed in this context :: missing an AuthorizationManager", AuthorizationManager::get(Client::getCurrent()->getServiceContext())); uassert( 31111, str::stream() << "The " << DocumentSourceListLocalSessions::kStageName - << "stage is not allowed in this context :: missing a LogicalSessionCache", + << " stage is not allowed in this context :: missing a LogicalSessionCache", LogicalSessionCache::get(Client::getCurrent()->getOperationContext())); if (!ret.getAllUsers() && (!ret.getUsers() || ret.getUsers()->empty())) { diff --git a/src/mongo/db/pipeline/document_source_sort.cpp b/src/mongo/db/pipeline/document_source_sort.cpp index 256cbf0edf1..3bc7dd75aa3 100644 --- a/src/mongo/db/pipeline/document_source_sort.cpp +++ b/src/mongo/db/pipeline/document_source_sort.cpp @@ -145,12 +145,13 @@ DocumentSource::GetNextResult DocumentSourceSort::getNext() { void DocumentSourceSort::serializeToArray( std::vector<Value>& array, boost::optional<ExplainOptions::Verbosity> explain) const { if (explain) { // always one Value for combined $sort + $limit - array.push_back( - Value(DOC(kStageName << DOC( - "sortKey" << sortKeyPattern(SortKeySerialization::kForExplain) << "limit" - << (_limitSrc ? Value(_limitSrc->getLimit()) : Value()))))); + array.push_back(Value(DOC( + kStageName << DOC( + "sortKey" << serializeSortKeyPattern(SortKeySerialization::kForExplain) << "limit" + << (_limitSrc ? Value(_limitSrc->getLimit()) : Value()))))); } else { // one Value for $sort and maybe a Value for $limit - MutableDocument inner(sortKeyPattern(SortKeySerialization::kForPipelineSerialization)); + MutableDocument inner( + serializeSortKeyPattern(SortKeySerialization::kForPipelineSerialization)); array.push_back(Value(DOC(kStageName << inner.freeze()))); if (_limitSrc) { @@ -167,7 +168,7 @@ long long DocumentSourceSort::getLimit() const { return _limitSrc ? _limitSrc->getLimit() : -1; } -Document DocumentSourceSort::sortKeyPattern(SortKeySerialization serializationMode) const { +Document DocumentSourceSort::serializeSortKeyPattern(SortKeySerialization serializationMode) const { MutableDocument keyObj; const size_t n = _sortPattern.size(); for (size_t i = 0; i < n; ++i) { @@ -313,7 +314,7 @@ intrusive_ptr<DocumentSourceSort> DocumentSourceSort::create( pSort->_sortKeyGen = SortKeyGenerator{ // The SortKeyGenerator expects the expressions to be serialized in order to detect a sort // by a metadata field. - pSort->sortKeyPattern(SortKeySerialization::kForPipelineSerialization).toBson(), + pSort->serializeSortKeyPattern(SortKeySerialization::kForPipelineSerialization).toBson(), pExpCtx->getCollator()}; if (limit > 0) { @@ -533,7 +534,8 @@ int DocumentSourceSort::compare(const Value& lhs, const Value& rhs) const { boost::optional<DocumentSource::MergingLogic> DocumentSourceSort::mergingLogic() { MergingLogic split; split.shardsStage = this; - split.inputSortPattern = sortKeyPattern(SortKeySerialization::kForSortKeyMerging).toBson(); + split.inputSortPattern = + serializeSortKeyPattern(SortKeySerialization::kForSortKeyMerging).toBson(); if (_limitSrc) { split.mergingStage = DocumentSourceLimit::create(pExpCtx, _limitSrc->getLimit()); } diff --git a/src/mongo/db/pipeline/document_source_sort.h b/src/mongo/db/pipeline/document_source_sort.h index 425698957c3..e4d2071184d 100644 --- a/src/mongo/db/pipeline/document_source_sort.h +++ b/src/mongo/db/pipeline/document_source_sort.h @@ -47,6 +47,17 @@ public: kForSortKeyMerging, }; + // Represents one of the components in a compound sort pattern. Each component is either the + // field path by which we are sorting, or an Expression which can be used to retrieve the sort + // value in the case of a $meta-sort (but not both). + struct SortPatternPart { + bool isAscending = true; + boost::optional<FieldPath> fieldPath; + boost::intrusive_ptr<Expression> expression; + }; + + using SortPattern = std::vector<SortPatternPart>; + GetNextResult getNext() final; const char* getSourceName() const final { @@ -84,9 +95,16 @@ public: const std::set<std::string>& nameOfShardKeyFieldsUponEntryToStage) const final; /** + * Returns the sort key pattern. + */ + const SortPattern& getSortKeyPattern() const { + return _sortPattern; + } + + /** * Write out a Document whose contents are the sort key pattern. */ - Document sortKeyPattern(SortKeySerialization) const; + Document serializeSortKeyPattern(SortKeySerialization) const; /** * Parses a $sort stage from the user-supplied BSON. @@ -164,17 +182,6 @@ private: const DocumentSourceSort& _source; }; - // Represents one of the components in a compound sort pattern. Each component is either the - // field path by which we are sorting, or an Expression which can be used to retrieve the sort - // value in the case of a $meta-sort (but not both). - struct SortPatternPart { - bool isAscending = true; - boost::optional<FieldPath> fieldPath; - boost::intrusive_ptr<Expression> expression; - }; - - using SortPattern = std::vector<SortPatternPart>; - explicit DocumentSourceSort(const boost::intrusive_ptr<ExpressionContext>& pExpCtx); Value serialize(boost::optional<ExplainOptions::Verbosity> explain = boost::none) const final { diff --git a/src/mongo/db/pipeline/pipeline_d.cpp b/src/mongo/db/pipeline/pipeline_d.cpp index 6a1e3c54946..37c5edba5f0 100644 --- a/src/mongo/db/pipeline/pipeline_d.cpp +++ b/src/mongo/db/pipeline/pipeline_d.cpp @@ -473,7 +473,7 @@ PipelineD::buildInnerQueryExecutorGeneric(Collection* collection, BSONObj sortObj; if (sortStage) { sortObj = sortStage - ->sortKeyPattern( + ->serializeSortKeyPattern( DocumentSourceSort::SortKeySerialization::kForPipelineSerialization) .toBson(); } |