summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDianna Hohensee <dianna.hohensee@10gen.com>2016-05-18 09:36:43 -0400
committerDianna Hohensee <dianna.hohensee@10gen.com>2016-05-18 09:36:43 -0400
commit1290f33574da2e129bd3f5471dd06f2e761c74ee (patch)
treec19c78b55d5bbed58ecdba4823961ac9a5a62848
parent086c70118d9e98f67beac16b87db93888f6be452 (diff)
downloadmongo-1290f33574da2e129bd3f5471dd06f2e761c74ee.tar.gz
Revert "SERVER-23833 DocumentSourceLookup::getOutputSorts correctly truncates input sort set."
This reverts commit 44abb8db32a6fad705854793e397961dfc72d09e. Unit tests QueuedDataStageTest and SortStageTest are failing.
-rw-r--r--src/mongo/db/pipeline/document_source.h5
-rw-r--r--src/mongo/db/pipeline/document_source_lookup.cpp26
-rw-r--r--src/mongo/db/pipeline/document_source_test.cpp32
3 files changed, 31 insertions, 32 deletions
diff --git a/src/mongo/db/pipeline/document_source.h b/src/mongo/db/pipeline/document_source.h
index a2a534e7aca..99197592d23 100644
--- a/src/mongo/db/pipeline/document_source.h
+++ b/src/mongo/db/pipeline/document_source.h
@@ -1485,10 +1485,7 @@ public:
Pipeline::SourceContainer* container) final;
GetDepsReturn getDependencies(DepsTracker* deps) const final;
void dispose() final;
-
- BSONObjSet getOutputSorts() final {
- return DocumentSource::truncateSortSet(pSource->getOutputSorts(), {_as.getPath(false)});
- }
+ BSONObjSet getOutputSorts() final;
bool needsPrimaryShard() const final {
return true;
diff --git a/src/mongo/db/pipeline/document_source_lookup.cpp b/src/mongo/db/pipeline/document_source_lookup.cpp
index c4e6b72947a..a3e7f29ec77 100644
--- a/src/mongo/db/pipeline/document_source_lookup.cpp
+++ b/src/mongo/db/pipeline/document_source_lookup.cpp
@@ -326,6 +326,32 @@ BSONObj DocumentSourceLookUp::queryForInput(const Document& input,
return query.obj();
}
+BSONObjSet DocumentSourceLookUp::getOutputSorts() {
+ BSONObjSet out;
+
+ BSONObjSet inputSort = pSource->getOutputSorts();
+ std::string asPath = _as.getPath(false);
+
+ for (auto&& sortObj : inputSort) {
+ // Truncate each sortObj at the '_as' path.
+ BSONObjBuilder outputSort;
+
+ for (BSONElement fieldSort : sortObj) {
+ if (fieldSort.fieldNameStringData() == asPath) {
+ break;
+ }
+ outputSort.append(fieldSort);
+ }
+
+ BSONObj outSortObj = outputSort.obj();
+ if (!outSortObj.isEmpty()) {
+ out.insert(outSortObj);
+ }
+ }
+
+ return out;
+}
+
boost::optional<Document> DocumentSourceLookUp::unwindResult() {
const boost::optional<FieldPath> indexPath(_unwindSrc->indexPath());
diff --git a/src/mongo/db/pipeline/document_source_test.cpp b/src/mongo/db/pipeline/document_source_test.cpp
index b8f96fd1f60..c7fcdab4675 100644
--- a/src/mongo/db/pipeline/document_source_test.cpp
+++ b/src/mongo/db/pipeline/document_source_test.cpp
@@ -3352,11 +3352,11 @@ TEST(ObjectForMatch, ShouldExtractEntireArrayFromPrefixOfDottedField) {
namespace DocumentSourceLookUp {
using mongo::DocumentSourceLookUp;
-class OutputSortTruncatesOnEquality : public Mock::Base {
+class OutputSort : public Mock::Base {
public:
void run() {
intrusive_ptr<DocumentSourceMock> source = DocumentSourceMock::create();
- source->sorts = {BSON("a" << 1 << "d.e" << 1 << "c" << 1)};
+ source->sorts = {BSON("a" << 1 << "d.e" << 1)};
intrusive_ptr<DocumentSource> lookup =
DocumentSourceLookUp::createFromBson(BSON("$lookup" << BSON("from"
<< "a"
@@ -3372,30 +3372,7 @@ public:
BSONObjSet outputSort = lookup->getOutputSorts();
ASSERT_EQUALS(outputSort.count(BSON("a" << 1)), 1U);
- ASSERT_EQUALS(outputSort.size(), 1U);
- }
-};
-
-class OutputSortTruncatesOnPrefix : public Mock::Base {
-public:
- void run() {
- intrusive_ptr<DocumentSourceMock> source = DocumentSourceMock::create();
- source->sorts = {BSON("a" << 1 << "d.e" << 1 << "c" << 1)};
- intrusive_ptr<DocumentSource> lookup =
- DocumentSourceLookUp::createFromBson(BSON("$lookup" << BSON("from"
- << "a"
- << "localField"
- << "b"
- << "foreignField"
- << "c"
- << "as"
- << "d")).firstElement(),
- ctx());
- lookup->setSource(source.get());
-
- BSONObjSet outputSort = lookup->getOutputSorts();
-
- ASSERT_EQUALS(outputSort.count(BSON("a" << 1)), 1U);
+ ASSERT_EQUALS(outputSort.count(BSON("d.e" << 1)), 0U);
ASSERT_EQUALS(outputSort.size(), 1U);
}
};
@@ -3519,8 +3496,7 @@ public:
add<DocumentSourceGeoNear::LimitCoalesce>();
add<DocumentSourceGeoNear::OutputSort>();
- add<DocumentSourceLookUp::OutputSortTruncatesOnEquality>();
- add<DocumentSourceLookUp::OutputSortTruncatesOnPrefix>();
+ add<DocumentSourceLookUp::OutputSort>();
add<DocumentSourceMatch::RedactSafePortion>();
add<DocumentSourceMatch::Coalesce>();