diff options
Diffstat (limited to 'src/mongo/db/pipeline')
27 files changed, 436 insertions, 294 deletions
diff --git a/src/mongo/db/pipeline/accumulator.cpp b/src/mongo/db/pipeline/accumulator.cpp index f5b21798f5a..b2fc55a455e 100644 --- a/src/mongo/db/pipeline/accumulator.cpp +++ b/src/mongo/db/pipeline/accumulator.cpp @@ -32,8 +32,8 @@ #include "mongo/db/pipeline/accumulator.h" #include "mongo/db/pipeline/value.h" -#include "mongo/util/string_map.h" #include "mongo/util/mongoutils/str.h" +#include "mongo/util/string_map.h" namespace mongo { diff --git a/src/mongo/db/pipeline/accumulator.h b/src/mongo/db/pipeline/accumulator.h index afcce43669e..7dd604b82b4 100644 --- a/src/mongo/db/pipeline/accumulator.h +++ b/src/mongo/db/pipeline/accumulator.h @@ -56,7 +56,7 @@ namespace mongo { class Accumulator : public RefCountable { public: - using Factory = boost::intrusive_ptr<Accumulator>(*)(); + using Factory = boost::intrusive_ptr<Accumulator> (*)(); Accumulator() = default; diff --git a/src/mongo/db/pipeline/document_internal.h b/src/mongo/db/pipeline/document_internal.h index 78f4dac02da..3ad0d1ee577 100644 --- a/src/mongo/db/pipeline/document_internal.h +++ b/src/mongo/db/pipeline/document_internal.h @@ -30,11 +30,11 @@ #include <third_party/murmurhash3/MurmurHash3.h> -#include <boost/intrusive_ptr.hpp> #include <bitset> +#include <boost/intrusive_ptr.hpp> -#include "mongo/util/intrusive_counter.h" #include "mongo/db/pipeline/value.h" +#include "mongo/util/intrusive_counter.h" namespace mongo { /** Helper class to make the position in a document abstract diff --git a/src/mongo/db/pipeline/document_source.h b/src/mongo/db/pipeline/document_source.h index a2a534e7aca..6fc931c09f4 100644 --- a/src/mongo/db/pipeline/document_source.h +++ b/src/mongo/db/pipeline/document_source.h @@ -44,11 +44,11 @@ #include "mongo/db/jsobj.h" #include "mongo/db/matcher/matcher.h" #include "mongo/db/pipeline/accumulator.h" -#include "mongo/db/pipeline/lookup_set_cache.h" #include "mongo/db/pipeline/dependencies.h" #include "mongo/db/pipeline/document.h" #include "mongo/db/pipeline/expression.h" #include "mongo/db/pipeline/expression_context.h" +#include "mongo/db/pipeline/lookup_set_cache.h" #include "mongo/db/pipeline/pipeline.h" #include "mongo/db/pipeline/value.h" #include "mongo/db/sorter/sorter.h" diff --git a/src/mongo/db/pipeline/document_source_cursor.cpp b/src/mongo/db/pipeline/document_source_cursor.cpp index 183ea58fda7..68cf11ba20e 100644 --- a/src/mongo/db/pipeline/document_source_cursor.cpp +++ b/src/mongo/db/pipeline/document_source_cursor.cpp @@ -125,10 +125,10 @@ void DocumentSourceCursor::loadBatch() { << WorkingSetCommon::toStatusString(obj), state != PlanExecutor::DEAD); - uassert( - 17285, - str::stream() << "cursor encountered an error: " << WorkingSetCommon::toStatusString(obj), - state != PlanExecutor::FAILURE); + uassert(17285, + str::stream() << "cursor encountered an error: " + << WorkingSetCommon::toStatusString(obj), + state != PlanExecutor::FAILURE); massert(17286, str::stream() << "Unexpected return from PlanExecutor::getNext: " << state, diff --git a/src/mongo/db/pipeline/document_source_geo_near.cpp b/src/mongo/db/pipeline/document_source_geo_near.cpp index da30c2adaa3..35133d6a400 100644 --- a/src/mongo/db/pipeline/document_source_geo_near.cpp +++ b/src/mongo/db/pipeline/document_source_geo_near.cpp @@ -30,8 +30,8 @@ #include "mongo/platform/basic.h" -#include "mongo/db/pipeline/document_source.h" #include "mongo/db/pipeline/document.h" +#include "mongo/db/pipeline/document_source.h" #include "mongo/util/log.h" namespace mongo { diff --git a/src/mongo/db/pipeline/document_source_graph_lookup.cpp b/src/mongo/db/pipeline/document_source_graph_lookup.cpp index f2821b9107c..3c5fccf47bd 100644 --- a/src/mongo/db/pipeline/document_source_graph_lookup.cpp +++ b/src/mongo/db/pipeline/document_source_graph_lookup.cpp @@ -358,9 +358,12 @@ void DocumentSourceGraphLookUp::checkMemoryUsage() { void DocumentSourceGraphLookUp::serializeToArray(std::vector<Value>& array, bool explain) const { // Serialize default options. MutableDocument spec(DOC("from" << _from.coll() << "as" << _as.getPath(false) - << "connectToField" << _connectToField.getPath(false) - << "connectFromField" << _connectFromField.getPath(false) - << "startWith" << _startWith->serialize(false))); + << "connectToField" + << _connectToField.getPath(false) + << "connectFromField" + << _connectFromField.getPath(false) + << "startWith" + << _startWith->serialize(false))); // depthField is optional; serialize it if it was specified. if (_depthField) { @@ -376,7 +379,8 @@ void DocumentSourceGraphLookUp::serializeToArray(std::vector<Value>& array, bool const boost::optional<FieldPath> indexPath = (*_unwind)->indexPath(); spec["unwinding"] = Value(DOC("preserveNullAndEmptyArrays" - << (*_unwind)->preserveNullAndEmptyArrays() << "includeArrayIndex" + << (*_unwind)->preserveNullAndEmptyArrays() + << "includeArrayIndex" << (indexPath ? Value((*indexPath).getPath(false)) : Value()))); } @@ -432,14 +436,14 @@ intrusive_ptr<DocumentSource> DocumentSourceGraphLookUp::createFromBson( << typeName(argument.type()), argument.isNumber()); maxDepth = argument.safeNumberLong(); - uassert( - 40101, - str::stream() << "maxDepth requires a nonnegative argument, found: " << *maxDepth, - *maxDepth >= 0); - uassert( - 40102, - str::stream() << "maxDepth could not be represented as a long long: " << *maxDepth, - *maxDepth == argument.number()); + uassert(40101, + str::stream() << "maxDepth requires a nonnegative argument, found: " + << *maxDepth, + *maxDepth >= 0); + uassert(40102, + str::stream() << "maxDepth could not be represented as a long long: " + << *maxDepth, + *maxDepth == argument.number()); continue; } @@ -447,8 +451,8 @@ intrusive_ptr<DocumentSource> DocumentSourceGraphLookUp::createFromBson( argName == "depthField" || argName == "connectToField") { // All remaining arguments to $graphLookup are expected to be strings. uassert(40103, - str::stream() << "expected string as argument for " << argName - << ", found: " << argument.toString(false, false), + str::stream() << "expected string as argument for " << argName << ", found: " + << argument.toString(false, false), argument.type() == String); } @@ -464,8 +468,8 @@ intrusive_ptr<DocumentSource> DocumentSourceGraphLookUp::createFromBson( depthField = boost::optional<FieldPath>(FieldPath(argument.String())); } else { uasserted(40104, - str::stream() - << "Unknown argument to $graphLookup: " << argument.fieldName()); + str::stream() << "Unknown argument to $graphLookup: " + << argument.fieldName()); } } diff --git a/src/mongo/db/pipeline/document_source_lookup.cpp b/src/mongo/db/pipeline/document_source_lookup.cpp index c4e6b72947a..277ea77d0fc 100644 --- a/src/mongo/db/pipeline/document_source_lookup.cpp +++ b/src/mongo/db/pipeline/document_source_lookup.cpp @@ -93,9 +93,9 @@ boost::optional<Document> DocumentSourceLookUp::getNext() { if (!_additionalFilter && _matchSrc) { // We have internalized a $match, but have not yet computed the descended $match that should // be applied to our queries. - _additionalFilter = DocumentSourceMatch::descendMatchOnPath(_matchSrc->getMatchExpression(), - _as.getPath(false), - pExpCtx)->getQuery(); + _additionalFilter = DocumentSourceMatch::descendMatchOnPath( + _matchSrc->getMatchExpression(), _as.getPath(false), pExpCtx) + ->getQuery(); } if (_handlingUnwind) { @@ -120,7 +120,8 @@ boost::optional<Document> DocumentSourceLookUp::getNext() { objsize += result.objsize(); uassert(4568, str::stream() << "Total size of documents in " << _fromNs.coll() << " matching " - << query << " exceeds maximum document size", + << query + << " exceeds maximum document size", objsize <= BSONObjMaxInternalSize); results.push_back(Value(result)); } @@ -224,23 +225,23 @@ Pipeline::SourceContainer::iterator DocumentSourceLookUp::optimizeAt( } bool isMatchOnlyOnAs = true; - auto computeWhetherMatchOnAs = - [&isMatchOnlyOnAs, &outputPath](MatchExpression* expression, std::string path) -> void { - // If 'expression' is the child of a $elemMatch, we cannot internalize the $match. For - // example, {b: {$elemMatch: {$gt: 1, $lt: 4}}}, where "b" is our "_as" field. This is - // because there's no way to modify the expression to be a match just on 'b'--we cannot - // change the path to an empty string, or remove the node entirely. - if (expression->matchType() == MatchExpression::ELEM_MATCH_VALUE || - expression->matchType() == MatchExpression::ELEM_MATCH_OBJECT) { - isMatchOnlyOnAs = false; - } - if (expression->numChildren() == 0) { - // 'expression' is a leaf node; examine the path. It is important that 'outputPath' - // not equal 'path', because we cannot change the expression {b: {$eq: 3}}, where - // 'path' is 'b', to be a match on a subfield, since no subfield exists. - isMatchOnlyOnAs = isMatchOnlyOnAs && expression::isPathPrefixOf(outputPath, path); - } - }; + auto computeWhetherMatchOnAs = [&isMatchOnlyOnAs, &outputPath](MatchExpression* expression, + std::string path) -> void { + // If 'expression' is the child of a $elemMatch, we cannot internalize the $match. For + // example, {b: {$elemMatch: {$gt: 1, $lt: 4}}}, where "b" is our "_as" field. This is + // because there's no way to modify the expression to be a match just on 'b'--we cannot + // change the path to an empty string, or remove the node entirely. + if (expression->matchType() == MatchExpression::ELEM_MATCH_VALUE || + expression->matchType() == MatchExpression::ELEM_MATCH_OBJECT) { + isMatchOnlyOnAs = false; + } + if (expression->numChildren() == 0) { + // 'expression' is a leaf node; examine the path. It is important that 'outputPath' + // not equal 'path', because we cannot change the expression {b: {$eq: 3}}, where + // 'path' is 'b', to be a match on a subfield, since no subfield exists. + isMatchOnlyOnAs = isMatchOnlyOnAs && expression::isPathPrefixOf(outputPath, path); + } + }; expression::mapOver(dependent->getMatchExpression(), computeWhetherMatchOnAs); @@ -375,23 +376,27 @@ boost::optional<Document> DocumentSourceLookUp::unwindResult() { void DocumentSourceLookUp::serializeToArray(std::vector<Value>& array, bool explain) const { MutableDocument output( DOC(getSourceName() << DOC("from" << _fromNs.coll() << "as" << _as.getPath(false) - << "localField" << _localField.getPath(false) - << "foreignField" << _foreignField.getPath(false)))); + << "localField" + << _localField.getPath(false) + << "foreignField" + << _foreignField.getPath(false)))); if (explain) { if (_handlingUnwind) { const boost::optional<FieldPath> indexPath = _unwindSrc->indexPath(); output[getSourceName()]["unwinding"] = Value(DOC("preserveNullAndEmptyArrays" - << _unwindSrc->preserveNullAndEmptyArrays() << "includeArrayIndex" + << _unwindSrc->preserveNullAndEmptyArrays() + << "includeArrayIndex" << (indexPath ? Value(indexPath->getPath(false)) : Value()))); } if (_matchSrc) { // Our output does not have to be parseable, so include a "matching" field with the // descended match expression. - output[getSourceName()]["matching"] = Value( - DocumentSourceMatch::descendMatchOnPath( - _matchSrc->getMatchExpression(), _as.getPath(false), pExpCtx)->getQuery()); + output[getSourceName()]["matching"] = + Value(DocumentSourceMatch::descendMatchOnPath( + _matchSrc->getMatchExpression(), _as.getPath(false), pExpCtx) + ->getQuery()); } array.push_back(Value(output.freeze())); diff --git a/src/mongo/db/pipeline/document_source_match.cpp b/src/mongo/db/pipeline/document_source_match.cpp index 21f7dab580c..b754caa3af9 100644 --- a/src/mongo/db/pipeline/document_source_match.cpp +++ b/src/mongo/db/pipeline/document_source_match.cpp @@ -404,31 +404,29 @@ boost::intrusive_ptr<DocumentSourceMatch> DocumentSourceMatch::descendMatchOnPat MatchExpression* matchExpr, const std::string& descendOn, intrusive_ptr<ExpressionContext> expCtx) { - expression::mapOver(matchExpr, - [&descendOn](MatchExpression* node, std::string path) -> void { - // Cannot call this method on a $match including a $elemMatch. - invariant(node->matchType() != MatchExpression::ELEM_MATCH_OBJECT && - node->matchType() != MatchExpression::ELEM_MATCH_VALUE); - // Logical nodes do not have a path, but both 'leaf' and 'array' nodes - // do. - if (node->isLogical()) { - return; - } - - auto leafPath = node->path(); - invariant(expression::isPathPrefixOf(descendOn, leafPath)); - - auto newPath = leafPath.substr(descendOn.size() + 1); - if (node->isLeaf() && - node->matchType() != MatchExpression::TYPE_OPERATOR && - node->matchType() != MatchExpression::WHERE) { - auto leafNode = static_cast<LeafMatchExpression*>(node); - leafNode->setPath(newPath); - } else if (node->isArray()) { - auto arrayNode = static_cast<ArrayMatchingMatchExpression*>(node); - arrayNode->setPath(newPath); - } - }); + expression::mapOver(matchExpr, [&descendOn](MatchExpression* node, std::string path) -> void { + // Cannot call this method on a $match including a $elemMatch. + invariant(node->matchType() != MatchExpression::ELEM_MATCH_OBJECT && + node->matchType() != MatchExpression::ELEM_MATCH_VALUE); + // Logical nodes do not have a path, but both 'leaf' and 'array' nodes + // do. + if (node->isLogical()) { + return; + } + + auto leafPath = node->path(); + invariant(expression::isPathPrefixOf(descendOn, leafPath)); + + auto newPath = leafPath.substr(descendOn.size() + 1); + if (node->isLeaf() && node->matchType() != MatchExpression::TYPE_OPERATOR && + node->matchType() != MatchExpression::WHERE) { + auto leafNode = static_cast<LeafMatchExpression*>(node); + leafNode->setPath(newPath); + } else if (node->isArray()) { + auto arrayNode = static_cast<ArrayMatchingMatchExpression*>(node); + arrayNode->setPath(newPath); + } + }); BSONObjBuilder query; matchExpr->serialize(&query); @@ -479,15 +477,13 @@ DocumentSource::GetDepsReturn DocumentSourceMatch::getDependencies(DepsTracker* } void DocumentSourceMatch::addDependencies(DepsTracker* deps) const { - expression::mapOver(_expression.get(), - [deps](MatchExpression* node, std::string path) -> void { - if (!path.empty() && - (node->numChildren() == 0 || - node->matchType() == MatchExpression::ELEM_MATCH_VALUE || - node->matchType() == MatchExpression::ELEM_MATCH_OBJECT)) { - deps->fields.insert(path); - } - }); + expression::mapOver(_expression.get(), [deps](MatchExpression* node, std::string path) -> void { + if (!path.empty() && + (node->numChildren() == 0 || node->matchType() == MatchExpression::ELEM_MATCH_VALUE || + node->matchType() == MatchExpression::ELEM_MATCH_OBJECT)) { + deps->fields.insert(path); + } + }); } DocumentSourceMatch::DocumentSourceMatch(const BSONObj& query, diff --git a/src/mongo/db/pipeline/document_source_merge_cursors.cpp b/src/mongo/db/pipeline/document_source_merge_cursors.cpp index 6056a2f7646..01f11cb0c9f 100644 --- a/src/mongo/db/pipeline/document_source_merge_cursors.cpp +++ b/src/mongo/db/pipeline/document_source_merge_cursors.cpp @@ -84,9 +84,11 @@ intrusive_ptr<DocumentSource> DocumentSourceMergeCursors::createFromBson( Value DocumentSourceMergeCursors::serialize(bool explain) const { vector<Value> cursors; for (size_t i = 0; i < _cursorDescriptors.size(); i++) { - cursors.push_back(Value( - DOC("host" << Value(_cursorDescriptors[i].connectionString.toString()) << "ns" - << _cursorDescriptors[i].ns << "id" << _cursorDescriptors[i].cursorId))); + cursors.push_back( + Value(DOC("host" << Value(_cursorDescriptors[i].connectionString.toString()) << "ns" + << _cursorDescriptors[i].ns + << "id" + << _cursorDescriptors[i].cursorId))); } return Value(DOC(getSourceName() << Value(cursors))); } @@ -137,7 +139,8 @@ Document DocumentSourceMergeCursors::nextSafeFrom(DBClientCursor* cursor) { const int code = next.hasField("code") ? next["code"].numberInt() : 17029; uasserted(code, str::stream() << "Received error in response from " << cursor->originalHost() - << ": " << next); + << ": " + << next); } return Document::fromBsonWithMetaData(next); } diff --git a/src/mongo/db/pipeline/document_source_out.cpp b/src/mongo/db/pipeline/document_source_out.cpp index 148f7f4fc7e..252d894ba04 100644 --- a/src/mongo/db/pipeline/document_source_out.cpp +++ b/src/mongo/db/pipeline/document_source_out.cpp @@ -87,7 +87,8 @@ void DocumentSourceOut::prepTempCollection() { bool ok = conn->runCommand(_outputNs.db().toString(), cmd.done(), info); uassert(16994, str::stream() << "failed to create temporary $out collection '" << _tempNs.ns() - << "': " << info.toString(), + << "': " + << info.toString(), ok); } @@ -103,7 +104,10 @@ void DocumentSourceOut::prepTempCollection() { BSONObj err = conn->getLastErrorDetailed(); uassert(16995, str::stream() << "copying index for $out failed." - << " index: " << indexBson << " error: " << err, + << " index: " + << indexBson + << " error: " + << err, DBClientWithCommands::getLastErrorString(err).empty()); } } diff --git a/src/mongo/db/pipeline/document_source_redact.cpp b/src/mongo/db/pipeline/document_source_redact.cpp index b1d2c9e54f2..38f1e9fa8b8 100644 --- a/src/mongo/db/pipeline/document_source_redact.cpp +++ b/src/mongo/db/pipeline/document_source_redact.cpp @@ -150,7 +150,8 @@ boost::optional<Document> DocumentSourceRedact::redactObject() { uasserted(17053, str::stream() << "$redact's expression should not return anything " << "aside from the variables $$KEEP, $$DESCEND, and " - << "$$PRUNE, but returned " << expressionResult.toString()); + << "$$PRUNE, but returned " + << expressionResult.toString()); } } diff --git a/src/mongo/db/pipeline/document_source_sample_from_random_cursor.cpp b/src/mongo/db/pipeline/document_source_sample_from_random_cursor.cpp index 802a5d05aab..dafae4ed111 100644 --- a/src/mongo/db/pipeline/document_source_sample_from_random_cursor.cpp +++ b/src/mongo/db/pipeline/document_source_sample_from_random_cursor.cpp @@ -106,9 +106,12 @@ boost::optional<Document> DocumentSourceSampleFromRandomCursor::getNextNonDuplic uassert( 28793, str::stream() - << "The optimized $sample stage requires all documents have a " << _idField + << "The optimized $sample stage requires all documents have a " + << _idField << " field in order to de-duplicate results, but encountered a document without a " - << _idField << " field: " << (*doc).toString(), + << _idField + << " field: " + << (*doc).toString(), !idField.missing()); if (_seenDocs.insert(std::move(idField)).second) { @@ -118,8 +121,9 @@ boost::optional<Document> DocumentSourceSampleFromRandomCursor::getNextNonDuplic } uasserted(28799, str::stream() << "$sample stage could not find a non-duplicate document after " - << kMaxAttempts << " while using a random cursor. This is likely a " - "sporadic failure, please try again."); + << kMaxAttempts + << " while using a random cursor. This is likely a " + "sporadic failure, please try again."); } Value DocumentSourceSampleFromRandomCursor::serialize(bool explain) const { diff --git a/src/mongo/db/pipeline/document_source_sort.cpp b/src/mongo/db/pipeline/document_source_sort.cpp index f2e5dca0347..c9c21043497 100644 --- a/src/mongo/db/pipeline/document_source_sort.cpp +++ b/src/mongo/db/pipeline/document_source_sort.cpp @@ -76,7 +76,8 @@ void DocumentSourceSort::serializeToArray(vector<Value>& array, bool explain) co array.push_back( Value(DOC(getSourceName() << DOC("sortKey" << serializeSortKey(explain) << "mergePresorted" - << (_mergingPresorted ? Value(true) : Value()) << "limit" + << (_mergingPresorted ? Value(true) : Value()) + << "limit" << (limitSrc ? Value(limitSrc->getLimit()) : Value()))))); } else { // one Value for $sort and maybe a Value for $limit MutableDocument inner(serializeSortKey(explain)); diff --git a/src/mongo/db/pipeline/document_source_test.cpp b/src/mongo/db/pipeline/document_source_test.cpp index e0c6782883e..b5ed007d1f9 100644 --- a/src/mongo/db/pipeline/document_source_test.cpp +++ b/src/mongo/db/pipeline/document_source_test.cpp @@ -40,9 +40,9 @@ #include "mongo/db/storage/storage_options.h" #include "mongo/dbtests/dbtests.h" #include "mongo/stdx/memory.h" +#include "mongo/unittest/temp_dir.h" #include "mongo/util/clock_source_mock.h" #include "mongo/util/tick_source_mock.h" -#include "mongo/unittest/temp_dir.h" namespace mongo { bool isMongos() { @@ -117,7 +117,7 @@ TEST(TruncateSort, TruncateSortDedupsSortCorrectly) { } template <size_t ArrayLen> -set<string> arrayToSet(const char*(&array)[ArrayLen]) { +set<string> arrayToSet(const char* (&array)[ArrayLen]) { set<string> out; for (size_t i = 0; i < ArrayLen; i++) out.insert(array[i]); @@ -837,8 +837,9 @@ class TwoValuesTwoKeys : public CheckResultsBase { virtual BSONObj groupSpec() { return BSON("_id" << "$_id" - << "a" << BSON("$push" - << "$a")); + << "a" + << BSON("$push" + << "$a")); } virtual string expectedResultSetString() { return "[{_id:0,a:[1]},{_id:1,a:[2]}]"; @@ -856,8 +857,9 @@ class FourValuesTwoKeys : public CheckResultsBase { virtual BSONObj groupSpec() { return BSON("_id" << "$id" - << "a" << BSON("$push" - << "$a")); + << "a" + << BSON("$push" + << "$a")); } virtual string expectedResultSetString() { return "[{_id:0,a:[1,3]},{_id:1,a:[2,4]}]"; @@ -875,8 +877,10 @@ class FourValuesTwoKeysTwoAccumulators : public CheckResultsBase { virtual BSONObj groupSpec() { return BSON("_id" << "$id" - << "list" << BSON("$push" - << "$a") << "sum" + << "list" + << BSON("$push" + << "$a") + << "sum" << BSON("$sum" << BSON("$divide" << BSON_ARRAY("$a" << 2)))); } virtual string expectedResultSetString() { @@ -892,8 +896,9 @@ class GroupNullUndefinedIds : public CheckResultsBase { virtual BSONObj groupSpec() { return BSON("_id" << "$a" - << "sum" << BSON("$sum" - << "$b")); + << "sum" + << BSON("$sum" + << "$b")); } virtual string expectedResultSetString() { return "[{_id:null,sum:110}]"; @@ -957,8 +962,9 @@ public: // Create a group source. createGroup(BSON("_id" << "$x" - << "list" << BSON("$push" - << "$y"))); + << "list" + << BSON("$push" + << "$y"))); // Create a merger version of the source. intrusive_ptr<DocumentSource> group = createMerger(); // Attach the merger to the synthetic shard results. @@ -2348,7 +2354,8 @@ private: void createUnwind(bool preserveNullAndEmptyArrays, bool includeArrayIndex) { auto specObj = DOC("$unwind" << DOC("path" << unwindFieldPath() << "preserveNullAndEmptyArrays" - << preserveNullAndEmptyArrays << "includeArrayIndex" + << preserveNullAndEmptyArrays + << "includeArrayIndex" << (includeArrayIndex ? Value(indexPath()) : Value()))); _unwind = static_cast<DocumentSourceUnwind*>( DocumentSourceUnwind::createFromBson(specObj.toBson().firstElement(), ctx()).get()); @@ -2396,11 +2403,12 @@ private: } BSONObj expectedSerialization(bool preserveNullAndEmptyArrays, bool includeArrayIndex) const { - return DOC("$unwind" << DOC( - "path" << Value(unwindFieldPath()) << "preserveNullAndEmptyArrays" - << (preserveNullAndEmptyArrays ? Value(true) : Value()) - << "includeArrayIndex" - << (includeArrayIndex ? Value(indexPath()) : Value()))).toBson(); + return DOC("$unwind" << DOC("path" << Value(unwindFieldPath()) + << "preserveNullAndEmptyArrays" + << (preserveNullAndEmptyArrays ? Value(true) : Value()) + << "includeArrayIndex" + << (includeArrayIndex ? Value(indexPath()) : Value()))) + .toBson(); } /** Assert that iterator state accessors consistently report the source is exhausted. */ @@ -2911,7 +2919,8 @@ TEST_F(InvalidUnwindSpec, NonDollarPrefixedPath) { TEST_F(InvalidUnwindSpec, NonBoolPreserveNullAndEmptyArrays) { ASSERT_THROWS_CODE(createUnwind(BSON("$unwind" << BSON("path" << "$x" - << "preserveNullAndEmptyArrays" << 2))), + << "preserveNullAndEmptyArrays" + << 2))), UserException, 28809); } @@ -2919,7 +2928,8 @@ TEST_F(InvalidUnwindSpec, NonBoolPreserveNullAndEmptyArrays) { TEST_F(InvalidUnwindSpec, NonStringIncludeArrayIndex) { ASSERT_THROWS_CODE(createUnwind(BSON("$unwind" << BSON("path" << "$x" - << "includeArrayIndex" << 2))), + << "includeArrayIndex" + << 2))), UserException, 28810); } @@ -2951,13 +2961,16 @@ TEST_F(InvalidUnwindSpec, DollarPrefixedIncludeArrayIndex) { TEST_F(InvalidUnwindSpec, UnrecognizedOption) { ASSERT_THROWS_CODE(createUnwind(BSON("$unwind" << BSON("path" << "$x" - << "preserveNullAndEmptyArrays" << true - << "foo" << 3))), + << "preserveNullAndEmptyArrays" + << true + << "foo" + << 3))), UserException, 28811); ASSERT_THROWS_CODE(createUnwind(BSON("$unwind" << BSON("path" << "$x" - << "foo" << 3))), + << "foo" + << 3))), UserException, 28811); } @@ -3306,9 +3319,8 @@ public: match1->optimizeAt(container.begin(), &container); ASSERT_EQUALS(container.size(), 1U); ASSERT_EQUALS(match1->getQuery(), - fromjson( - "{'$and': [{'$and': [{a:1}, {b:1}]}," - "{c:1}]}")); + fromjson("{'$and': [{'$and': [{a:1}, {b:1}]}," + "{c:1}]}")); } }; @@ -3367,7 +3379,8 @@ public: << "foreignField" << "c" << "as" - << "d.e")).firstElement(), + << "d.e")) + .firstElement(), ctx()); lookup->setSource(source.get()); @@ -3391,7 +3404,8 @@ public: << "foreignField" << "c" << "as" - << "d")).firstElement(), + << "d")) + .firstElement(), ctx()); lookup->setSource(source.get()); diff --git a/src/mongo/db/pipeline/document_source_unwind.cpp b/src/mongo/db/pipeline/document_source_unwind.cpp index bba51298389..58a4d979146 100644 --- a/src/mongo/db/pipeline/document_source_unwind.cpp +++ b/src/mongo/db/pipeline/document_source_unwind.cpp @@ -309,7 +309,8 @@ intrusive_ptr<DocumentSource> DocumentSourceUnwind::createFromBson( indexPath = subElem.String(); uassert(28822, str::stream() << "includeArrayIndex option to $unwind stage should not be " - "prefixed with a '$': " << (*indexPath), + "prefixed with a '$': " + << (*indexPath), (*indexPath)[0] != '$'); } else { uasserted(28811, diff --git a/src/mongo/db/pipeline/expression.cpp b/src/mongo/db/pipeline/expression.cpp index 8024ec39cf2..9c68924d476 100644 --- a/src/mongo/db/pipeline/expression.cpp +++ b/src/mongo/db/pipeline/expression.cpp @@ -40,9 +40,9 @@ #include "mongo/db/pipeline/document.h" #include "mongo/db/pipeline/expression_context.h" #include "mongo/db/pipeline/value.h" -#include "mongo/util/string_map.h" -#include "mongo/util/mongoutils/str.h" #include "mongo/platform/bits.h" +#include "mongo/util/mongoutils/str.h" +#include "mongo/util/string_map.h" namespace mongo { using Parser = Expression::Parser; @@ -85,7 +85,9 @@ void Variables::uassertValidNameForUserWrite(StringData varName) { uassert(16868, str::stream() << "'" << varName << "' contains an invalid character " - << "for a variable name: '" << varName[i] << "'", + << "for a variable name: '" + << varName[i] + << "'", charIsValid); } } @@ -110,7 +112,9 @@ void Variables::uassertValidNameForUserRead(StringData varName) { uassert(16871, str::stream() << "'" << varName << "' contains an invalid character " - << "for a variable name: '" << varName[i] << "'", + << "for a variable name: '" + << varName[i] + << "'", charIsValid); } } @@ -182,7 +186,8 @@ bool Expression::ObjectCtx::inclusionOk() const { string Expression::removeFieldPrefix(const string& prefixedField) { uassert(16419, str::stream() << "field path must not contain embedded null characters" - << prefixedField.find("\0") << ",", + << prefixedField.find("\0") + << ",", prefixedField.find('\0') == string::npos); const char* pPrefixedField = prefixedField.c_str(); @@ -220,7 +225,8 @@ intrusive_ptr<Expression> Expression::parseObject(BSONObj obj, uassert( 15983, str::stream() << "the operator must be the only field in a pipeline object (at '" - << pFieldName << "'", + << pFieldName + << "'", fieldCount == 0); uassert(16404, @@ -234,7 +240,9 @@ intrusive_ptr<Expression> Expression::parseObject(BSONObj obj, } else { uassert(15990, str::stream() << "this object is already an operator expression, and can't be " - "used as a document expression (at '" << pFieldName << "')", + "used as a document expression (at '" + << pFieldName + << "')", kind != OPERATOR); uassert(16405, @@ -299,7 +307,9 @@ intrusive_ptr<Expression> Expression::parseObject(BSONObj obj, default: uassert(15992, str::stream() << "disallowed field type " << typeName(fieldType) - << " in object expression (at '" << fieldName << "')", + << " in object expression (at '" + << fieldName + << "')", false); } } @@ -637,11 +647,13 @@ Value ExpressionArrayElemAt::evaluateInternal(Variables* vars) const { array.isArray()); uassert(28690, str::stream() << getOpName() << "'s second argument must be a numeric value," - << " but is " << typeName(indexArg.getType()), + << " but is " + << typeName(indexArg.getType()), indexArg.numeric()); uassert(28691, str::stream() << getOpName() << "'s second argument must be representable as" - << " a 32-bit integer: " << indexArg.coerceToDouble(), + << " a 32-bit integer: " + << indexArg.coerceToDouble(), indexArg.integral()); long long i = indexArg.coerceToLong(); @@ -969,8 +981,8 @@ intrusive_ptr<Expression> ExpressionDateToString::parse(BSONElement expr, dateElem = arg; } else { uasserted(18534, - str::stream() - << "Unrecognized argument to $dateToString: " << arg.fieldName()); + str::stream() << "Unrecognized argument to $dateToString: " + << arg.fieldName()); } } @@ -1070,7 +1082,8 @@ string ExpressionDateToString::formatDate(const string& format, const int year = ExpressionYear::extract(tm); uassert(18537, str::stream() << "$dateToString is only defined on year 0-9999," - << " tried to use year " << year, + << " tried to use year " + << year, (year >= 0) && (year <= 9999)); insertPadded(formatted, year, 4); break; @@ -1201,7 +1214,9 @@ Value ExpressionDivide::evaluateInternal(Variables* vars) const { } else { uasserted(16609, str::stream() << "$divide only supports numeric types, not " - << typeName(lhs.getType()) << " and " << typeName(rhs.getType())); + << typeName(lhs.getType()) + << " and " + << typeName(rhs.getType())); } } @@ -1683,8 +1698,9 @@ intrusive_ptr<Expression> ExpressionFilter::optimize() { } Value ExpressionFilter::serialize(bool explain) const { - return Value(DOC("$filter" << DOC("input" << _input->serialize(explain) << "as" << _varName - << "cond" << _filter->serialize(explain)))); + return Value( + DOC("$filter" << DOC("input" << _input->serialize(explain) << "as" << _varName << "cond" + << _filter->serialize(explain)))); } Value ExpressionFilter::evaluateInternal(Variables* vars) const { @@ -2038,7 +2054,9 @@ Value ExpressionMod::evaluateInternal(Variables* vars) const { } else { uasserted(16611, str::stream() << "$mod only supports numeric types, not " - << typeName(lhs.getType()) << " and " << typeName(rhs.getType())); + << typeName(lhs.getType()) + << " and " + << typeName(rhs.getType())); } } @@ -2165,12 +2183,15 @@ void uassertIfNotIntegralAndNonNegative(Value val, StringData argumentName) { uassert(40096, str::stream() << expressionName << "requires an integral " << argumentName - << ", found a value of type: " << typeName(val.getType()) - << ", with value: " << val.toString(), + << ", found a value of type: " + << typeName(val.getType()) + << ", with value: " + << val.toString(), val.integral()); uassert(40097, str::stream() << expressionName << " requires a nonnegative " << argumentName - << ", found: " << val.toString(), + << ", found: " + << val.toString(), val.coerceToInt() >= 0); } @@ -2796,7 +2817,8 @@ Value ExpressionRange::evaluateInternal(Variables* vars) const { startVal.numeric()); uassert(34444, str::stream() << "$range requires a starting value that can be represented as a 32-bit " - "integer, found value: " << startVal.toString(), + "integer, found value: " + << startVal.toString(), startVal.integral()); uassert(34445, str::stream() << "$range requires a numeric ending value, found value of type: " @@ -2804,7 +2826,8 @@ Value ExpressionRange::evaluateInternal(Variables* vars) const { endVal.numeric()); uassert(34446, str::stream() << "$range requires an ending value that can be represented as a 32-bit " - "integer, found value: " << endVal.toString(), + "integer, found value: " + << endVal.toString(), endVal.integral()); int current = startVal.coerceToInt(); @@ -2821,7 +2844,8 @@ Value ExpressionRange::evaluateInternal(Variables* vars) const { stepVal.numeric()); uassert(34448, str::stream() << "$range requires a step value that can be represented as a 32-bit " - "integer, found value: " << stepVal.toString(), + "integer, found value: " + << stepVal.toString(), stepVal.integral()); step = stepVal.coerceToInt(); @@ -2984,11 +3008,13 @@ Value ExpressionSetDifference::evaluateInternal(Variables* vars) const { uassert(17048, str::stream() << "both operands of $setDifference must be arrays. First " - << "argument is of type: " << typeName(lhs.getType()), + << "argument is of type: " + << typeName(lhs.getType()), lhs.isArray()); uassert(17049, str::stream() << "both operands of $setDifference must be arrays. Second " - << "argument is of type: " << typeName(rhs.getType()), + << "argument is of type: " + << typeName(rhs.getType()), rhs.isArray()); ValueSet rhsSet = arrayToSet(rhs); @@ -3026,7 +3052,8 @@ Value ExpressionSetEquals::evaluateInternal(Variables* vars) const { const Value nextEntry = vpOperand[i]->evaluateInternal(vars); uassert(17044, str::stream() << "All operands of $setEquals must be arrays. One " - << "argument is of type: " << typeName(nextEntry.getType()), + << "argument is of type: " + << typeName(nextEntry.getType()), nextEntry.isArray()); if (i == 0) { @@ -3058,7 +3085,8 @@ Value ExpressionSetIntersection::evaluateInternal(Variables* vars) const { } uassert(17047, str::stream() << "All operands of $setIntersection must be arrays. One " - << "argument is of type: " << typeName(nextEntry.getType()), + << "argument is of type: " + << typeName(nextEntry.getType()), nextEntry.isArray()); if (i == 0) { @@ -3113,11 +3141,13 @@ Value ExpressionSetIsSubset::evaluateInternal(Variables* vars) const { uassert(17046, str::stream() << "both operands of $setIsSubset must be arrays. First " - << "argument is of type: " << typeName(lhs.getType()), + << "argument is of type: " + << typeName(lhs.getType()), lhs.isArray()); uassert(17042, str::stream() << "both operands of $setIsSubset must be arrays. Second " - << "argument is of type: " << typeName(rhs.getType()), + << "argument is of type: " + << typeName(rhs.getType()), rhs.isArray()); return setIsSubsetHelper(lhs.getArray(), arrayToSet(rhs)); @@ -3142,7 +3172,8 @@ public: uassert(17310, str::stream() << "both operands of $setIsSubset must be arrays. First " - << "argument is of type: " << typeName(lhs.getType()), + << "argument is of type: " + << typeName(lhs.getType()), lhs.isArray()); return setIsSubsetHelper(lhs.getArray(), _cachedRhsSet); @@ -3164,7 +3195,8 @@ intrusive_ptr<Expression> ExpressionSetIsSubset::optimize() { const Value rhs = ec->getValue(); uassert(17311, str::stream() << "both operands of $setIsSubset must be arrays. Second " - << "argument is of type: " << typeName(rhs.getType()), + << "argument is of type: " + << typeName(rhs.getType()), rhs.isArray()); return new Optimized(arrayToSet(rhs), vpOperand); @@ -3189,7 +3221,8 @@ Value ExpressionSetUnion::evaluateInternal(Variables* vars) const { } uassert(17043, str::stream() << "All operands of $setUnion must be arrays. One argument" - << " is of type: " << typeName(newEntries.getType()), + << " is of type: " + << typeName(newEntries.getType()), newEntries.isArray()); unionedSet.insert(newEntries.getArray().begin(), newEntries.getArray().end()); @@ -3229,15 +3262,18 @@ Value ExpressionSlice::evaluateInternal(Variables* vars) const { uassert(28724, str::stream() << "First argument to $slice must be an array, but is" - << " of type: " << typeName(arrayVal.getType()), + << " of type: " + << typeName(arrayVal.getType()), arrayVal.isArray()); uassert(28725, str::stream() << "Second argument to $slice must be a numeric value," - << " but is of type: " << typeName(arg2.getType()), + << " but is of type: " + << typeName(arg2.getType()), arg2.numeric()); uassert(28726, str::stream() << "Second argument to $slice can't be represented as" - << " a 32-bit integer: " << arg2.coerceToDouble(), + << " a 32-bit integer: " + << arg2.coerceToDouble(), arg2.integral()); const auto& array = arrayVal.getArray(); @@ -3277,11 +3313,13 @@ Value ExpressionSlice::evaluateInternal(Variables* vars) const { uassert(28727, str::stream() << "Third argument to $slice must be numeric, but " - << "is of type: " << typeName(countVal.getType()), + << "is of type: " + << typeName(countVal.getType()), countVal.numeric()); uassert(28728, str::stream() << "Third argument to $slice can't be represented" - << " as a 32-bit integer: " << countVal.coerceToDouble(), + << " as a 32-bit integer: " + << countVal.coerceToDouble(), countVal.integral()); uassert(28729, str::stream() << "Third argument to $slice must be positive: " @@ -3329,11 +3367,13 @@ Value ExpressionSplit::evaluateInternal(Variables* vars) const { uassert(40085, str::stream() << "$split requires an expression that evaluates to a string as a first " - "argument, found: " << typeName(inputArg.getType()), + "argument, found: " + << typeName(inputArg.getType()), inputArg.getType() == BSONType::String); uassert(40086, str::stream() << "$split requires an expression that evaluates to a string as a second " - "argument, found: " << typeName(separatorArg.getType()), + "argument, found: " + << typeName(separatorArg.getType()), separatorArg.getType() == BSONType::String); std::string input = inputArg.getString(); @@ -3421,12 +3461,14 @@ Value ExpressionSubstrBytes::evaluateInternal(Variables* vars) const { uassert(16034, str::stream() << getOpName() << ": starting index must be a numeric type (is BSON type " - << typeName(pLower.getType()) << ")", + << typeName(pLower.getType()) + << ")", (pLower.getType() == NumberInt || pLower.getType() == NumberLong || pLower.getType() == NumberDouble)); uassert(16035, str::stream() << getOpName() << ": length must be a numeric type (is BSON type " - << typeName(pLength.getType()) << ")", + << typeName(pLength.getType()) + << ")", (pLength.getType() == NumberInt || pLength.getType() == NumberLong || pLength.getType() == NumberDouble)); @@ -3471,7 +3513,8 @@ Value ExpressionSubstrCP::evaluateInternal(Variables* vars) const { std::string str = inputVal.coerceToString(); uassert(34450, str::stream() << getOpName() << ": starting index must be a numeric type (is BSON type " - << typeName(lowerVal.getType()) << ")", + << typeName(lowerVal.getType()) + << ")", lowerVal.numeric()); uassert(34451, str::stream() << getOpName() @@ -3480,7 +3523,8 @@ Value ExpressionSubstrCP::evaluateInternal(Variables* vars) const { lowerVal.integral()); uassert(34452, str::stream() << getOpName() << ": length must be a numeric type (is BSON type " - << typeName(lengthVal.getType()) << ")", + << typeName(lengthVal.getType()) + << ")", lengthVal.numeric()); uassert(34453, str::stream() << getOpName() @@ -3562,10 +3606,10 @@ const char* ExpressionStrLenBytes::getOpName() const { Value ExpressionStrLenCP::evaluateInternal(Variables* vars) const { Value val(vpOperand[0]->evaluateInternal(vars)); - uassert( - 34471, - str::stream() << "$strLenCP requires a string argument, found: " << typeName(val.getType()), - val.getType() == String); + uassert(34471, + str::stream() << "$strLenCP requires a string argument, found: " + << typeName(val.getType()), + val.getType() == String); std::string stringVal = val.getString(); @@ -4076,10 +4120,10 @@ Value ExpressionZip::evaluateInternal(Variables* vars) const { return Value(BSONNULL); } - uassert( - 34468, - str::stream() << "$zip found a non-array expression in input: " << evalExpr.toString(), - evalExpr.isArray()); + uassert(34468, + str::stream() << "$zip found a non-array expression in input: " + << evalExpr.toString(), + evalExpr.isArray()); inputValues.push_back(evalExpr.getArray()); @@ -4136,14 +4180,16 @@ boost::intrusive_ptr<Expression> ExpressionZip::optimize() { std::transform(_inputs.begin(), _inputs.end(), _inputs.begin(), - [](intrusive_ptr<Expression> inputExpression) - -> intrusive_ptr<Expression> { return inputExpression->optimize(); }); + [](intrusive_ptr<Expression> inputExpression) -> intrusive_ptr<Expression> { + return inputExpression->optimize(); + }); std::transform(_defaults.begin(), _defaults.end(), _defaults.begin(), - [](intrusive_ptr<Expression> defaultExpression) - -> intrusive_ptr<Expression> { return defaultExpression->optimize(); }); + [](intrusive_ptr<Expression> defaultExpression) -> intrusive_ptr<Expression> { + return defaultExpression->optimize(); + }); return this; } @@ -4162,19 +4208,21 @@ Value ExpressionZip::serialize(bool explain) const { } return Value(DOC("$zip" << DOC("inputs" << Value(serializedInput) << "defaults" - << Value(serializedDefaults) << "useLongestLength" + << Value(serializedDefaults) + << "useLongestLength" << serializedUseLongestLength))); } void ExpressionZip::addDependencies(DepsTracker* deps, std::vector<std::string>* path) const { - std::for_each(_inputs.begin(), - _inputs.end(), - [&deps](intrusive_ptr<Expression> inputExpression) - -> void { inputExpression->addDependencies(deps); }); + std::for_each( + _inputs.begin(), _inputs.end(), [&deps](intrusive_ptr<Expression> inputExpression) -> void { + inputExpression->addDependencies(deps); + }); std::for_each(_defaults.begin(), _defaults.end(), - [&deps](intrusive_ptr<Expression> defaultExpression) - -> void { defaultExpression->addDependencies(deps); }); + [&deps](intrusive_ptr<Expression> defaultExpression) -> void { + defaultExpression->addDependencies(deps); + }); } const char* ExpressionZip::getOpName() const { diff --git a/src/mongo/db/pipeline/expression.h b/src/mongo/db/pipeline/expression.h index 87a9536e689..8ed6f95f6eb 100644 --- a/src/mongo/db/pipeline/expression.h +++ b/src/mongo/db/pipeline/expression.h @@ -394,10 +394,14 @@ class ExpressionRangedArity : public ExpressionNaryBase<SubClass> { public: void validateArguments(const Expression::ExpressionVector& args) const override { uassert(28667, - mongoutils::str::stream() - << "Expression " << this->getOpName() << " takes at least " << MinArgs - << " arguments, and at most " << MaxArgs << ", but " << args.size() - << " were passed in.", + mongoutils::str::stream() << "Expression " << this->getOpName() + << " takes at least " + << MinArgs + << " arguments, and at most " + << MaxArgs + << ", but " + << args.size() + << " were passed in.", MinArgs <= args.size() && args.size() <= MaxArgs); } }; @@ -409,7 +413,9 @@ public: void validateArguments(const Expression::ExpressionVector& args) const override { uassert(16020, mongoutils::str::stream() << "Expression " << this->getOpName() << " takes exactly " - << NArgs << " arguments. " << args.size() + << NArgs + << " arguments. " + << args.size() << " were passed in.", args.size() == NArgs); } diff --git a/src/mongo/db/pipeline/expression_test.cpp b/src/mongo/db/pipeline/expression_test.cpp index d4b566e2bb4..2487bfc18f1 100644 --- a/src/mongo/db/pipeline/expression_test.cpp +++ b/src/mongo/db/pipeline/expression_test.cpp @@ -528,8 +528,8 @@ TEST_F(ExpressionNaryTest, FlattenInnerOperandsOptimizationOnAssociativeOnlyMidd intrusive_ptr<Expression> optimized = _associativeOnly->optimize(); ASSERT(_associativeOnly == optimized); - BSONArray expectedContent = BSON_ARRAY(200 << "$path3" << BSON_ARRAY(201 << 100) << "$path1" - << BSON_ARRAY(101 << 99) << "$path2"); + BSONArray expectedContent = BSON_ARRAY( + 200 << "$path3" << BSON_ARRAY(201 << 100) << "$path1" << BSON_ARRAY(101 << 99) << "$path2"); assertContents(_associativeOnly, expectedContent); } @@ -1368,7 +1368,8 @@ class NonConstantZero : public OptimizeBase { class NonConstantNonConstantOne : public OptimizeBase { BSONObj spec() { return BSON("$and" << BSON_ARRAY("$a" - << "$b" << 1)); + << "$b" + << 1)); } BSONObj expectedOptimized() { return BSON("$and" << BSON_ARRAY("$a" @@ -1380,7 +1381,8 @@ class NonConstantNonConstantOne : public OptimizeBase { class NonConstantNonConstantZero : public OptimizeBase { BSONObj spec() { return BSON("$and" << BSON_ARRAY("$a" - << "$b" << 0)); + << "$b" + << 0)); } BSONObj expectedOptimized() { return BSON("$const" << false); @@ -2250,12 +2252,11 @@ public: void run() { intrusive_ptr<Expression> expression = ExpressionFieldPath::create("a.b.c"); assertBinaryEqual(fromjson("{'':[[1,2],3,[4],[[5]],[6,7]]}"), - toBson(expression->evaluate(fromBson(fromjson( - "{a:[{b:[{c:1},{c:2}]}," - "{b:{c:3}}," - "{b:[{c:4}]}," - "{b:[{c:[5]}]}," - "{b:{c:[6,7]}}]}"))))); + toBson(expression->evaluate(fromBson(fromjson("{a:[{b:[{c:1},{c:2}]}," + "{b:{c:3}}," + "{b:[{c:4}]}," + "{b:[{c:[5]}]}," + "{b:{c:[6,7]}}]}"))))); } }; @@ -3386,7 +3387,8 @@ class NonConstantZero : public OptimizeBase { class NonConstantNonConstantOne : public OptimizeBase { BSONObj spec() { return BSON("$or" << BSON_ARRAY("$a" - << "$b" << 1)); + << "$b" + << 1)); } BSONObj expectedOptimized() { return BSON("$const" << true); @@ -3397,7 +3399,8 @@ class NonConstantNonConstantOne : public OptimizeBase { class NonConstantNonConstantZero : public OptimizeBase { BSONObj spec() { return BSON("$or" << BSON_ARRAY("$a" - << "$b" << 0)); + << "$b" + << 0)); } BSONObj expectedOptimized() { return BSON("$or" << BSON_ARRAY("$a" @@ -3996,13 +3999,15 @@ public: const BSONObj obj = BSON(asserters[i].getString() << args); VariablesIdGenerator idGenerator; VariablesParseState vps(&idGenerator); - ASSERT_THROWS({ - // NOTE: parse and evaluatation failures are treated the - // same - const intrusive_ptr<Expression> expr = - Expression::parseExpression(obj.firstElement(), vps); - expr->evaluate(Document()); - }, UserException); + ASSERT_THROWS( + { + // NOTE: parse and evaluatation failures are treated the + // same + const intrusive_ptr<Expression> expr = + Expression::parseExpression(obj.firstElement(), vps); + expr->evaluate(Document()); + }, + UserException); } } } @@ -4015,9 +4020,12 @@ class Same : public ExpectedResultBase { Document getSpec() { return DOC("input" << DOC_ARRAY(DOC_ARRAY(1 << 2) << DOC_ARRAY(1 << 2)) << "expected" << DOC("$setIsSubset" << true << "$setEquals" << true - << "$setIntersection" << DOC_ARRAY(1 << 2) - << "$setUnion" << DOC_ARRAY(1 << 2) - << "$setDifference" << vector<Value>())); + << "$setIntersection" + << DOC_ARRAY(1 << 2) + << "$setUnion" + << DOC_ARRAY(1 << 2) + << "$setDifference" + << vector<Value>())); } }; @@ -4025,9 +4033,12 @@ class Redundant : public ExpectedResultBase { Document getSpec() { return DOC("input" << DOC_ARRAY(DOC_ARRAY(1 << 2) << DOC_ARRAY(1 << 2 << 2)) << "expected" << DOC("$setIsSubset" << true << "$setEquals" << true - << "$setIntersection" << DOC_ARRAY(1 << 2) - << "$setUnion" << DOC_ARRAY(1 << 2) - << "$setDifference" << vector<Value>())); + << "$setIntersection" + << DOC_ARRAY(1 << 2) + << "$setUnion" + << DOC_ARRAY(1 << 2) + << "$setDifference" + << vector<Value>())); } }; @@ -4036,8 +4047,11 @@ class DoubleRedundant : public ExpectedResultBase { return DOC( "input" << DOC_ARRAY(DOC_ARRAY(1 << 1 << 2) << DOC_ARRAY(1 << 2 << 2)) << "expected" << DOC("$setIsSubset" << true << "$setEquals" << true << "$setIntersection" - << DOC_ARRAY(1 << 2) << "$setUnion" << DOC_ARRAY(1 << 2) - << "$setDifference" << vector<Value>())); + << DOC_ARRAY(1 << 2) + << "$setUnion" + << DOC_ARRAY(1 << 2) + << "$setDifference" + << vector<Value>())); } }; @@ -4045,9 +4059,12 @@ class Super : public ExpectedResultBase { Document getSpec() { return DOC("input" << DOC_ARRAY(DOC_ARRAY(1 << 2) << DOC_ARRAY(1)) << "expected" << DOC("$setIsSubset" << false << "$setEquals" << false - << "$setIntersection" << DOC_ARRAY(1) - << "$setUnion" << DOC_ARRAY(1 << 2) - << "$setDifference" << DOC_ARRAY(2))); + << "$setIntersection" + << DOC_ARRAY(1) + << "$setUnion" + << DOC_ARRAY(1 << 2) + << "$setDifference" + << DOC_ARRAY(2))); } }; @@ -4055,9 +4072,12 @@ class SuperWithRedundant : public ExpectedResultBase { Document getSpec() { return DOC("input" << DOC_ARRAY(DOC_ARRAY(1 << 2 << 2) << DOC_ARRAY(1)) << "expected" << DOC("$setIsSubset" << false << "$setEquals" << false - << "$setIntersection" << DOC_ARRAY(1) - << "$setUnion" << DOC_ARRAY(1 << 2) - << "$setDifference" << DOC_ARRAY(2))); + << "$setIntersection" + << DOC_ARRAY(1) + << "$setUnion" + << DOC_ARRAY(1 << 2) + << "$setDifference" + << DOC_ARRAY(2))); } }; @@ -4065,9 +4085,12 @@ class Sub : public ExpectedResultBase { Document getSpec() { return DOC("input" << DOC_ARRAY(DOC_ARRAY(1) << DOC_ARRAY(1 << 2)) << "expected" << DOC("$setIsSubset" << true << "$setEquals" << false - << "$setIntersection" << DOC_ARRAY(1) - << "$setUnion" << DOC_ARRAY(1 << 2) - << "$setDifference" << vector<Value>())); + << "$setIntersection" + << DOC_ARRAY(1) + << "$setUnion" + << DOC_ARRAY(1 << 2) + << "$setDifference" + << vector<Value>())); } }; @@ -4075,9 +4098,12 @@ class SameBackwards : public ExpectedResultBase { Document getSpec() { return DOC("input" << DOC_ARRAY(DOC_ARRAY(1 << 2) << DOC_ARRAY(2 << 1)) << "expected" << DOC("$setIsSubset" << true << "$setEquals" << true - << "$setIntersection" << DOC_ARRAY(1 << 2) - << "$setUnion" << DOC_ARRAY(1 << 2) - << "$setDifference" << vector<Value>())); + << "$setIntersection" + << DOC_ARRAY(1 << 2) + << "$setUnion" + << DOC_ARRAY(1 << 2) + << "$setDifference" + << vector<Value>())); } }; @@ -4085,9 +4111,12 @@ class NoOverlap : public ExpectedResultBase { Document getSpec() { return DOC("input" << DOC_ARRAY(DOC_ARRAY(1 << 2) << DOC_ARRAY(8 << 4)) << "expected" << DOC("$setIsSubset" << false << "$setEquals" << false - << "$setIntersection" << vector<Value>() - << "$setUnion" << DOC_ARRAY(1 << 2 << 4 << 8) - << "$setDifference" << DOC_ARRAY(1 << 2))); + << "$setIntersection" + << vector<Value>() + << "$setUnion" + << DOC_ARRAY(1 << 2 << 4 << 8) + << "$setDifference" + << DOC_ARRAY(1 << 2))); } }; @@ -4095,9 +4124,12 @@ class Overlap : public ExpectedResultBase { Document getSpec() { return DOC("input" << DOC_ARRAY(DOC_ARRAY(1 << 2) << DOC_ARRAY(8 << 2 << 4)) << "expected" << DOC("$setIsSubset" << false << "$setEquals" << false - << "$setIntersection" << DOC_ARRAY(2) - << "$setUnion" << DOC_ARRAY(1 << 2 << 4 << 8) - << "$setDifference" << DOC_ARRAY(1))); + << "$setIntersection" + << DOC_ARRAY(2) + << "$setUnion" + << DOC_ARRAY(1 << 2 << 4 << 8) + << "$setDifference" + << DOC_ARRAY(1))); } }; @@ -4105,7 +4137,9 @@ class LastNull : public ExpectedResultBase { Document getSpec() { return DOC("input" << DOC_ARRAY(DOC_ARRAY(1 << 2) << Value(BSONNULL)) << "expected" << DOC("$setIntersection" << BSONNULL << "$setUnion" << BSONNULL - << "$setDifference" << BSONNULL) << "error" + << "$setDifference" + << BSONNULL) + << "error" << DOC_ARRAY("$setEquals" << "$setIsSubset")); } @@ -4115,7 +4149,9 @@ class FirstNull : public ExpectedResultBase { Document getSpec() { return DOC("input" << DOC_ARRAY(Value(BSONNULL) << DOC_ARRAY(1 << 2)) << "expected" << DOC("$setIntersection" << BSONNULL << "$setUnion" << BSONNULL - << "$setDifference" << BSONNULL) << "error" + << "$setDifference" + << BSONNULL) + << "error" << DOC_ARRAY("$setEquals" << "$setIsSubset")); } @@ -4126,9 +4162,10 @@ class NoArg : public ExpectedResultBase { return DOC( "input" << vector<Value>() << "expected" << DOC("$setIntersection" << vector<Value>() << "$setUnion" << vector<Value>()) - << "error" << DOC_ARRAY("$setEquals" - << "$setIsSubset" - << "$setDifference")); + << "error" + << DOC_ARRAY("$setEquals" + << "$setIsSubset" + << "$setDifference")); } }; @@ -4136,7 +4173,8 @@ class OneArg : public ExpectedResultBase { Document getSpec() { return DOC("input" << DOC_ARRAY(DOC_ARRAY(1 << 2)) << "expected" << DOC("$setIntersection" << DOC_ARRAY(1 << 2) << "$setUnion" - << DOC_ARRAY(1 << 2)) << "error" + << DOC_ARRAY(1 << 2)) + << "error" << DOC_ARRAY("$setEquals" << "$setIsSubset" << "$setDifference")); @@ -4148,9 +4186,10 @@ class EmptyArg : public ExpectedResultBase { return DOC( "input" << DOC_ARRAY(vector<Value>()) << "expected" << DOC("$setIntersection" << vector<Value>() << "$setUnion" << vector<Value>()) - << "error" << DOC_ARRAY("$setEquals" - << "$setIsSubset" - << "$setDifference")); + << "error" + << DOC_ARRAY("$setEquals" + << "$setIsSubset" + << "$setDifference")); } }; @@ -4158,8 +4197,12 @@ class LeftArgEmpty : public ExpectedResultBase { Document getSpec() { return DOC("input" << DOC_ARRAY(vector<Value>() << DOC_ARRAY(1 << 2)) << "expected" << DOC("$setIntersection" << vector<Value>() << "$setUnion" - << DOC_ARRAY(1 << 2) << "$setIsSubset" << true - << "$setEquals" << false << "$setDifference" + << DOC_ARRAY(1 << 2) + << "$setIsSubset" + << true + << "$setEquals" + << false + << "$setDifference" << vector<Value>())); } }; @@ -4168,8 +4211,12 @@ class RightArgEmpty : public ExpectedResultBase { Document getSpec() { return DOC("input" << DOC_ARRAY(DOC_ARRAY(1 << 2) << vector<Value>()) << "expected" << DOC("$setIntersection" << vector<Value>() << "$setUnion" - << DOC_ARRAY(1 << 2) << "$setIsSubset" << false - << "$setEquals" << false << "$setDifference" + << DOC_ARRAY(1 << 2) + << "$setIsSubset" + << false + << "$setEquals" + << false + << "$setDifference" << DOC_ARRAY(1 << 2))); } }; @@ -4177,27 +4224,34 @@ class RightArgEmpty : public ExpectedResultBase { class ManyArgs : public ExpectedResultBase { Document getSpec() { return DOC( - "input" << DOC_ARRAY(DOC_ARRAY(8 << 3) - << DOC_ARRAY("asdf" - << "foo") << DOC_ARRAY(80.3 << 34) << vector<Value>() - << DOC_ARRAY(80.3 << "foo" << 11 << "yay")) << "expected" - << DOC("$setIntersection" - << vector<Value>() << "$setEquals" << false << "$setUnion" - << DOC_ARRAY(3 << 8 << 11 << 34 << 80.3 << "asdf" - << "foo" - << "yay")) << "error" << DOC_ARRAY("$setIsSubset" - << "$setDifference")); + "input" << DOC_ARRAY(DOC_ARRAY(8 << 3) << DOC_ARRAY("asdf" + << "foo") + << DOC_ARRAY(80.3 << 34) + << vector<Value>() + << DOC_ARRAY(80.3 << "foo" << 11 << "yay")) + << "expected" + << DOC("$setIntersection" << vector<Value>() << "$setEquals" << false + << "$setUnion" + << DOC_ARRAY(3 << 8 << 11 << 34 << 80.3 << "asdf" + << "foo" + << "yay")) + << "error" + << DOC_ARRAY("$setIsSubset" + << "$setDifference")); } }; class ManyArgsEqual : public ExpectedResultBase { Document getSpec() { - return DOC("input" << DOC_ARRAY(DOC_ARRAY(1 << 2 << 4) - << DOC_ARRAY(1 << 2 << 2 << 4) << DOC_ARRAY(4 << 1 << 2) - << DOC_ARRAY(2 << 1 << 1 << 4)) << "expected" + return DOC("input" << DOC_ARRAY(DOC_ARRAY(1 << 2 << 4) << DOC_ARRAY(1 << 2 << 2 << 4) + << DOC_ARRAY(4 << 1 << 2) + << DOC_ARRAY(2 << 1 << 1 << 4)) + << "expected" << DOC("$setIntersection" << DOC_ARRAY(1 << 2 << 4) << "$setEquals" - << true << "$setUnion" - << DOC_ARRAY(1 << 2 << 4)) << "error" + << true + << "$setUnion" + << DOC_ARRAY(1 << 2 << 4)) + << "error" << DOC_ARRAY("$setIsSubset" << "$setDifference")); } @@ -4757,13 +4811,15 @@ public: const BSONObj obj = BSON(asserters[i].getString() << args); VariablesIdGenerator idGenerator; VariablesParseState vps(&idGenerator); - ASSERT_THROWS({ - // NOTE: parse and evaluatation failures are treated the - // same - const intrusive_ptr<Expression> expr = - Expression::parseExpression(obj.firstElement(), vps); - expr->evaluate(Document()); - }, UserException); + ASSERT_THROWS( + { + // NOTE: parse and evaluatation failures are treated the + // same + const intrusive_ptr<Expression> expr = + Expression::parseExpression(obj.firstElement(), vps); + expr->evaluate(Document()); + }, + UserException); } } } diff --git a/src/mongo/db/pipeline/field_path_test.cpp b/src/mongo/db/pipeline/field_path_test.cpp index 63c0216a76d..92ba167f562 100644 --- a/src/mongo/db/pipeline/field_path_test.cpp +++ b/src/mongo/db/pipeline/field_path_test.cpp @@ -29,9 +29,9 @@ #include "mongo/platform/basic.h" #include "mongo/db/pipeline/field_path.h" +#include "mongo/dbtests/dbtests.h" #include "mongo/unittest/unittest.h" #include "mongo/util/assert_util.h" -#include "mongo/dbtests/dbtests.h" namespace mongo { using std::string; diff --git a/src/mongo/db/pipeline/lookup_set_cache.h b/src/mongo/db/pipeline/lookup_set_cache.h index a40ac28155b..3150d7bc1af 100644 --- a/src/mongo/db/pipeline/lookup_set_cache.h +++ b/src/mongo/db/pipeline/lookup_set_cache.h @@ -29,15 +29,15 @@ #include "mongo/platform/basic.h" -#include <unordered_map> -#include <unordered_set> -#include <iostream> #include <boost/intrusive_ptr.hpp> -#include <boost/multi_index_container.hpp> #include <boost/multi_index/hashed_index.hpp> #include <boost/multi_index/member.hpp> #include <boost/multi_index/sequenced_index.hpp> +#include <boost/multi_index_container.hpp> #include <boost/optional.hpp> +#include <iostream> +#include <unordered_map> +#include <unordered_set> #include "mongo/bson/bsonobj.h" #include "mongo/db/pipeline/value.h" diff --git a/src/mongo/db/pipeline/lookup_set_cache_test.cpp b/src/mongo/db/pipeline/lookup_set_cache_test.cpp index 4d5ec28ad56..2903a3632f5 100644 --- a/src/mongo/db/pipeline/lookup_set_cache_test.cpp +++ b/src/mongo/db/pipeline/lookup_set_cache_test.cpp @@ -28,9 +28,9 @@ #include "mongo/platform/basic.h" +#include "mongo/bson/bsonobjbuilder.h" #include "mongo/db/pipeline/lookup_set_cache.h" #include "mongo/unittest/unittest.h" -#include "mongo/bson/bsonobjbuilder.h" namespace mongo { diff --git a/src/mongo/db/pipeline/pipeline.cpp b/src/mongo/db/pipeline/pipeline.cpp index 32285652e24..9f5d6e1fd67 100644 --- a/src/mongo/db/pipeline/pipeline.cpp +++ b/src/mongo/db/pipeline/pipeline.cpp @@ -499,7 +499,8 @@ void Pipeline::run(BSONObjBuilder& result) { // object will be too large, assert. the extra 1KB is for headers uassert(16389, str::stream() << "aggregation result exceeds maximum document size (" - << BSONObjMaxUserSize / (1024 * 1024) << "MB)", + << BSONObjMaxUserSize / (1024 * 1024) + << "MB)", resultArray.len() < BSONObjMaxUserSize - 1024); } diff --git a/src/mongo/db/pipeline/pipeline_d.cpp b/src/mongo/db/pipeline/pipeline_d.cpp index 6e4c8c817a3..f30e513a2f4 100644 --- a/src/mongo/db/pipeline/pipeline_d.cpp +++ b/src/mongo/db/pipeline/pipeline_d.cpp @@ -37,13 +37,13 @@ #include "mongo/db/catalog/database.h" #include "mongo/db/catalog/document_validation.h" #include "mongo/db/concurrency/write_conflict_exception.h" +#include "mongo/db/db_raii.h" +#include "mongo/db/dbdirectclient.h" #include "mongo/db/exec/fetch.h" #include "mongo/db/exec/index_iterator.h" #include "mongo/db/exec/multi_iterator.h" #include "mongo/db/exec/shard_filter.h" #include "mongo/db/exec/working_set.h" -#include "mongo/db/db_raii.h" -#include "mongo/db/dbdirectclient.h" #include "mongo/db/index/index_access_method.h" #include "mongo/db/matcher/extensions_callback_real.h" #include "mongo/db/pipeline/document_source.h" @@ -51,11 +51,11 @@ #include "mongo/db/query/collation/collation_serializer.h" #include "mongo/db/query/get_executor.h" #include "mongo/db/query/query_planner.h" +#include "mongo/db/s/sharded_connection_info.h" +#include "mongo/db/s/sharding_state.h" #include "mongo/db/service_context.h" #include "mongo/db/storage/record_store.h" #include "mongo/db/storage/sorted_data_interface.h" -#include "mongo/db/s/sharded_connection_info.h" -#include "mongo/db/s/sharding_state.h" #include "mongo/s/chunk_version.h" #include "mongo/stdx/memory.h" #include "mongo/util/log.h" @@ -84,9 +84,8 @@ public: bool isSharded(const NamespaceString& ns) final { const ChunkVersion unsharded(0, 0, OID()); - return !(ShardingState::get(_ctx->opCtx) - ->getVersion(ns.ns()) - .isWriteCompatibleWith(unsharded)); + return !( + ShardingState::get(_ctx->opCtx)->getVersion(ns.ns()).isWriteCompatibleWith(unsharded)); } bool isCapped(const NamespaceString& ns) final { diff --git a/src/mongo/db/pipeline/value.cpp b/src/mongo/db/pipeline/value.cpp index 9d98f8d6f02..8a37c51067c 100644 --- a/src/mongo/db/pipeline/value.cpp +++ b/src/mongo/db/pipeline/value.cpp @@ -30,9 +30,9 @@ #include "mongo/db/pipeline/value.h" +#include <boost/functional/hash.hpp> #include <cmath> #include <limits> -#include <boost/functional/hash.hpp> #include "mongo/base/compare_numbers.h" #include "mongo/base/data_type_endian.h" diff --git a/src/mongo/db/pipeline/value.h b/src/mongo/db/pipeline/value.h index 19b951f852c..c6d4b90c0cd 100644 --- a/src/mongo/db/pipeline/value.h +++ b/src/mongo/db/pipeline/value.h @@ -303,8 +303,7 @@ inline void swap(mongo::Value& lhs, mongo::Value& rhs) { class ImplicitValue : public Value { public: template <typename T> - ImplicitValue(T arg) - : Value(std::move(arg)) {} + ImplicitValue(T arg) : Value(std::move(arg)) {} }; } diff --git a/src/mongo/db/pipeline/value_internal.h b/src/mongo/db/pipeline/value_internal.h index 556eebec060..fe34b97e0a7 100644 --- a/src/mongo/db/pipeline/value_internal.h +++ b/src/mongo/db/pipeline/value_internal.h @@ -32,13 +32,13 @@ #include <boost/config.hpp> #include <boost/intrusive_ptr.hpp> +#include "mongo/bson/bsonmisc.h" #include "mongo/bson/bsonobj.h" #include "mongo/bson/bsontypes.h" -#include "mongo/bson/bsonmisc.h" #include "mongo/bson/oid.h" +#include "mongo/bson/timestamp.h" #include "mongo/util/debug_util.h" #include "mongo/util/intrusive_counter.h" -#include "mongo/bson/timestamp.h" namespace mongo { |