diff options
author | clang-format-7.0.1 <adam.martin@10gen.com> | 2019-07-26 18:20:35 -0400 |
---|---|---|
committer | ADAM David Alan Martin <adam.martin@10gen.com> | 2019-07-27 11:02:23 -0400 |
commit | 134a4083953270e8a11430395357fb70a29047ad (patch) | |
tree | dd428e1230e31d92b20b393dfdc17ffe7fa79cb6 /src/mongo/db/pipeline | |
parent | 1e46b5049003f427047e723ea5fab15b5a9253ca (diff) | |
download | mongo-134a4083953270e8a11430395357fb70a29047ad.tar.gz |
SERVER-41772 Apply clang-format 7.0.1 to the codebase
Diffstat (limited to 'src/mongo/db/pipeline')
94 files changed, 755 insertions, 1217 deletions
diff --git a/src/mongo/db/pipeline/accumulator.h b/src/mongo/db/pipeline/accumulator.h index 1a2986cb374..c382429e6ea 100644 --- a/src/mongo/db/pipeline/accumulator.h +++ b/src/mongo/db/pipeline/accumulator.h @@ -351,4 +351,4 @@ public: private: MutableDocument _output; }; -} +} // namespace mongo diff --git a/src/mongo/db/pipeline/accumulator_avg.cpp b/src/mongo/db/pipeline/accumulator_avg.cpp index 38946678389..43550e9e361 100644 --- a/src/mongo/db/pipeline/accumulator_avg.cpp +++ b/src/mongo/db/pipeline/accumulator_avg.cpp @@ -134,4 +134,4 @@ void AccumulatorAvg::reset() { _decimalTotal = {}; _count = 0; } -} +} // namespace mongo diff --git a/src/mongo/db/pipeline/accumulator_first.cpp b/src/mongo/db/pipeline/accumulator_first.cpp index 3e452f1d0e6..6fcc334af83 100644 --- a/src/mongo/db/pipeline/accumulator_first.cpp +++ b/src/mongo/db/pipeline/accumulator_first.cpp @@ -74,4 +74,4 @@ intrusive_ptr<Accumulator> AccumulatorFirst::create( const boost::intrusive_ptr<ExpressionContext>& expCtx) { return new AccumulatorFirst(expCtx); } -} +} // namespace mongo diff --git a/src/mongo/db/pipeline/accumulator_last.cpp b/src/mongo/db/pipeline/accumulator_last.cpp index 3c667d16d53..4774abca5e9 100644 --- a/src/mongo/db/pipeline/accumulator_last.cpp +++ b/src/mongo/db/pipeline/accumulator_last.cpp @@ -68,4 +68,4 @@ intrusive_ptr<Accumulator> AccumulatorLast::create( const boost::intrusive_ptr<ExpressionContext>& expCtx) { return new AccumulatorLast(expCtx); } -} +} // namespace mongo diff --git a/src/mongo/db/pipeline/accumulator_merge_objects.cpp b/src/mongo/db/pipeline/accumulator_merge_objects.cpp index 4f8ef357f35..8878ff97676 100644 --- a/src/mongo/db/pipeline/accumulator_merge_objects.cpp +++ b/src/mongo/db/pipeline/accumulator_merge_objects.cpp @@ -71,8 +71,7 @@ void AccumulatorMergeObjects::processInternal(const Value& input, bool merging) uassert(40400, str::stream() << "$mergeObjects requires object inputs, but input " << input.toString() - << " is of type " - << typeName(input.getType()), + << " is of type " << typeName(input.getType()), (input.getType() == BSONType::Object)); FieldIterator iter = input.getDocument().fieldIterator(); diff --git a/src/mongo/db/pipeline/accumulator_min_max.cpp b/src/mongo/db/pipeline/accumulator_min_max.cpp index d81403eac85..496d9d94220 100644 --- a/src/mongo/db/pipeline/accumulator_min_max.cpp +++ b/src/mongo/db/pipeline/accumulator_min_max.cpp @@ -89,4 +89,4 @@ intrusive_ptr<Accumulator> AccumulatorMax::create( const boost::intrusive_ptr<ExpressionContext>& expCtx) { return new AccumulatorMax(expCtx); } -} +} // namespace mongo diff --git a/src/mongo/db/pipeline/accumulator_push.cpp b/src/mongo/db/pipeline/accumulator_push.cpp index becb6828635..5c1f640cef8 100644 --- a/src/mongo/db/pipeline/accumulator_push.cpp +++ b/src/mongo/db/pipeline/accumulator_push.cpp @@ -86,4 +86,4 @@ intrusive_ptr<Accumulator> AccumulatorPush::create( const boost::intrusive_ptr<ExpressionContext>& expCtx) { return new AccumulatorPush(expCtx); } -} +} // namespace mongo diff --git a/src/mongo/db/pipeline/accumulator_std_dev.cpp b/src/mongo/db/pipeline/accumulator_std_dev.cpp index a10da2a41c0..a2bce628539 100644 --- a/src/mongo/db/pipeline/accumulator_std_dev.cpp +++ b/src/mongo/db/pipeline/accumulator_std_dev.cpp @@ -118,4 +118,4 @@ void AccumulatorStdDev::reset() { _mean = 0; _m2 = 0; } -} +} // namespace mongo diff --git a/src/mongo/db/pipeline/aggregation_request.cpp b/src/mongo/db/pipeline/aggregation_request.cpp index 54a17b0b980..04c806bb992 100644 --- a/src/mongo/db/pipeline/aggregation_request.cpp +++ b/src/mongo/db/pipeline/aggregation_request.cpp @@ -130,8 +130,7 @@ StatusWith<AggregationRequest> AggregationRequest::parseFromBSON( if (elem.type() != BSONType::Object) { return {ErrorCodes::TypeMismatch, str::stream() << repl::ReadConcernArgs::kReadConcernFieldName - << " must be an object, not a " - << typeName(elem.type())}; + << " must be an object, not a " << typeName(elem.type())}; } request.setReadConcern(elem.embeddedObject().getOwned()); } else if (kHintName == fieldName) { @@ -205,8 +204,8 @@ StatusWith<AggregationRequest> AggregationRequest::parseFromBSON( } else if (WriteConcernOptions::kWriteConcernField == fieldName) { if (elem.type() != BSONType::Object) { return {ErrorCodes::TypeMismatch, - str::stream() << fieldName << " must be an object, not a " - << typeName(elem.type())}; + str::stream() + << fieldName << " must be an object, not a " << typeName(elem.type())}; } WriteConcernOptions writeConcern; @@ -246,23 +245,20 @@ StatusWith<AggregationRequest> AggregationRequest::parseFromBSON( if (!hasCursorElem && !hasExplainElem) { return {ErrorCodes::FailedToParse, str::stream() - << "The '" - << kCursorName + << "The '" << kCursorName << "' option is required, except for aggregate with the explain argument"}; } if (request.getExplain() && cmdObj[WriteConcernOptions::kWriteConcernField]) { return {ErrorCodes::FailedToParse, str::stream() << "Aggregation explain does not support the'" - << WriteConcernOptions::kWriteConcernField - << "' option"}; + << WriteConcernOptions::kWriteConcernField << "' option"}; } if (hasNeedsMergeElem && !hasFromMongosElem) { return {ErrorCodes::FailedToParse, str::stream() << "Cannot specify '" << kNeedsMergeName << "' without '" - << kFromMongosName - << "'"}; + << kFromMongosName << "'"}; } return request; diff --git a/src/mongo/db/pipeline/dependencies.cpp b/src/mongo/db/pipeline/dependencies.cpp index 6bfdc19bdce..1586a68f96b 100644 --- a/src/mongo/db/pipeline/dependencies.cpp +++ b/src/mongo/db/pipeline/dependencies.cpp @@ -282,4 +282,4 @@ Document documentHelper(const BSONObj& bson, const Document& neededFields, int n Document ParsedDeps::extractFields(const BSONObj& input) const { return documentHelper(input, _fields, _nFields); } -} +} // namespace mongo diff --git a/src/mongo/db/pipeline/dependencies.h b/src/mongo/db/pipeline/dependencies.h index b7e31a6237b..3487584a4a0 100644 --- a/src/mongo/db/pipeline/dependencies.h +++ b/src/mongo/db/pipeline/dependencies.h @@ -205,4 +205,4 @@ private: Document _fields; int _nFields; // Cache the number of top-level fields needed. }; -} +} // namespace mongo diff --git a/src/mongo/db/pipeline/dependencies_test.cpp b/src/mongo/db/pipeline/dependencies_test.cpp index 2fdf25c799b..6d2741a78e4 100644 --- a/src/mongo/db/pipeline/dependencies_test.cpp +++ b/src/mongo/db/pipeline/dependencies_test.cpp @@ -147,8 +147,7 @@ TEST(DependenciesToProjectionTest, ShouldAttemptToExcludeOtherFieldsIfOnlyTextSc deps.setNeedsMetadata(DepsTracker::MetadataType::TEXT_SCORE, true); ASSERT_BSONOBJ_EQ(deps.toProjection(), BSON(Document::metaFieldTextScore << metaTextScore << "_id" << 0 - << "$noFieldsNeeded" - << 1)); + << "$noFieldsNeeded" << 1)); } TEST(DependenciesToProjectionTest, diff --git a/src/mongo/db/pipeline/document.cpp b/src/mongo/db/pipeline/document.cpp index 9557d01a414..30ffa5a662d 100644 --- a/src/mongo/db/pipeline/document.cpp +++ b/src/mongo/db/pipeline/document.cpp @@ -406,8 +406,7 @@ BSONObjBuilder& operator<<(BSONObjBuilderValueStream& builder, const Document& d void Document::toBson(BSONObjBuilder* builder, size_t recursionLevel) const { uassert(ErrorCodes::Overflow, str::stream() << "cannot convert document to BSON because it exceeds the limit of " - << BSONDepth::getMaxAllowableDepth() - << " levels of nesting", + << BSONDepth::getMaxAllowableDepth() << " levels of nesting", recursionLevel <= BSONDepth::getMaxAllowableDepth()); for (DocumentStorageIterator it = storage().iterator(); !it.atEnd(); it.advance()) { @@ -646,4 +645,4 @@ Document Document::deserializeForSorter(BufReader& buf, const SorterDeserializeS return doc.freeze(); } -} +} // namespace mongo diff --git a/src/mongo/db/pipeline/document.h b/src/mongo/db/pipeline/document.h index d89389dbabe..4a67439dee0 100644 --- a/src/mongo/db/pipeline/document.h +++ b/src/mongo/db/pipeline/document.h @@ -717,4 +717,4 @@ inline MutableValue MutableValue::getField(Position pos) { inline MutableValue MutableValue::getField(StringData key) { return MutableDocument(*this).getField(key); } -} +} // namespace mongo diff --git a/src/mongo/db/pipeline/document_internal.h b/src/mongo/db/pipeline/document_internal.h index f5dc33e0ae4..c87ab70f43e 100644 --- a/src/mongo/db/pipeline/document_internal.h +++ b/src/mongo/db/pipeline/document_internal.h @@ -529,4 +529,4 @@ private: friend class DocumentStorageIterator; }; -} +} // namespace mongo diff --git a/src/mongo/db/pipeline/document_source_add_fields.cpp b/src/mongo/db/pipeline/document_source_add_fields.cpp index 8784a5ebf16..dd7550a0c1c 100644 --- a/src/mongo/db/pipeline/document_source_add_fields.cpp +++ b/src/mongo/db/pipeline/document_source_add_fields.cpp @@ -83,4 +83,4 @@ intrusive_ptr<DocumentSource> DocumentSourceAddFields::createFromBson( return DocumentSourceAddFields::create(elem.Obj(), expCtx, specifiedName); } -} +} // namespace mongo diff --git a/src/mongo/db/pipeline/document_source_bucket.cpp b/src/mongo/db/pipeline/document_source_bucket.cpp index e7efd9b202e..3245d21b742 100644 --- a/src/mongo/db/pipeline/document_source_bucket.cpp +++ b/src/mongo/db/pipeline/document_source_bucket.cpp @@ -37,8 +37,8 @@ namespace mongo { using boost::intrusive_ptr; -using std::vector; using std::list; +using std::vector; REGISTER_MULTI_STAGE_ALIAS(bucket, LiteParsedDocumentSourceDefault::parse, @@ -58,8 +58,7 @@ list<intrusive_ptr<DocumentSource>> DocumentSourceBucket::createFromBson( BSONElement elem, const intrusive_ptr<ExpressionContext>& pExpCtx) { uassert(40201, str::stream() << "Argument to $bucket stage must be an object, but found type: " - << typeName(elem.type()) - << ".", + << typeName(elem.type()) << ".", elem.type() == BSONType::Object); const BSONObj bucketObj = elem.embeddedObject(); @@ -86,15 +85,13 @@ list<intrusive_ptr<DocumentSource>> DocumentSourceBucket::createFromBson( uassert(40202, str::stream() << "The $bucket 'groupBy' field must be defined as a $-prefixed " "path or an expression, but found: " - << groupByField.toString(false, false) - << ".", + << groupByField.toString(false, false) << ".", groupByIsExpressionInObject || groupByIsPrefixedPath); } else if ("boundaries" == argName) { uassert( 40200, str::stream() << "The $bucket 'boundaries' field must be an array, but found type: " - << typeName(argument.type()) - << ".", + << typeName(argument.type()) << ".", argument.type() == BSONType::Array); for (auto&& boundaryElem : argument.embeddedObject()) { @@ -102,8 +99,7 @@ list<intrusive_ptr<DocumentSource>> DocumentSourceBucket::createFromBson( uassert(40191, str::stream() << "The $bucket 'boundaries' field must be an array of " "constant values, but found value: " - << boundaryElem.toString(false, false) - << ".", + << boundaryElem.toString(false, false) << ".", exprConst); boundaryValues.push_back(exprConst->getValue()); } @@ -111,8 +107,7 @@ list<intrusive_ptr<DocumentSource>> DocumentSourceBucket::createFromBson( uassert(40192, str::stream() << "The $bucket 'boundaries' field must have at least 2 values, but found " - << boundaryValues.size() - << " value(s).", + << boundaryValues.size() << " value(s).", boundaryValues.size() >= 2); // Make sure that the boundaries are unique, sorted in ascending order, and have the @@ -126,22 +121,14 @@ list<intrusive_ptr<DocumentSource>> DocumentSourceBucket::createFromBson( uassert(40193, str::stream() << "All values in the the 'boundaries' option to $bucket " "must have the same type. Found conflicting types " - << typeName(lower.getType()) - << " and " - << typeName(upper.getType()) - << ".", + << typeName(lower.getType()) << " and " + << typeName(upper.getType()) << ".", lowerCanonicalType == upperCanonicalType); uassert(40194, str::stream() << "The 'boundaries' option to $bucket must be sorted, but elements " - << i - 1 - << " and " - << i - << " are not in ascending order (" - << lower.toString() - << " is not less than " - << upper.toString() - << ").", + << i - 1 << " and " << i << " are not in ascending order (" + << lower.toString() << " is not less than " << upper.toString() << ").", pExpCtx->getValueComparator().evaluate(lower < upper)); } } else if ("default" == argName) { @@ -151,8 +138,7 @@ list<intrusive_ptr<DocumentSource>> DocumentSourceBucket::createFromBson( uassert(40195, str::stream() << "The $bucket 'default' field must be a constant expression, but found: " - << argument.toString(false, false) - << ".", + << argument.toString(false, false) << ".", exprConst); defaultValue = exprConst->getValue(); @@ -162,8 +148,7 @@ list<intrusive_ptr<DocumentSource>> DocumentSourceBucket::createFromBson( uassert( 40196, str::stream() << "The $bucket 'output' field must be an object, but found type: " - << typeName(argument.type()) - << ".", + << typeName(argument.type()) << ".", argument.type() == BSONType::Object); for (auto&& outputElem : argument.embeddedObject()) { diff --git a/src/mongo/db/pipeline/document_source_bucket_auto_test.cpp b/src/mongo/db/pipeline/document_source_bucket_auto_test.cpp index ecb3bf08007..f5a0600ae1b 100644 --- a/src/mongo/db/pipeline/document_source_bucket_auto_test.cpp +++ b/src/mongo/db/pipeline/document_source_bucket_auto_test.cpp @@ -51,10 +51,10 @@ namespace mongo { namespace { +using boost::intrusive_ptr; using std::deque; -using std::vector; using std::string; -using boost::intrusive_ptr; +using std::vector; class BucketAutoTests : public AggregationContextFixture { public: diff --git a/src/mongo/db/pipeline/document_source_change_stream.cpp b/src/mongo/db/pipeline/document_source_change_stream.cpp index 5e5861f2971..9050b9990dd 100644 --- a/src/mongo/db/pipeline/document_source_change_stream.cpp +++ b/src/mongo/db/pipeline/document_source_change_stream.cpp @@ -147,9 +147,7 @@ void DocumentSourceChangeStream::checkValueType(const Value v, BSONType expectedType) { uassert(40532, str::stream() << "Entry field \"" << filedName << "\" should be " - << typeName(expectedType) - << ", found: " - << typeName(v.getType()), + << typeName(expectedType) << ", found: " << typeName(v.getType()), (v.getType() == expectedType)); } @@ -402,11 +400,12 @@ list<intrusive_ptr<DocumentSource>> buildPipeline(const intrusive_ptr<Expression // There might not be a starting point if we're on mongos, otherwise we should either have a // 'resumeAfter' starting point, or should start from the latest majority committed operation. auto replCoord = repl::ReplicationCoordinator::get(expCtx->opCtx); - uassert(40573, - "The $changeStream stage is only supported on replica sets", - expCtx->inMongos || (replCoord && - replCoord->getReplicationMode() == - repl::ReplicationCoordinator::Mode::modeReplSet)); + uassert( + 40573, + "The $changeStream stage is only supported on replica sets", + expCtx->inMongos || + (replCoord && + replCoord->getReplicationMode() == repl::ReplicationCoordinator::Mode::modeReplSet)); if (!startFrom && !expCtx->inMongos) { startFrom = replCoord->getMyLastAppliedOpTime().getTimestamp(); } @@ -464,8 +463,7 @@ list<intrusive_ptr<DocumentSource>> DocumentSourceChangeStream::createFromBson( str::stream() << "unrecognized value for the 'fullDocument' option to the " "$changeStream stage. Expected \"default\" or " "\"updateLookup\", got \"" - << fullDocOption - << "\"", + << fullDocOption << "\"", fullDocOption == "updateLookup"_sd || fullDocOption == "default"_sd); const bool shouldLookupPostImage = (fullDocOption == "updateLookup"_sd); diff --git a/src/mongo/db/pipeline/document_source_change_stream_test.cpp b/src/mongo/db/pipeline/document_source_change_stream_test.cpp index 65a2ed55821..acc9d82e1f8 100644 --- a/src/mongo/db/pipeline/document_source_change_stream_test.cpp +++ b/src/mongo/db/pipeline/document_source_change_stream_test.cpp @@ -62,8 +62,8 @@ namespace mongo { namespace { using boost::intrusive_ptr; -using repl::OpTypeEnum; using repl::OplogEntry; +using repl::OpTypeEnum; using std::list; using std::string; using std::vector; @@ -423,8 +423,7 @@ TEST_F(ChangeStreamStageTest, ShouldRejectBothStartAtOperationTimeAndResumeAfter BSON(DSChangeStream::kStageName << BSON("resumeAfter" << makeResumeToken(kDefaultTs, testUuid(), BSON("x" << 2 << "_id" << 1)) - << "startAtOperationTime" - << kDefaultTs)) + << "startAtOperationTime" << kDefaultTs)) .firstElement(), expCtx), AssertionException, @@ -467,8 +466,7 @@ TEST_F(ChangeStreamStageTest, ShouldRejectBothStartAtOperationTimeAndStartAfterO BSON(DSChangeStream::kStageName << BSON("startAfter" << makeResumeToken(kDefaultTs, testUuid(), BSON("x" << 2 << "_id" << 1)) - << "startAtOperationTime" - << kDefaultTs)) + << "startAtOperationTime" << kDefaultTs)) .firstElement(), expCtx), AssertionException, @@ -629,7 +627,8 @@ TEST_F(ChangeStreamStageTest, TransformUpdateFields) { {DSChangeStream::kNamespaceField, D{{"db", nss.db()}, {"coll", nss.coll()}}}, {DSChangeStream::kDocumentKeyField, D{{"_id", 1}, {"x", 2}}}, { - "updateDescription", D{{"updatedFields", D{{"y", 1}}}, {"removedFields", vector<V>()}}, + "updateDescription", + D{{"updatedFields", D{{"y", 1}}}, {"removedFields", vector<V>()}}, }, }; checkTransformation(updateField, expectedUpdateField); @@ -655,7 +654,8 @@ TEST_F(ChangeStreamStageTest, TransformUpdateFieldsLegacyNoId) { {DSChangeStream::kNamespaceField, D{{"db", nss.db()}, {"coll", nss.coll()}}}, {DSChangeStream::kDocumentKeyField, D{{"x", 1}, {"y", 1}}}, { - "updateDescription", D{{"updatedFields", D{{"y", 1}}}, {"removedFields", vector<V>()}}, + "updateDescription", + D{{"updatedFields", D{{"y", 1}}}, {"removedFields", vector<V>()}}, }, }; checkTransformation(updateField, expectedUpdateField); @@ -679,7 +679,8 @@ TEST_F(ChangeStreamStageTest, TransformRemoveFields) { {DSChangeStream::kNamespaceField, D{{"db", nss.db()}, {"coll", nss.coll()}}}, {DSChangeStream::kDocumentKeyField, D{{{"_id", 1}, {"x", 2}}}}, { - "updateDescription", D{{"updatedFields", D{}}, {"removedFields", vector<V>{V("y"_sd)}}}, + "updateDescription", + D{{"updatedFields", D{}}, {"removedFields", vector<V>{V("y"_sd)}}}, }}; checkTransformation(removeField, expectedRemoveField); } @@ -1374,7 +1375,8 @@ TEST_F(ChangeStreamStageTest, ClusterTimeMatchesOplogEntry) { {DSChangeStream::kNamespaceField, D{{"db", nss.db()}, {"coll", nss.coll()}}}, {DSChangeStream::kDocumentKeyField, D{{"_id", 1}, {"x", 2}}}, { - "updateDescription", D{{"updatedFields", D{{"y", 1}}}, {"removedFields", vector<V>()}}, + "updateDescription", + D{{"updatedFields", D{{"y", 1}}}, {"removedFields", vector<V>()}}, }, }; checkTransformation(updateField, expectedUpdateField); @@ -1659,9 +1661,9 @@ TEST_F(ChangeStreamStageTest, ResumeAfterWithTokenFromInvalidateShouldFail) { ResumeTokenData::FromInvalidate::kFromInvalidate); ASSERT_THROWS_CODE(DSChangeStream::createFromBson( - BSON(DSChangeStream::kStageName << BSON( - "resumeAfter" << resumeTokenInvalidate << "startAtOperationTime" - << kDefaultTs)) + BSON(DSChangeStream::kStageName + << BSON("resumeAfter" << resumeTokenInvalidate + << "startAtOperationTime" << kDefaultTs)) .firstElement(), expCtx), AssertionException, @@ -1826,7 +1828,8 @@ TEST_F(ChangeStreamStageDBTest, TransformRemoveFields) { {DSChangeStream::kNamespaceField, D{{"db", nss.db()}, {"coll", nss.coll()}}}, {DSChangeStream::kDocumentKeyField, D{{{"_id", 1}, {"x", 2}}}}, { - "updateDescription", D{{"updatedFields", D{}}, {"removedFields", vector<V>{V("y"_sd)}}}, + "updateDescription", + D{{"updatedFields", D{}}, {"removedFields", vector<V>{V("y"_sd)}}}, }}; checkTransformation(removeField, expectedRemoveField); } diff --git a/src/mongo/db/pipeline/document_source_coll_stats.cpp b/src/mongo/db/pipeline/document_source_coll_stats.cpp index a02a6018231..bbf031b9f08 100644 --- a/src/mongo/db/pipeline/document_source_coll_stats.cpp +++ b/src/mongo/db/pipeline/document_source_coll_stats.cpp @@ -62,35 +62,28 @@ intrusive_ptr<DocumentSource> DocumentSourceCollStats::createFromBson( if ("latencyStats" == fieldName) { uassert(40167, str::stream() << "latencyStats argument must be an object, but got " << elem - << " of type " - << typeName(elem.type()), + << " of type " << typeName(elem.type()), elem.type() == BSONType::Object); if (!elem["histograms"].eoo()) { uassert(40305, str::stream() << "histograms option to latencyStats must be bool, got " - << elem - << "of type " - << typeName(elem.type()), + << elem << "of type " << typeName(elem.type()), elem["histograms"].isBoolean()); } } else if ("storageStats" == fieldName) { uassert(40279, str::stream() << "storageStats argument must be an object, but got " << elem - << " of type " - << typeName(elem.type()), + << " of type " << typeName(elem.type()), elem.type() == BSONType::Object); } else if ("count" == fieldName) { uassert(40480, str::stream() << "count argument must be an object, but got " << elem - << " of type " - << typeName(elem.type()), + << " of type " << typeName(elem.type()), elem.type() == BSONType::Object); } else if ("queryExecStats" == fieldName) { uassert(31141, str::stream() << "queryExecStats argument must be an empty object, but got " - << elem - << " of type " - << typeName(elem.type()), + << elem << " of type " << typeName(elem.type()), elem.type() == BSONType::Object); uassert(31170, str::stream() << "queryExecStats argument must be an empty object, but got " @@ -155,8 +148,8 @@ DocumentSource::GetNextResult DocumentSourceCollStats::getNext() { pExpCtx->opCtx, pExpCtx->ns, &builder); if (!status.isOK()) { uasserted(40481, - str::stream() << "Unable to retrieve count in $collStats stage: " - << status.reason()); + str::stream() + << "Unable to retrieve count in $collStats stage: " << status.reason()); } } diff --git a/src/mongo/db/pipeline/document_source_current_op.cpp b/src/mongo/db/pipeline/document_source_current_op.cpp index ba9c11d9e98..72225d8185f 100644 --- a/src/mongo/db/pipeline/document_source_current_op.cpp +++ b/src/mongo/db/pipeline/document_source_current_op.cpp @@ -155,9 +155,7 @@ DocumentSource::GetNextResult DocumentSourceCurrentOp::getNext() { if (fieldName == kOpIdFieldName) { uassert(ErrorCodes::TypeMismatch, str::stream() << "expected numeric opid for $currentOp response from '" - << _shardName - << "' but got: " - << typeName(elt.type()), + << _shardName << "' but got: " << typeName(elt.type()), elt.isNumber()); std::string shardOpID = (str::stream() << _shardName << ":" << elt.numberInt()); @@ -258,8 +256,8 @@ intrusive_ptr<DocumentSource> DocumentSourceCurrentOp::createFromBson( : BacktraceMode::kExcludeBacktrace); } else { uasserted(ErrorCodes::FailedToParse, - str::stream() << "Unrecognized option '" << fieldName - << "' in $currentOp stage."); + str::stream() + << "Unrecognized option '" << fieldName << "' in $currentOp stage."); } } diff --git a/src/mongo/db/pipeline/document_source_current_op.h b/src/mongo/db/pipeline/document_source_current_op.h index 537f4662fee..0e86973a009 100644 --- a/src/mongo/db/pipeline/document_source_current_op.h +++ b/src/mongo/db/pipeline/document_source_current_op.h @@ -83,8 +83,7 @@ public: uassert(ErrorCodes::InvalidOptions, str::stream() << "Aggregation stage " << kStageName << " cannot run with a " << "readConcern other than 'local', or in a multi-document " - << "transaction. Current readConcern: " - << readConcern.toString(), + << "transaction. Current readConcern: " << readConcern.toString(), readConcern.getLevel() == repl::ReadConcernLevel::kLocalReadConcern); } diff --git a/src/mongo/db/pipeline/document_source_cursor.cpp b/src/mongo/db/pipeline/document_source_cursor.cpp index 9c2d124f34d..22d263741c2 100644 --- a/src/mongo/db/pipeline/document_source_cursor.cpp +++ b/src/mongo/db/pipeline/document_source_cursor.cpp @@ -337,4 +337,4 @@ intrusive_ptr<DocumentSourceCursor> DocumentSourceCursor::create( new DocumentSourceCursor(collection, std::move(exec), pExpCtx, trackOplogTimestamp)); return source; } -} +} // namespace mongo diff --git a/src/mongo/db/pipeline/document_source_exchange.cpp b/src/mongo/db/pipeline/document_source_exchange.cpp index 96efa899d29..b45938c45d0 100644 --- a/src/mongo/db/pipeline/document_source_exchange.cpp +++ b/src/mongo/db/pipeline/document_source_exchange.cpp @@ -124,9 +124,7 @@ Exchange::Exchange(ExchangeSpec spec, std::unique_ptr<Pipeline, PipelineDeleter> uassert(50951, str::stream() << "Specified exchange buffer size (" << _maxBufferSize - << ") exceeds the maximum allowable amount (" - << kMaxBufferSize - << ").", + << ") exceeds the maximum allowable amount (" << kMaxBufferSize << ").", _maxBufferSize <= kMaxBufferSize); for (int idx = 0; idx < _spec.getConsumers(); ++idx) { @@ -205,8 +203,7 @@ std::vector<size_t> Exchange::extractConsumerIds( uassert(50950, str::stream() << "Specified number of exchange consumers (" << nConsumers - << ") exceeds the maximum allowable amount (" - << kMaxNumberConsumers + << ") exceeds the maximum allowable amount (" << kMaxNumberConsumers << ").", nConsumers <= kMaxNumberConsumers); @@ -415,8 +412,9 @@ size_t Exchange::getTargetConsumer(const Document& input) { } if (elem.type() == BSONType::String && elem.str() == "hashed") { - kb << "" << BSONElementHasher::hash64(BSON("" << value).firstElement(), - BSONElementHasher::DEFAULT_HASH_SEED); + kb << "" + << BSONElementHasher::hash64(BSON("" << value).firstElement(), + BSONElementHasher::DEFAULT_HASH_SEED); } else { kb << "" << value; } diff --git a/src/mongo/db/pipeline/document_source_exchange_test.cpp b/src/mongo/db/pipeline/document_source_exchange_test.cpp index cd66171a246..ef4f626e7b6 100644 --- a/src/mongo/db/pipeline/document_source_exchange_test.cpp +++ b/src/mongo/db/pipeline/document_source_exchange_test.cpp @@ -556,7 +556,6 @@ TEST_F(DocumentSourceExchangeTest, RandomExchangeNConsumerResourceYielding) { ThreadInfo* threadInfo = &threads[id]; auto handle = _executor->scheduleWork( [threadInfo, &processedDocs](const executor::TaskExecutor::CallbackArgs& cb) { - DocumentSourceExchange* exchange = threadInfo->documentSourceExchange.get(); const auto getNext = [exchange, threadInfo]() { // Will acquire 'artificalGlobalMutex'. Within getNext() it will be released and @@ -652,8 +651,7 @@ TEST_F(DocumentSourceExchangeTest, RangeRandomHashExchangeNConsumer) { TEST_F(DocumentSourceExchangeTest, RejectNoConsumers) { BSONObj spec = BSON("policy" << "broadcast" - << "consumers" - << 0); + << "consumers" << 0); ASSERT_THROWS_CODE( Exchange(parseSpec(spec), unittest::assertGet(Pipeline::create({}, getExpCtx()))), AssertionException, @@ -663,10 +661,7 @@ TEST_F(DocumentSourceExchangeTest, RejectNoConsumers) { TEST_F(DocumentSourceExchangeTest, RejectInvalidKey) { BSONObj spec = BSON("policy" << "broadcast" - << "consumers" - << 1 - << "key" - << BSON("a" << 2)); + << "consumers" << 1 << "key" << BSON("a" << 2)); ASSERT_THROWS_CODE( Exchange(parseSpec(spec), unittest::assertGet(Pipeline::create({}, getExpCtx()))), AssertionException, @@ -676,9 +671,7 @@ TEST_F(DocumentSourceExchangeTest, RejectInvalidKey) { TEST_F(DocumentSourceExchangeTest, RejectInvalidKeyHashExpected) { BSONObj spec = BSON("policy" << "broadcast" - << "consumers" - << 1 - << "key" + << "consumers" << 1 << "key" << BSON("a" << "nothash")); ASSERT_THROWS_CODE( @@ -690,10 +683,7 @@ TEST_F(DocumentSourceExchangeTest, RejectInvalidKeyHashExpected) { TEST_F(DocumentSourceExchangeTest, RejectInvalidKeyWrongType) { BSONObj spec = BSON("policy" << "broadcast" - << "consumers" - << 1 - << "key" - << BSON("a" << true)); + << "consumers" << 1 << "key" << BSON("a" << true)); ASSERT_THROWS_CODE( Exchange(parseSpec(spec), unittest::assertGet(Pipeline::create({}, getExpCtx()))), AssertionException, @@ -703,10 +693,7 @@ TEST_F(DocumentSourceExchangeTest, RejectInvalidKeyWrongType) { TEST_F(DocumentSourceExchangeTest, RejectInvalidKeyEmpty) { BSONObj spec = BSON("policy" << "broadcast" - << "consumers" - << 1 - << "key" - << BSON("" << 1)); + << "consumers" << 1 << "key" << BSON("" << 1)); ASSERT_THROWS_CODE( Exchange(parseSpec(spec), unittest::assertGet(Pipeline::create({}, getExpCtx()))), AssertionException, @@ -716,13 +703,8 @@ TEST_F(DocumentSourceExchangeTest, RejectInvalidKeyEmpty) { TEST_F(DocumentSourceExchangeTest, RejectInvalidBoundaries) { BSONObj spec = BSON("policy" << "keyRange" - << "consumers" - << 1 - << "key" - << BSON("a" << 1) - << "boundaries" - << BSON_ARRAY(BSON("a" << MAXKEY) << BSON("a" << MINKEY)) - << "consumerIds" + << "consumers" << 1 << "key" << BSON("a" << 1) << "boundaries" + << BSON_ARRAY(BSON("a" << MAXKEY) << BSON("a" << MINKEY)) << "consumerIds" << BSON_ARRAY(0)); ASSERT_THROWS_CODE( Exchange(parseSpec(spec), unittest::assertGet(Pipeline::create({}, getExpCtx()))), @@ -733,13 +715,8 @@ TEST_F(DocumentSourceExchangeTest, RejectInvalidBoundaries) { TEST_F(DocumentSourceExchangeTest, RejectInvalidBoundariesMissingMin) { BSONObj spec = BSON("policy" << "keyRange" - << "consumers" - << 1 - << "key" - << BSON("a" << 1) - << "boundaries" - << BSON_ARRAY(BSON("a" << 0) << BSON("a" << MAXKEY)) - << "consumerIds" + << "consumers" << 1 << "key" << BSON("a" << 1) << "boundaries" + << BSON_ARRAY(BSON("a" << 0) << BSON("a" << MAXKEY)) << "consumerIds" << BSON_ARRAY(0)); ASSERT_THROWS_CODE( Exchange(parseSpec(spec), unittest::assertGet(Pipeline::create({}, getExpCtx()))), @@ -750,13 +727,8 @@ TEST_F(DocumentSourceExchangeTest, RejectInvalidBoundariesMissingMin) { TEST_F(DocumentSourceExchangeTest, RejectInvalidBoundariesMissingMax) { BSONObj spec = BSON("policy" << "keyRange" - << "consumers" - << 1 - << "key" - << BSON("a" << 1) - << "boundaries" - << BSON_ARRAY(BSON("a" << MINKEY) << BSON("a" << 0)) - << "consumerIds" + << "consumers" << 1 << "key" << BSON("a" << 1) << "boundaries" + << BSON_ARRAY(BSON("a" << MINKEY) << BSON("a" << 0)) << "consumerIds" << BSON_ARRAY(0)); ASSERT_THROWS_CODE( Exchange(parseSpec(spec), unittest::assertGet(Pipeline::create({}, getExpCtx()))), @@ -767,13 +739,8 @@ TEST_F(DocumentSourceExchangeTest, RejectInvalidBoundariesMissingMax) { TEST_F(DocumentSourceExchangeTest, RejectInvalidBoundariesAndConsumerIds) { BSONObj spec = BSON("policy" << "keyRange" - << "consumers" - << 2 - << "key" - << BSON("a" << 1) - << "boundaries" - << BSON_ARRAY(BSON("a" << MINKEY) << BSON("a" << MAXKEY)) - << "consumerIds" + << "consumers" << 2 << "key" << BSON("a" << 1) << "boundaries" + << BSON_ARRAY(BSON("a" << MINKEY) << BSON("a" << MAXKEY)) << "consumerIds" << BSON_ARRAY(0 << 1)); ASSERT_THROWS_CODE( Exchange(parseSpec(spec), unittest::assertGet(Pipeline::create({}, getExpCtx()))), @@ -784,13 +751,8 @@ TEST_F(DocumentSourceExchangeTest, RejectInvalidBoundariesAndConsumerIds) { TEST_F(DocumentSourceExchangeTest, RejectInvalidPolicyBoundaries) { BSONObj spec = BSON("policy" << "roundrobin" - << "consumers" - << 1 - << "key" - << BSON("a" << 1) - << "boundaries" - << BSON_ARRAY(BSON("a" << MINKEY) << BSON("a" << MAXKEY)) - << "consumerIds" + << "consumers" << 1 << "key" << BSON("a" << 1) << "boundaries" + << BSON_ARRAY(BSON("a" << MINKEY) << BSON("a" << MAXKEY)) << "consumerIds" << BSON_ARRAY(0)); ASSERT_THROWS_CODE( Exchange(parseSpec(spec), unittest::assertGet(Pipeline::create({}, getExpCtx()))), @@ -801,13 +763,8 @@ TEST_F(DocumentSourceExchangeTest, RejectInvalidPolicyBoundaries) { TEST_F(DocumentSourceExchangeTest, RejectInvalidConsumerIds) { BSONObj spec = BSON("policy" << "keyRange" - << "consumers" - << 1 - << "key" - << BSON("a" << 1) - << "boundaries" - << BSON_ARRAY(BSON("a" << MINKEY) << BSON("a" << MAXKEY)) - << "consumerIds" + << "consumers" << 1 << "key" << BSON("a" << 1) << "boundaries" + << BSON_ARRAY(BSON("a" << MINKEY) << BSON("a" << MAXKEY)) << "consumerIds" << BSON_ARRAY(1)); ASSERT_THROWS_CODE( Exchange(parseSpec(spec), unittest::assertGet(Pipeline::create({}, getExpCtx()))), @@ -818,11 +775,8 @@ TEST_F(DocumentSourceExchangeTest, RejectInvalidConsumerIds) { TEST_F(DocumentSourceExchangeTest, RejectInvalidMissingKeys) { BSONObj spec = BSON("policy" << "keyRange" - << "consumers" - << 1 - << "boundaries" - << BSON_ARRAY(BSON("a" << MINKEY) << BSON("a" << MAXKEY)) - << "consumerIds" + << "consumers" << 1 << "boundaries" + << BSON_ARRAY(BSON("a" << MINKEY) << BSON("a" << MAXKEY)) << "consumerIds" << BSON_ARRAY(0)); ASSERT_THROWS_CODE( Exchange(parseSpec(spec), unittest::assertGet(Pipeline::create({}, getExpCtx()))), diff --git a/src/mongo/db/pipeline/document_source_facet.cpp b/src/mongo/db/pipeline/document_source_facet.cpp index 95214ab1560..16d14e1edf4 100644 --- a/src/mongo/db/pipeline/document_source_facet.cpp +++ b/src/mongo/db/pipeline/document_source_facet.cpp @@ -93,11 +93,8 @@ vector<pair<string, vector<BSONObj>>> extractRawPipelines(const BSONElement& ele for (auto&& subPipeElem : facetElem.Obj()) { uassert(40171, str::stream() << "elements of arrays in $facet spec must be non-empty objects, " - << facetName - << " argument contained an element of type " - << typeName(subPipeElem.type()) - << ": " - << subPipeElem, + << facetName << " argument contained an element of type " + << typeName(subPipeElem.type()) << ": " << subPipeElem, subPipeElem.type() == BSONType::Object); rawPipeline.push_back(subPipeElem.embeddedObject()); } @@ -350,8 +347,7 @@ intrusive_ptr<DocumentSource> DocumentSourceFacet::createFromBson( } uassert(ErrorCodes::IllegalOperation, str::stream() << "$facet pipeline '" << *needsMongoS - << "' must run on mongoS, but '" - << *needsShard + << "' must run on mongoS, but '" << *needsShard << "' requires a shard", !(needsShard && needsMongoS)); diff --git a/src/mongo/db/pipeline/document_source_graph_lookup.cpp b/src/mongo/db/pipeline/document_source_graph_lookup.cpp index 471f93f04f0..c96ac4b4114 100644 --- a/src/mongo/db/pipeline/document_source_graph_lookup.cpp +++ b/src/mongo/db/pipeline/document_source_graph_lookup.cpp @@ -211,8 +211,7 @@ void DocumentSourceGraphLookUp::doBreadthFirstSearch() { while (auto next = pipeline->getNext()) { uassert(40271, str::stream() - << "Documents in the '" - << _from.ns() + << "Documents in the '" << _from.ns() << "' namespace must contain an _id for de-duplication in $graphLookup", !(*next)["_id"].missing()); @@ -392,10 +391,8 @@ void DocumentSourceGraphLookUp::serializeToArray( std::vector<Value>& array, boost::optional<ExplainOptions::Verbosity> explain) const { // Serialize default options. MutableDocument spec(DOC("from" << _from.coll() << "as" << _as.fullPath() << "connectToField" - << _connectToField.fullPath() - << "connectFromField" - << _connectFromField.fullPath() - << "startWith" + << _connectToField.fullPath() << "connectFromField" + << _connectFromField.fullPath() << "startWith" << _startWith->serialize(false))); // depthField is optional; serialize it if it was specified. @@ -414,10 +411,10 @@ void DocumentSourceGraphLookUp::serializeToArray( // If we are explaining, include an absorbed $unwind inside the $graphLookup specification. if (_unwind && explain) { const boost::optional<FieldPath> indexPath = (*_unwind)->indexPath(); - spec["unwinding"] = Value(DOC("preserveNullAndEmptyArrays" - << (*_unwind)->preserveNullAndEmptyArrays() - << "includeArrayIndex" - << (indexPath ? Value((*indexPath).fullPath()) : Value()))); + spec["unwinding"] = + Value(DOC("preserveNullAndEmptyArrays" + << (*_unwind)->preserveNullAndEmptyArrays() << "includeArrayIndex" + << (indexPath ? Value((*indexPath).fullPath()) : Value()))); } array.push_back(Value(DOC(getSourceName() << spec.freeze()))); @@ -550,8 +547,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); } @@ -567,8 +564,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_graph_lookup_test.cpp b/src/mongo/db/pipeline/document_source_graph_lookup_test.cpp index 0e402da49a1..27b364ca2cd 100644 --- a/src/mongo/db/pipeline/document_source_graph_lookup_test.cpp +++ b/src/mongo/db/pipeline/document_source_graph_lookup_test.cpp @@ -247,10 +247,8 @@ TEST_F(DocumentSourceGraphLookUpTest, ASSERT(next.isEOF()); } else { FAIL(str::stream() << "Expected either [ " << to0from1.toString() << " ] or [ " - << to0from2.toString() - << " ] but found [ " - << next.getDocument().toString() - << " ]"); + << to0from2.toString() << " ] but found [ " + << next.getDocument().toString() << " ]"); } } diff --git a/src/mongo/db/pipeline/document_source_group_test.cpp b/src/mongo/db/pipeline/document_source_group_test.cpp index 998255cfee8..42411f52660 100644 --- a/src/mongo/db/pipeline/document_source_group_test.cpp +++ b/src/mongo/db/pipeline/document_source_group_test.cpp @@ -215,10 +215,10 @@ TEST_F(DocumentSourceGroupTest, ShouldReportMultipleFieldGroupKeysAsARename) { std::vector<std::pair<std::string, boost::intrusive_ptr<Expression>&>> expressions; auto doc = std::vector<std::pair<std::string, boost::intrusive_ptr<Expression>>>{{"x", x}, {"y", y}}; - for (auto & [ unused, expression ] : doc) + for (auto& [unused, expression] : doc) children.push_back(std::move(expression)); std::vector<boost::intrusive_ptr<Expression>>::size_type index = 0; - for (auto & [ fieldName, unused ] : doc) { + for (auto& [fieldName, unused] : doc) { expressions.emplace_back(fieldName, children[index]); ++index; } @@ -523,8 +523,9 @@ class AggregateObjectExpression : public ExpressionBase { return BSON("a" << 6); } BSONObj spec() { - return BSON("_id" << 0 << "z" << BSON("$first" << BSON("x" - << "$a"))); + return BSON("_id" << 0 << "z" + << BSON("$first" << BSON("x" + << "$a"))); } BSONObj expected() { return BSON("_id" << 0 << "z" << BSON("x" << 6)); @@ -537,8 +538,9 @@ class AggregateOperatorExpression : public ExpressionBase { return BSON("a" << 6); } BSONObj spec() { - return BSON("_id" << 0 << "z" << BSON("$first" - << "$a")); + return BSON("_id" << 0 << "z" + << BSON("$first" + << "$a")); } BSONObj expected() { return BSON("_id" << 0 << "z" << 6); @@ -635,8 +637,9 @@ class SingleDocument : public CheckResultsBase { return {DOC("a" << 1)}; } virtual BSONObj groupSpec() { - return BSON("_id" << 0 << "a" << BSON("$sum" - << "$a")); + return BSON("_id" << 0 << "a" + << BSON("$sum" + << "$a")); } virtual string expectedResultSetString() { return "[{_id:0,a:1}]"; @@ -649,8 +652,9 @@ class TwoValuesSingleKey : public CheckResultsBase { return {DOC("a" << 1), DOC("a" << 2)}; } virtual BSONObj groupSpec() { - return BSON("_id" << 0 << "a" << BSON("$push" - << "$a")); + return BSON("_id" << 0 << "a" + << BSON("$push" + << "$a")); } virtual string expectedResultSetString() { return "[{_id:0,a:[1,2]}]"; @@ -708,8 +712,7 @@ class FourValuesTwoKeysTwoAccumulators : public CheckResultsBase { << "list" << BSON("$push" << "$a") - << "sum" - << BSON("$sum" << BSON("$divide" << BSON_ARRAY("$a" << 2)))); + << "sum" << BSON("$sum" << BSON("$divide" << BSON_ARRAY("$a" << 2)))); } virtual string expectedResultSetString() { return "[{_id:0,list:[1,3],sum:2},{_id:1,list:[2,4],sum:3}]"; @@ -770,8 +773,9 @@ class UndefinedAccumulatorValue : public CheckResultsBase { return {Document()}; } virtual BSONObj groupSpec() { - return BSON("_id" << 0 << "first" << BSON("$first" - << "$missing")); + return BSON("_id" << 0 << "first" + << BSON("$first" + << "$missing")); } virtual string expectedResultSetString() { return "[{_id:0, first:null}]"; diff --git a/src/mongo/db/pipeline/document_source_index_stats.cpp b/src/mongo/db/pipeline/document_source_index_stats.cpp index 23343699114..c24671624f6 100644 --- a/src/mongo/db/pipeline/document_source_index_stats.cpp +++ b/src/mongo/db/pipeline/document_source_index_stats.cpp @@ -85,4 +85,4 @@ Value DocumentSourceIndexStats::serialize( boost::optional<ExplainOptions::Verbosity> explain) const { return Value(DOC(getSourceName() << Document())); } -} +} // namespace mongo diff --git a/src/mongo/db/pipeline/document_source_internal_inhibit_optimization.cpp b/src/mongo/db/pipeline/document_source_internal_inhibit_optimization.cpp index b4dd8a61adf..13a0c173424 100644 --- a/src/mongo/db/pipeline/document_source_internal_inhibit_optimization.cpp +++ b/src/mongo/db/pipeline/document_source_internal_inhibit_optimization.cpp @@ -65,4 +65,4 @@ Value DocumentSourceInternalInhibitOptimization::serialize( return Value(Document{{getSourceName(), Value{Document{}}}}); } -} // namesace mongo +} // namespace mongo diff --git a/src/mongo/db/pipeline/document_source_internal_inhibit_optimization.h b/src/mongo/db/pipeline/document_source_internal_inhibit_optimization.h index 86b919fb848..75f3e637a7d 100644 --- a/src/mongo/db/pipeline/document_source_internal_inhibit_optimization.h +++ b/src/mongo/db/pipeline/document_source_internal_inhibit_optimization.h @@ -73,4 +73,4 @@ private: Value serialize(boost::optional<ExplainOptions::Verbosity> explain = boost::none) const final; }; -} // namesace mongo +} // namespace mongo diff --git a/src/mongo/db/pipeline/document_source_internal_split_pipeline.cpp b/src/mongo/db/pipeline/document_source_internal_split_pipeline.cpp index 3b7eb1f86a8..0eb5a85f0d0 100644 --- a/src/mongo/db/pipeline/document_source_internal_split_pipeline.cpp +++ b/src/mongo/db/pipeline/document_source_internal_split_pipeline.cpp @@ -69,14 +69,12 @@ boost::intrusive_ptr<DocumentSource> DocumentSourceInternalSplitPipeline::create } else { uasserted(ErrorCodes::BadValue, str::stream() << "unrecognized field while parsing mergeType: '" - << elt.fieldNameStringData() - << "'"); + << elt.fieldNameStringData() << "'"); } } else { uasserted(ErrorCodes::BadValue, str::stream() << "unrecognized field while parsing $_internalSplitPipeline: '" - << elt.fieldNameStringData() - << "'"); + << elt.fieldNameStringData() << "'"); } } @@ -120,4 +118,4 @@ Value DocumentSourceInternalSplitPipeline::serialize( mergeTypeString.empty() ? Value() : Value(mergeTypeString)}}}}}); } -} // namesace mongo +} // namespace mongo diff --git a/src/mongo/db/pipeline/document_source_internal_split_pipeline.h b/src/mongo/db/pipeline/document_source_internal_split_pipeline.h index 9d58b7e3fd5..d2d4b14e685 100644 --- a/src/mongo/db/pipeline/document_source_internal_split_pipeline.h +++ b/src/mongo/db/pipeline/document_source_internal_split_pipeline.h @@ -85,4 +85,4 @@ private: HostTypeRequirement _mergeType = HostTypeRequirement::kNone; }; -} // namesace mongo +} // namespace mongo diff --git a/src/mongo/db/pipeline/document_source_list_cached_and_active_users.cpp b/src/mongo/db/pipeline/document_source_list_cached_and_active_users.cpp index 3c189798db9..9195d0aa0aa 100644 --- a/src/mongo/db/pipeline/document_source_list_cached_and_active_users.cpp +++ b/src/mongo/db/pipeline/document_source_list_cached_and_active_users.cpp @@ -51,8 +51,7 @@ DocumentSource::GetNextResult DocumentSourceListCachedAndActiveUsers::getNext() const auto info = std::move(_users.back()); _users.pop_back(); return Document(BSON("username" << info.userName.getUser() << "db" << info.userName.getDB() - << "active" - << info.active)); + << "active" << info.active)); } return GetNextResult::makeEOF(); diff --git a/src/mongo/db/pipeline/document_source_list_cached_and_active_users.h b/src/mongo/db/pipeline/document_source_list_cached_and_active_users.h index 3a9efde6261..51dea36c162 100644 --- a/src/mongo/db/pipeline/document_source_list_cached_and_active_users.h +++ b/src/mongo/db/pipeline/document_source_list_cached_and_active_users.h @@ -73,8 +73,7 @@ public: uassert(ErrorCodes::InvalidOptions, str::stream() << "Aggregation stage " << kStageName << " cannot run with a " << "readConcern other than 'local', or in a multi-document " - << "transaction. Current readConcern: " - << readConcern.toString(), + << "transaction. Current readConcern: " << readConcern.toString(), readConcern.getLevel() == repl::ReadConcernLevel::kLocalReadConcern); } }; diff --git a/src/mongo/db/pipeline/document_source_list_local_sessions.h b/src/mongo/db/pipeline/document_source_list_local_sessions.h index 853ea2034e5..74403ac9d45 100644 --- a/src/mongo/db/pipeline/document_source_list_local_sessions.h +++ b/src/mongo/db/pipeline/document_source_list_local_sessions.h @@ -84,8 +84,7 @@ public: uassert(ErrorCodes::InvalidOptions, str::stream() << "Aggregation stage " << kStageName << " cannot run with a " << "readConcern other than 'local', or in a multi-document " - << "transaction. Current readConcern: " - << readConcern.toString(), + << "transaction. Current readConcern: " << readConcern.toString(), readConcern.getLevel() == repl::ReadConcernLevel::kLocalReadConcern); } diff --git a/src/mongo/db/pipeline/document_source_lookup.cpp b/src/mongo/db/pipeline/document_source_lookup.cpp index b2a81168a77..f14b3db0394 100644 --- a/src/mongo/db/pipeline/document_source_lookup.cpp +++ b/src/mongo/db/pipeline/document_source_lookup.cpp @@ -261,8 +261,7 @@ DocumentSource::GetNextResult DocumentSourceLookUp::getNext() { objsize += result->getApproximateSize(); uassert(4568, str::stream() << "Total size of documents in " << _fromNs.coll() - << " matching pipeline's $lookup stage exceeds " - << maxBytes + << " matching pipeline's $lookup stage exceeds " << maxBytes << " bytes", objsize <= maxBytes); @@ -687,8 +686,7 @@ void DocumentSourceLookUp::serializeToArray( const boost::optional<FieldPath> indexPath = _unwindSrc->indexPath(); output[getSourceName()]["unwinding"] = Value(DOC("preserveNullAndEmptyArrays" - << _unwindSrc->preserveNullAndEmptyArrays() - << "includeArrayIndex" + << _unwindSrc->preserveNullAndEmptyArrays() << "includeArrayIndex" << (indexPath ? Value(indexPath->fullPath()) : Value()))); } @@ -810,8 +808,7 @@ intrusive_ptr<DocumentSource> DocumentSourceLookUp::createFromBson( if (argName == "let") { uassert(ErrorCodes::FailedToParse, str::stream() << "$lookup argument '" << argument - << "' must be an object, is type " - << argument.type(), + << "' must be an object, is type " << argument.type(), argument.type() == BSONType::Object); letVariables = argument.Obj(); hasLet = true; @@ -820,9 +817,7 @@ intrusive_ptr<DocumentSource> DocumentSourceLookUp::createFromBson( uassert(ErrorCodes::FailedToParse, str::stream() << "$lookup argument '" << argName << "' must be a string, found " - << argument - << ": " - << argument.type(), + << argument << ": " << argument.type(), argument.type() == BSONType::String); if (argName == "from") { diff --git a/src/mongo/db/pipeline/document_source_lookup_change_post_image.cpp b/src/mongo/db/pipeline/document_source_lookup_change_post_image.cpp index 327fdf6f703..cb24b7b9ae8 100644 --- a/src/mongo/db/pipeline/document_source_lookup_change_post_image.cpp +++ b/src/mongo/db/pipeline/document_source_lookup_change_post_image.cpp @@ -43,14 +43,9 @@ Value assertFieldHasType(const Document& fullDoc, StringData fieldName, BSONType auto val = fullDoc[fieldName]; uassert(40578, str::stream() << "failed to look up post image after change: expected \"" << fieldName - << "\" field to have type " - << typeName(expectedType) - << ", instead found type " - << typeName(val.getType()) - << ": " - << val.toString() - << ", full object: " - << fullDoc.toString(), + << "\" field to have type " << typeName(expectedType) + << ", instead found type " << typeName(val.getType()) << ": " + << val.toString() << ", full object: " << fullDoc.toString(), val.getType() == expectedType); return val; } @@ -88,8 +83,7 @@ NamespaceString DocumentSourceLookupChangePostImage::assertValidNamespace( // lookup into any namespace. uassert(40579, str::stream() << "unexpected namespace during post image lookup: " << nss.ns() - << ", expected " - << pExpCtx->ns.ns(), + << ", expected " << pExpCtx->ns.ns(), nss == pExpCtx->ns || (pExpCtx->isClusterAggregation() || pExpCtx->isDBAggregation(nss.db()))); @@ -112,8 +106,7 @@ Value DocumentSourceLookupChangePostImage::lookupPostImage(const Document& updat const auto readConcern = pExpCtx->inMongos ? boost::optional<BSONObj>(BSON("level" << "majority" - << "afterClusterTime" - << resumeToken.getData().clusterTime)) + << "afterClusterTime" << resumeToken.getData().clusterTime)) : boost::none; diff --git a/src/mongo/db/pipeline/document_source_lookup_test.cpp b/src/mongo/db/pipeline/document_source_lookup_test.cpp index 24d640ea85f..38b17213eaf 100644 --- a/src/mongo/db/pipeline/document_source_lookup_test.cpp +++ b/src/mongo/db/pipeline/document_source_lookup_test.cpp @@ -95,9 +95,7 @@ TEST_F(DocumentSourceLookUpTest, PreservesParentPipelineLetVariables) { auto docSource = DocumentSourceLookUp::createFromBson( BSON("$lookup" << BSON("from" << "coll" - << "pipeline" - << BSON_ARRAY(BSON("$match" << BSON("x" << 1))) - << "as" + << "pipeline" << BSON_ARRAY(BSON("$match" << BSON("x" << 1))) << "as" << "as")) .firstElement(), expCtx); @@ -117,9 +115,7 @@ TEST_F(DocumentSourceLookUpTest, AcceptsPipelineSyntax) { auto docSource = DocumentSourceLookUp::createFromBson( BSON("$lookup" << BSON("from" << "coll" - << "pipeline" - << BSON_ARRAY(BSON("$match" << BSON("x" << 1))) - << "as" + << "pipeline" << BSON_ARRAY(BSON("$match" << BSON("x" << 1))) << "as" << "as")) .firstElement(), expCtx); @@ -229,17 +225,17 @@ TEST_F(DocumentSourceLookUpTest, RejectLookupWhenDepthLimitIsExceeded) { expCtx->subPipelineDepth = DocumentSourceLookUp::kMaxSubPipelineDepth; - ASSERT_THROWS_CODE(DocumentSourceLookUp::createFromBson( - BSON("$lookup" << BSON("from" - << "coll" - << "pipeline" - << BSON_ARRAY(BSON("$match" << BSON("x" << 1))) - << "as" - << "as")) - .firstElement(), - expCtx), - AssertionException, - ErrorCodes::MaxSubPipelineDepthExceeded); + ASSERT_THROWS_CODE( + DocumentSourceLookUp::createFromBson( + BSON("$lookup" << BSON("from" + << "coll" + << "pipeline" << BSON_ARRAY(BSON("$match" << BSON("x" << 1))) + << "as" + << "as")) + .firstElement(), + expCtx), + AssertionException, + ErrorCodes::MaxSubPipelineDepthExceeded); } TEST_F(ReplDocumentSourceLookUpTest, RejectsPipelineWithChangeStreamStage) { @@ -286,8 +282,7 @@ TEST_F(DocumentSourceLookUpTest, RejectsLocalFieldForeignFieldWhenPipelineIsSpec auto lookupStage = DocumentSourceLookUp::createFromBson( BSON("$lookup" << BSON("from" << "coll" - << "pipeline" - << BSON_ARRAY(BSON("$match" << BSON("x" << 1))) + << "pipeline" << BSON_ARRAY(BSON("$match" << BSON("x" << 1))) << "localField" << "a" << "foreignField" @@ -298,8 +293,7 @@ TEST_F(DocumentSourceLookUpTest, RejectsLocalFieldForeignFieldWhenPipelineIsSpec expCtx); FAIL(str::stream() - << "Expected creation of the " - << lookupStage->getSourceName() + << "Expected creation of the " << lookupStage->getSourceName() << " stage to uassert on mix of localField/foreignField and pipeline options"); } catch (const AssertionException& ex) { ASSERT_EQ(ErrorCodes::FailedToParse, ex.code()); @@ -335,50 +329,50 @@ TEST_F(DocumentSourceLookUpTest, RejectsInvalidLetVariableName) { expCtx->setResolvedNamespaces(StringMap<ExpressionContext::ResolvedNamespace>{ {fromNs.coll().toString(), {fromNs, std::vector<BSONObj>()}}}); - ASSERT_THROWS_CODE(DocumentSourceLookUp::createFromBson( - BSON("$lookup" << BSON("from" - << "coll" - << "let" - << BSON("" // Empty variable name. - << "$a") - << "pipeline" - << BSON_ARRAY(BSON("$match" << BSON("x" << 1))) - << "as" - << "as")) - .firstElement(), - expCtx), - AssertionException, - 16866); - - ASSERT_THROWS_CODE(DocumentSourceLookUp::createFromBson( - BSON("$lookup" << BSON("from" - << "coll" - << "let" - << BSON("^invalidFirstChar" - << "$a") - << "pipeline" - << BSON_ARRAY(BSON("$match" << BSON("x" << 1))) - << "as" - << "as")) - .firstElement(), - expCtx), - AssertionException, - 16867); - - ASSERT_THROWS_CODE(DocumentSourceLookUp::createFromBson( - BSON("$lookup" << BSON("from" - << "coll" - << "let" - << BSON("contains.invalidChar" - << "$a") - << "pipeline" - << BSON_ARRAY(BSON("$match" << BSON("x" << 1))) - << "as" - << "as")) - .firstElement(), - expCtx), - AssertionException, - 16868); + ASSERT_THROWS_CODE( + DocumentSourceLookUp::createFromBson( + BSON("$lookup" << BSON("from" + << "coll" + << "let" + << BSON("" // Empty variable name. + << "$a") + << "pipeline" << BSON_ARRAY(BSON("$match" << BSON("x" << 1))) + << "as" + << "as")) + .firstElement(), + expCtx), + AssertionException, + 16866); + + ASSERT_THROWS_CODE( + DocumentSourceLookUp::createFromBson( + BSON("$lookup" << BSON("from" + << "coll" + << "let" + << BSON("^invalidFirstChar" + << "$a") + << "pipeline" << BSON_ARRAY(BSON("$match" << BSON("x" << 1))) + << "as" + << "as")) + .firstElement(), + expCtx), + AssertionException, + 16867); + + ASSERT_THROWS_CODE( + DocumentSourceLookUp::createFromBson( + BSON("$lookup" << BSON("from" + << "coll" + << "let" + << BSON("contains.invalidChar" + << "$a") + << "pipeline" << BSON_ARRAY(BSON("$match" << BSON("x" << 1))) + << "as" + << "as")) + .firstElement(), + expCtx), + AssertionException, + 16868); } TEST_F(DocumentSourceLookUpTest, ShouldBeAbleToReParseSerializedStage) { @@ -393,9 +387,7 @@ TEST_F(DocumentSourceLookUpTest, ShouldBeAbleToReParseSerializedStage) { << "let" << BSON("local_x" << "$x") - << "pipeline" - << BSON_ARRAY(BSON("$match" << BSON("x" << 1))) - << "as" + << "pipeline" << BSON_ARRAY(BSON("$match" << BSON("x" << 1))) << "as" << "as")) .firstElement(), expCtx); @@ -729,8 +721,7 @@ TEST_F(DocumentSourceLookUpTest, ShouldCacheNonCorrelatedSubPipelinePrefix) { auto expectedPipe = fromjson( str::stream() << "[{mock: {}}, {$match: {x:{$eq: 1}}}, {$sort: {sortKey: {x: 1}}}, " - << sequentialCacheStageObj() - << ", {$addFields: {varField: {$const: 5} }}]"); + << sequentialCacheStageObj() << ", {$addFields: {varField: {$const: 5} }}]"); ASSERT_VALUE_EQ(Value(subPipeline->writeExplainOps(kExplain)), Value(BSONArray(expectedPipe))); } @@ -914,8 +905,7 @@ TEST_F(DocumentSourceLookUpTest, str::stream() << "[{mock: {}}, {$match: {x:{$eq: 1}}}, {$sort: {sortKey: {x: 1}}}, " "{$lookup: {from: 'coll', as: 'subas', let: {var1: '$y'}, " "pipeline: [{$match: {$expr: { $eq: ['$z', '$$var1']}}}]}}, " - << sequentialCacheStageObj() - << ", {$addFields: {varField: {$const: 5} }}]"); + << sequentialCacheStageObj() << ", {$addFields: {varField: {$const: 5} }}]"); ASSERT_VALUE_EQ(Value(subPipeline->writeExplainOps(kExplain)), Value(BSONArray(expectedPipe))); } @@ -947,8 +937,7 @@ TEST_F(DocumentSourceLookUpTest, ShouldCacheEntirePipelineIfNonCorrelated) { << "[{mock: {}}, {$match: {x:{$eq: 1}}}, {$sort: {sortKey: {x: 1}}}, {$lookup: {from: " "'coll', as: 'subas', let: {}, pipeline: [{$match: {y: 5}}]}}, {$addFields: " "{constField: {$const: 5}}}, " - << sequentialCacheStageObj() - << "]"); + << sequentialCacheStageObj() << "]"); ASSERT_VALUE_EQ(Value(subPipeline->writeExplainOps(kExplain)), Value(BSONArray(expectedPipe))); } diff --git a/src/mongo/db/pipeline/document_source_match.cpp b/src/mongo/db/pipeline/document_source_match.cpp index d29fe8285aa..6ed37705edd 100644 --- a/src/mongo/db/pipeline/document_source_match.cpp +++ b/src/mongo/db/pipeline/document_source_match.cpp @@ -49,8 +49,8 @@ namespace mongo { using boost::intrusive_ptr; using std::pair; -using std::unique_ptr; using std::string; +using std::unique_ptr; using std::vector; REGISTER_DOCUMENT_SOURCE(match, diff --git a/src/mongo/db/pipeline/document_source_merge.cpp b/src/mongo/db/pipeline/document_source_merge.cpp index ec09b41fd5c..c4f7e864231 100644 --- a/src/mongo/db/pipeline/document_source_merge.cpp +++ b/src/mongo/db/pipeline/document_source_merge.cpp @@ -83,7 +83,7 @@ constexpr auto kPipelineDiscardMode = MergeMode{WhenMatched::kPipeline, WhenNotM */ MergeStrategy makeUpdateStrategy(bool upsert, BatchTransform transform) { return [upsert, transform]( - const auto& expCtx, const auto& ns, const auto& wc, auto epoch, auto&& batch) { + const auto& expCtx, const auto& ns, const auto& wc, auto epoch, auto&& batch) { if (transform) { transform(batch); } @@ -104,7 +104,7 @@ MergeStrategy makeUpdateStrategy(bool upsert, BatchTransform transform) { */ MergeStrategy makeStrictUpdateStrategy(bool upsert, BatchTransform transform) { return [upsert, transform]( - const auto& expCtx, const auto& ns, const auto& wc, auto epoch, auto&& batch) { + const auto& expCtx, const auto& ns, const auto& wc, auto epoch, auto&& batch) { if (transform) { transform(batch); } @@ -408,7 +408,7 @@ boost::intrusive_ptr<DocumentSource> DocumentSourceMerge::createFromBson( mergeSpec.getWhenMatched() ? mergeSpec.getWhenMatched()->mode : kDefaultWhenMatched; auto whenNotMatched = mergeSpec.getWhenNotMatched().value_or(kDefaultWhenNotMatched); auto pipeline = mergeSpec.getWhenMatched() ? mergeSpec.getWhenMatched()->pipeline : boost::none; - auto[mergeOnFields, targetCollectionVersion] = + auto [mergeOnFields, targetCollectionVersion] = expCtx->mongoProcessInterface->ensureFieldsUniqueOrResolveDocumentKey( expCtx, mergeSpec.getOn(), mergeSpec.getTargetCollectionVersion(), targetNss); @@ -431,7 +431,7 @@ Value DocumentSourceMerge::serialize(boost::optional<ExplainOptions::Verbosity> } BSONObjBuilder bob; - for (auto && [ name, expr ] : *_letVariables) { + for (auto&& [name, expr] : *_letVariables) { bob << name << expr->serialize(static_cast<bool>(explain)); } return bob.obj(); diff --git a/src/mongo/db/pipeline/document_source_merge.h b/src/mongo/db/pipeline/document_source_merge.h index 927c0376245..f7889528930 100644 --- a/src/mongo/db/pipeline/document_source_merge.h +++ b/src/mongo/db/pipeline/document_source_merge.h @@ -180,7 +180,7 @@ private: } BSONObjBuilder bob; - for (auto && [ name, expr ] : *_letVariables) { + for (auto&& [name, expr] : *_letVariables) { bob << name << expr->evaluate(doc, &pExpCtx->variables); } return bob.obj(); diff --git a/src/mongo/db/pipeline/document_source_merge_cursors_test.cpp b/src/mongo/db/pipeline/document_source_merge_cursors_test.cpp index b344097425d..7daca0df406 100644 --- a/src/mongo/db/pipeline/document_source_merge_cursors_test.cpp +++ b/src/mongo/db/pipeline/document_source_merge_cursors_test.cpp @@ -133,8 +133,8 @@ TEST_F(DocumentSourceMergeCursorsTest, ShouldRejectEmptyArray) { TEST_F(DocumentSourceMergeCursorsTest, ShouldRejectLegacySerializationFormats) { // Formats like this were used in old versions of the server but are no longer supported. - auto spec = BSON("$mergeCursors" << BSON_ARRAY(BSON( - "ns" << kTestNss.ns() << "id" << 0LL << "host" << kTestHost.toString()))); + auto spec = BSON("$mergeCursors" << BSON_ARRAY(BSON("ns" << kTestNss.ns() << "id" << 0LL + << "host" << kTestHost.toString()))); ASSERT_THROWS_CODE(DocumentSourceMergeCursors::createFromBson(spec.firstElement(), getExpCtx()), AssertionException, 17026); diff --git a/src/mongo/db/pipeline/document_source_merge_test.cpp b/src/mongo/db/pipeline/document_source_merge_test.cpp index 32ed7b9f963..cdef17e6ca9 100644 --- a/src/mongo/db/pipeline/document_source_merge_test.cpp +++ b/src/mongo/db/pipeline/document_source_merge_test.cpp @@ -140,8 +140,7 @@ TEST_F(DocumentSourceMergeTest, CorrectlyParsesIfWhenMatchedIsStringOrArray) { spec = BSON("$merge" << BSON("into" << "target_collection" - << "whenMatched" - << BSONArray())); + << "whenMatched" << BSONArray())); ASSERT(createMergeStage(spec)); } @@ -214,14 +213,12 @@ TEST_F(DocumentSourceMergeTest, FailsToParseIfIntoIsNotAValidUserCollection) { TEST_F(DocumentSourceMergeTest, FailsToParseIfDbIsNotString) { auto spec = BSON("$merge" << BSON("into" << BSON("coll" << "target_collection" - << "db" - << true))); + << "db" << true))); ASSERT_THROWS_CODE(createMergeStage(spec), AssertionException, ErrorCodes::TypeMismatch); spec = BSON("$merge" << BSON("into" << BSON("coll" << "target_collection" - << "db" - << BSONArray()))); + << "db" << BSONArray()))); ASSERT_THROWS_CODE(createMergeStage(spec), AssertionException, ErrorCodes::TypeMismatch); spec = BSON("$merge" << BSON("into" << BSON("coll" @@ -235,14 +232,12 @@ TEST_F(DocumentSourceMergeTest, FailsToParseIfDbIsNotString) { TEST_F(DocumentSourceMergeTest, FailsToParseIfCollIsNotString) { auto spec = BSON("$merge" << BSON("into" << BSON("db" << "target_db" - << "coll" - << true))); + << "coll" << true))); ASSERT_THROWS_CODE(createMergeStage(spec), AssertionException, ErrorCodes::TypeMismatch); spec = BSON("$merge" << BSON("into" << BSON("db" << "target_db" - << "coll" - << BSONArray()))); + << "coll" << BSONArray()))); ASSERT_THROWS_CODE(createMergeStage(spec), AssertionException, ErrorCodes::TypeMismatch); spec = BSON("$merge" << BSON("into" << BSON("db" @@ -264,40 +259,34 @@ TEST_F(DocumentSourceMergeTest, FailsToParseIfDbIsNotAValidDatabaseName) { TEST_F(DocumentSourceMergeTest, FailsToParseIfWhenMatchedModeIsNotStringOrArray) { auto spec = BSON("$merge" << BSON("into" << "target_collection" - << "whenMatched" - << true)); + << "whenMatched" << true)); ASSERT_THROWS_CODE(createMergeStage(spec), AssertionException, 51191); spec = BSON("$merge" << BSON("into" << "target_collection" - << "whenMatched" - << 100)); + << "whenMatched" << 100)); ASSERT_THROWS_CODE(createMergeStage(spec), AssertionException, 51191); spec = BSON("$merge" << BSON("into" << "target_collection" - << "whenMatched" - << BSON("" << kDefaultWhenMatchedMode))); + << "whenMatched" << BSON("" << kDefaultWhenMatchedMode))); ASSERT_THROWS_CODE(createMergeStage(spec), AssertionException, 51191); } TEST_F(DocumentSourceMergeTest, FailsToParseIfWhenNotMatchedModeIsNotString) { auto spec = BSON("$merge" << BSON("into" << "target_collection" - << "whenNotMatched" - << true)); + << "whenNotMatched" << true)); ASSERT_THROWS_CODE(createMergeStage(spec), AssertionException, ErrorCodes::TypeMismatch); spec = BSON("$merge" << BSON("into" << "target_collection" - << "whenNotMatched" - << BSONArray())); + << "whenNotMatched" << BSONArray())); ASSERT_THROWS_CODE(createMergeStage(spec), AssertionException, ErrorCodes::TypeMismatch); spec = BSON("$merge" << BSON("into" << "target_collection" - << "whenNotMatched" - << BSON("" << kDefaultWhenNotMatchedMode))); + << "whenNotMatched" << BSON("" << kDefaultWhenNotMatchedMode))); ASSERT_THROWS_CODE(createMergeStage(spec), AssertionException, ErrorCodes::TypeMismatch); } @@ -341,26 +330,22 @@ TEST_F(DocumentSourceMergeTest, FailsToParseIfWhenNotMatchedModeIsUnsupportedStr TEST_F(DocumentSourceMergeTest, FailsToParseIfOnFieldIsNotStringOrArrayOfStrings) { auto spec = BSON("$merge" << BSON("into" << "target_collection" - << "on" - << 1)); + << "on" << 1)); ASSERT_THROWS_CODE(createMergeStage(spec), AssertionException, 51186); spec = BSON("$merge" << BSON("into" << "target_collection" - << "on" - << BSONArray())); + << "on" << BSONArray())); ASSERT_THROWS_CODE(createMergeStage(spec), AssertionException, 51187); spec = BSON("$merge" << BSON("into" << "target_collection" - << "on" - << BSON_ARRAY(1 << 2 << BSON("a" << 3)))); + << "on" << BSON_ARRAY(1 << 2 << BSON("a" << 3)))); ASSERT_THROWS_CODE(createMergeStage(spec), AssertionException, 51134); spec = BSON("$merge" << BSON("into" << "target_collection" - << "on" - << BSON("_id" << 1))); + << "on" << BSON("_id" << 1))); ASSERT_THROWS_CODE(createMergeStage(spec), AssertionException, 51186); } @@ -616,24 +601,21 @@ TEST_F(DocumentSourceMergeTest, CorrectlyHandlesWhenMatchedAndWhenNotMatchedMode spec = BSON("$merge" << BSON("into" << "target_collection" - << "whenMatched" - << BSON_ARRAY(BSON("$project" << BSON("x" << 1))) + << "whenMatched" << BSON_ARRAY(BSON("$project" << BSON("x" << 1))) << "whenNotMatched" << "insert")); ASSERT(createMergeStage(spec)); spec = BSON("$merge" << BSON("into" << "target_collection" - << "whenMatched" - << BSON_ARRAY(BSON("$project" << BSON("x" << 1))) + << "whenMatched" << BSON_ARRAY(BSON("$project" << BSON("x" << 1))) << "whenNotMatched" << "fail")); ASSERT(createMergeStage(spec)); spec = BSON("$merge" << BSON("into" << "target_collection" - << "whenMatched" - << BSON_ARRAY(BSON("$project" << BSON("x" << 1))) + << "whenMatched" << BSON_ARRAY(BSON("$project" << BSON("x" << 1))) << "whenNotMatched" << "discard")); ASSERT(createMergeStage(spec)); @@ -658,41 +640,33 @@ TEST_F(DocumentSourceMergeTest, CorrectlyHandlesWhenMatchedAndWhenNotMatchedMode TEST_F(DocumentSourceMergeTest, LetVariablesCanOnlyBeUsedWithPipelineMode) { auto let = BSON("foo" << "bar"); - auto spec = BSON("$merge" << BSON("into" - << "target_collection" - << "let" - << let - << "whenMatched" - << BSON_ARRAY(BSON("$project" << BSON("x" << 1))) - << "whenNotMatched" - << "insert")); + auto spec = + BSON("$merge" << BSON("into" + << "target_collection" + << "let" << let << "whenMatched" + << BSON_ARRAY(BSON("$project" << BSON("x" << 1))) << "whenNotMatched" + << "insert")); ASSERT(createMergeStage(spec)); - spec = BSON("$merge" << BSON("into" - << "target_collection" - << "let" - << let - << "whenMatched" - << BSON_ARRAY(BSON("$project" << BSON("x" << 1))) - << "whenNotMatched" - << "fail")); + spec = + BSON("$merge" << BSON("into" + << "target_collection" + << "let" << let << "whenMatched" + << BSON_ARRAY(BSON("$project" << BSON("x" << 1))) << "whenNotMatched" + << "fail")); ASSERT(createMergeStage(spec)); - spec = BSON("$merge" << BSON("into" - << "target_collection" - << "let" - << let - << "whenMatched" - << BSON_ARRAY(BSON("$project" << BSON("x" << 1))) - << "whenNotMatched" - << "discard")); + spec = + BSON("$merge" << BSON("into" + << "target_collection" + << "let" << let << "whenMatched" + << BSON_ARRAY(BSON("$project" << BSON("x" << 1))) << "whenNotMatched" + << "discard")); ASSERT(createMergeStage(spec)); spec = BSON("$merge" << BSON("into" << "target_collection" - << "let" - << let - << "whenMatched" + << "let" << let << "whenMatched" << "replace" << "whenNotMatched" << "insert")); @@ -700,9 +674,7 @@ TEST_F(DocumentSourceMergeTest, LetVariablesCanOnlyBeUsedWithPipelineMode) { spec = BSON("$merge" << BSON("into" << "target_collection" - << "let" - << let - << "whenMatched" + << "let" << let << "whenMatched" << "replace" << "whenNotMatched" << "fail")); @@ -710,9 +682,7 @@ TEST_F(DocumentSourceMergeTest, LetVariablesCanOnlyBeUsedWithPipelineMode) { spec = BSON("$merge" << BSON("into" << "target_collection" - << "let" - << let - << "whenMatched" + << "let" << let << "whenMatched" << "replace" << "whenNotMatched" << "discard")); @@ -720,9 +690,7 @@ TEST_F(DocumentSourceMergeTest, LetVariablesCanOnlyBeUsedWithPipelineMode) { spec = BSON("$merge" << BSON("into" << "target_collection" - << "let" - << let - << "whenMatched" + << "let" << let << "whenMatched" << "merge" << "whenNotMatched" << "insert")); @@ -730,9 +698,7 @@ TEST_F(DocumentSourceMergeTest, LetVariablesCanOnlyBeUsedWithPipelineMode) { spec = BSON("$merge" << BSON("into" << "target_collection" - << "let" - << let - << "whenMatched" + << "let" << let << "whenMatched" << "merge" << "whenNotMatched" << "fail")); @@ -740,9 +706,7 @@ TEST_F(DocumentSourceMergeTest, LetVariablesCanOnlyBeUsedWithPipelineMode) { spec = BSON("$merge" << BSON("into" << "target_collection" - << "let" - << let - << "whenMatched" + << "let" << let << "whenMatched" << "merge" << "whenNotMatched" << "discard")); @@ -750,9 +714,7 @@ TEST_F(DocumentSourceMergeTest, LetVariablesCanOnlyBeUsedWithPipelineMode) { spec = BSON("$merge" << BSON("into" << "target_collection" - << "let" - << let - << "whenMatched" + << "let" << let << "whenMatched" << "keepExisting" << "whenNotMatched" << "insert")); @@ -760,9 +722,7 @@ TEST_F(DocumentSourceMergeTest, LetVariablesCanOnlyBeUsedWithPipelineMode) { spec = BSON("$merge" << BSON("into" << "target_collection" - << "let" - << let - << "whenMatched" + << "let" << let << "whenMatched" << "fail" << "whenNotMatched" << "insert")); @@ -770,12 +730,12 @@ TEST_F(DocumentSourceMergeTest, LetVariablesCanOnlyBeUsedWithPipelineMode) { } TEST_F(DocumentSourceMergeTest, SerializeDefaultLetVariable) { - auto spec = BSON("$merge" << BSON("into" - << "target_collection" - << "whenMatched" - << BSON_ARRAY(BSON("$project" << BSON("x" << 1))) - << "whenNotMatched" - << "insert")); + auto spec = + BSON("$merge" << BSON("into" + << "target_collection" + << "whenMatched" << BSON_ARRAY(BSON("$project" << BSON("x" << 1))) + << "whenNotMatched" + << "insert")); auto mergeStage = createMergeStage(spec); auto serialized = mergeStage->serialize().getDocument(); ASSERT_VALUE_EQ(serialized["$merge"]["let"], @@ -796,11 +756,10 @@ TEST_F(DocumentSourceMergeTest, SerializeLetVariables) { << BSON("v1" << 10 << "v2" << "foo" << "v3" - << BSON("x" << 1 << "y" << BSON("z" - << "bar"))) - << "whenMatched" - << pipeline - << "whenNotMatched" + << BSON("x" << 1 << "y" + << BSON("z" + << "bar"))) + << "whenMatched" << pipeline << "whenNotMatched" << "insert")); auto mergeStage = createMergeStage(spec); ASSERT(mergeStage); @@ -810,8 +769,9 @@ TEST_F(DocumentSourceMergeTest, SerializeLetVariables) { Value(BSON("$const" << "foo"))); ASSERT_VALUE_EQ(serialized["$merge"]["let"]["v3"], - Value(BSON("x" << BSON("$const" << 1) << "y" << BSON("z" << BSON("$const" - << "bar"))))); + Value(BSON("x" << BSON("$const" << 1) << "y" + << BSON("z" << BSON("$const" + << "bar"))))); ASSERT_VALUE_EQ(serialized["$merge"]["whenMatched"], Value(pipeline)); } @@ -823,9 +783,7 @@ TEST_F(DocumentSourceMergeTest, SerializeLetArrayVariable) { << "target_collection" << "let" << BSON("v1" << BSON_ARRAY(1 << "2" << BSON("x" << 1 << "y" << 2))) - << "whenMatched" - << pipeline - << "whenNotMatched" + << "whenMatched" << pipeline << "whenNotMatched" << "insert")); auto mergeStage = createMergeStage(spec); ASSERT(mergeStage); @@ -847,14 +805,11 @@ TEST_F(DocumentSourceMergeTest, SerializeLetArrayVariable) { TEST_F(DocumentSourceMergeTest, SerializeNullLetVariablesAsDefault) { auto pipeline = BSON_ARRAY(BSON("$project" << BSON("x" << "1"))); - auto spec = BSON("$merge" << BSON("into" - << "target_collection" - << "let" - << BSONNULL - << "whenMatched" - << pipeline - << "whenNotMatched" - << "insert")); + auto spec = + BSON("$merge" << BSON("into" + << "target_collection" + << "let" << BSONNULL << "whenMatched" << pipeline << "whenNotMatched" + << "insert")); auto mergeStage = createMergeStage(spec); ASSERT(mergeStage); auto serialized = mergeStage->serialize().getDocument(); @@ -867,14 +822,11 @@ TEST_F(DocumentSourceMergeTest, SerializeNullLetVariablesAsDefault) { TEST_F(DocumentSourceMergeTest, SerializeEmptyLetVariables) { auto pipeline = BSON_ARRAY(BSON("$project" << BSON("x" << "1"))); - auto spec = BSON("$merge" << BSON("into" - << "target_collection" - << "let" - << BSONObj() - << "whenMatched" - << pipeline - << "whenNotMatched" - << "insert")); + auto spec = + BSON("$merge" << BSON("into" + << "target_collection" + << "let" << BSONObj() << "whenMatched" << pipeline << "whenNotMatched" + << "insert")); auto mergeStage = createMergeStage(spec); ASSERT(mergeStage); auto serialized = mergeStage->serialize().getDocument(); @@ -887,11 +839,7 @@ TEST_F(DocumentSourceMergeTest, OnlyObjectCanBeUsedAsLetVariables) { << "1"))); auto spec = BSON("$merge" << BSON("into" << "target_collection" - << "let" - << 1 - << "whenMatched" - << pipeline - << "whenNotMatched" + << "let" << 1 << "whenMatched" << pipeline << "whenNotMatched" << "insert")); ASSERT_THROWS_CODE(createMergeStage(spec), AssertionException, ErrorCodes::TypeMismatch); @@ -899,18 +847,13 @@ TEST_F(DocumentSourceMergeTest, OnlyObjectCanBeUsedAsLetVariables) { << "target_collection" << "let" << "foo" - << "whenMatched" - << pipeline - << "whenNotMatched" + << "whenMatched" << pipeline << "whenNotMatched" << "insert")); ASSERT_THROWS_CODE(createMergeStage(spec), AssertionException, ErrorCodes::TypeMismatch); spec = BSON("$merge" << BSON("into" << "target_collection" - << "let" - << BSON_ARRAY(1 << "2") - << "whenMatched" - << pipeline + << "let" << BSON_ARRAY(1 << "2") << "whenMatched" << pipeline << "whenNotMatched" << "insert")); ASSERT_THROWS_CODE(createMergeStage(spec), AssertionException, ErrorCodes::TypeMismatch); diff --git a/src/mongo/db/pipeline/document_source_mock.cpp b/src/mongo/db/pipeline/document_source_mock.cpp index f4efb3e731e..86e9ebda0ee 100644 --- a/src/mongo/db/pipeline/document_source_mock.cpp +++ b/src/mongo/db/pipeline/document_source_mock.cpp @@ -76,4 +76,4 @@ intrusive_ptr<DocumentSourceMock> DocumentSourceMock::createForTest( } return new DocumentSourceMock(std::move(results)); } -} +} // namespace mongo diff --git a/src/mongo/db/pipeline/document_source_out.cpp b/src/mongo/db/pipeline/document_source_out.cpp index 318dfb47859..2293294534c 100644 --- a/src/mongo/db/pipeline/document_source_out.cpp +++ b/src/mongo/db/pipeline/document_source_out.cpp @@ -106,8 +106,8 @@ void DocumentSourceOut::initialize() { DBClientBase* conn = pExpCtx->mongoProcessInterface->directClient(); const auto& outputNs = getOutputNs(); - _tempNs = NamespaceString(str::stream() << outputNs.db() << ".tmp.agg_out." - << aggOutCounter.addAndFetch(1)); + _tempNs = NamespaceString(str::stream() + << outputNs.db() << ".tmp.agg_out." << aggOutCounter.addAndFetch(1)); // Save the original collection options and index specs so we can check they didn't change // during computation. @@ -123,8 +123,8 @@ void DocumentSourceOut::initialize() { // We will write all results into a temporary collection, then rename the temporary // collection to be the target collection once we are done. - _tempNs = NamespaceString(str::stream() << outputNs.db() << ".tmp.agg_out." - << aggOutCounter.addAndFetch(1)); + _tempNs = NamespaceString(str::stream() + << outputNs.db() << ".tmp.agg_out." << aggOutCounter.addAndFetch(1)); // Create temp collection, copying options from the existing output collection if any. { diff --git a/src/mongo/db/pipeline/document_source_plan_cache_stats.cpp b/src/mongo/db/pipeline/document_source_plan_cache_stats.cpp index d95043e66fe..dfa460c3f9f 100644 --- a/src/mongo/db/pipeline/document_source_plan_cache_stats.cpp +++ b/src/mongo/db/pipeline/document_source_plan_cache_stats.cpp @@ -41,14 +41,14 @@ REGISTER_DOCUMENT_SOURCE(planCacheStats, boost::intrusive_ptr<DocumentSource> DocumentSourcePlanCacheStats::createFromBson( BSONElement spec, const boost::intrusive_ptr<ExpressionContext>& pExpCtx) { - uassert( - ErrorCodes::FailedToParse, - str::stream() << kStageName << " value must be an object. Found: " << typeName(spec.type()), - spec.type() == BSONType::Object); + uassert(ErrorCodes::FailedToParse, + str::stream() << kStageName + << " value must be an object. Found: " << typeName(spec.type()), + spec.type() == BSONType::Object); uassert(ErrorCodes::FailedToParse, - str::stream() << kStageName << " parameters object must be empty. Found: " - << typeName(spec.type()), + str::stream() << kStageName + << " parameters object must be empty. Found: " << typeName(spec.type()), spec.embeddedObject().isEmpty()); uassert(50932, diff --git a/src/mongo/db/pipeline/document_source_plan_cache_stats_test.cpp b/src/mongo/db/pipeline/document_source_plan_cache_stats_test.cpp index 3eec42538f2..6980b400972 100644 --- a/src/mongo/db/pipeline/document_source_plan_cache_stats_test.cpp +++ b/src/mongo/db/pipeline/document_source_plan_cache_stats_test.cpp @@ -159,8 +159,7 @@ TEST_F(DocumentSourcePlanCacheStatsTest, ReturnsOnlyMatchingStatsAfterAbsorbingM << "baz"), BSON("foo" << "bar" - << "match" - << true)}; + << "match" << true)}; getExpCtx()->mongoProcessInterface = std::make_shared<PlanCacheStatsMongoProcessInterface>(stats); diff --git a/src/mongo/db/pipeline/document_source_queue.cpp b/src/mongo/db/pipeline/document_source_queue.cpp index 80559de1a71..47a77709363 100644 --- a/src/mongo/db/pipeline/document_source_queue.cpp +++ b/src/mongo/db/pipeline/document_source_queue.cpp @@ -55,4 +55,4 @@ DocumentSource::GetNextResult DocumentSourceQueue::getNext() { _queue.pop_front(); return next; } -} +} // namespace mongo diff --git a/src/mongo/db/pipeline/document_source_redact.cpp b/src/mongo/db/pipeline/document_source_redact.cpp index 3ff60410a95..7afc1eea75a 100644 --- a/src/mongo/db/pipeline/document_source_redact.cpp +++ b/src/mongo/db/pipeline/document_source_redact.cpp @@ -161,8 +161,7 @@ boost::optional<Document> DocumentSourceRedact::redactObject(const Document& roo 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()); } } @@ -196,4 +195,4 @@ intrusive_ptr<DocumentSource> DocumentSourceRedact::createFromBson( return source; } -} +} // namespace mongo diff --git a/src/mongo/db/pipeline/document_source_replace_root.cpp b/src/mongo/db/pipeline/document_source_replace_root.cpp index e494fe1ea2a..3fe49d83f0b 100644 --- a/src/mongo/db/pipeline/document_source_replace_root.cpp +++ b/src/mongo/db/pipeline/document_source_replace_root.cpp @@ -63,11 +63,9 @@ Document ReplaceRootTransformation::applyTransformation(const Document& input) { uassert(40228, str::stream() << msgOpener.toString() << "must evaluate to an object, but resulting value was: " - << newRoot.toString() - << ". Type of resulting value: '" + << newRoot.toString() << ". Type of resulting value: '" << typeName(newRoot.getType()) - << "'. Input document: " - << input.toString(), + << "'. Input document: " << input.toString(), newRoot.getType() == BSONType::Object); // Turn the value into a document. @@ -97,8 +95,7 @@ intrusive_ptr<DocumentSource> DocumentSourceReplaceRoot::createFromBson( << stageName); uassert(40229, str::stream() << "expected an object as specification for " << kStageName - << " stage, got " - << typeName(elem.type()), + << " stage, got " << typeName(elem.type()), elem.type() == Object); auto spec = diff --git a/src/mongo/db/pipeline/document_source_replace_root_test.cpp b/src/mongo/db/pipeline/document_source_replace_root_test.cpp index 71c356e98f2..cb71448fa7b 100644 --- a/src/mongo/db/pipeline/document_source_replace_root_test.cpp +++ b/src/mongo/db/pipeline/document_source_replace_root_test.cpp @@ -336,14 +336,12 @@ TEST_F(ReplaceRootSpec, CreationRequiresObjectSpecification) { TEST_F(ReplaceRootSpec, OnlyValidOptionInObjectSpecIsNewRoot) { ASSERT_THROWS_CODE(createReplaceRoot(createSpec(BSON("newRoot" << "$a" - << "root" - << 2))), + << "root" << 2))), AssertionException, 40415); ASSERT_THROWS_CODE(createReplaceRoot(createSpec(BSON("newRoot" << "$a" - << "path" - << 2))), + << "path" << 2))), AssertionException, 40415); ASSERT_THROWS_CODE(createReplaceRoot(createSpec(BSON("path" 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 a3a33ca6f4c..cddae4ad571 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 @@ -116,9 +116,7 @@ DocumentSource::GetNextResult DocumentSourceSampleFromRandomCursor::getNextNonDu << _idField << " field in order to de-duplicate results, but encountered a " "document without a " - << _idField - << " field: " - << nextInput.getDocument().toString(), + << _idField << " field: " << nextInput.getDocument().toString(), !idField.missing()); if (_seenDocs.insert(std::move(idField)).second) { @@ -163,4 +161,4 @@ intrusive_ptr<DocumentSourceSampleFromRandomCursor> DocumentSourceSampleFromRand new DocumentSourceSampleFromRandomCursor(expCtx, size, idField, nDocsInCollection)); return source; } -} // mongo +} // namespace mongo diff --git a/src/mongo/db/pipeline/document_source_sequential_document_cache.cpp b/src/mongo/db/pipeline/document_source_sequential_document_cache.cpp index 7fb2933fada..e6d1f3bd7f8 100644 --- a/src/mongo/db/pipeline/document_source_sequential_document_cache.cpp +++ b/src/mongo/db/pipeline/document_source_sequential_document_cache.cpp @@ -153,12 +153,12 @@ Value DocumentSourceSequentialDocumentCache::serialize( {kStageName, Document{{"maxSizeBytes"_sd, Value(static_cast<long long>(_cache->maxSizeBytes()))}, {"status"_sd, - _cache->isBuilding() ? "kBuilding"_sd : _cache->isServing() - ? "kServing"_sd - : "kAbandoned"_sd}}}}); + _cache->isBuilding() + ? "kBuilding"_sd + : _cache->isServing() ? "kServing"_sd : "kAbandoned"_sd}}}}); } return Value(); } -} // namesace mongo +} // namespace mongo diff --git a/src/mongo/db/pipeline/document_source_sequential_document_cache.h b/src/mongo/db/pipeline/document_source_sequential_document_cache.h index c575772e2c9..d8d2ba90db8 100644 --- a/src/mongo/db/pipeline/document_source_sequential_document_cache.h +++ b/src/mongo/db/pipeline/document_source_sequential_document_cache.h @@ -103,4 +103,4 @@ private: bool _hasOptimizedPos = false; }; -} // namesace mongo +} // namespace mongo diff --git a/src/mongo/db/pipeline/document_source_skip.cpp b/src/mongo/db/pipeline/document_source_skip.cpp index 2eead90aa3f..143a796cdf6 100644 --- a/src/mongo/db/pipeline/document_source_skip.cpp +++ b/src/mongo/db/pipeline/document_source_skip.cpp @@ -116,4 +116,4 @@ intrusive_ptr<DocumentSource> DocumentSourceSkip::createFromBson( return DocumentSourceSkip::create(pExpCtx, nToSkip); } -} +} // namespace mongo diff --git a/src/mongo/db/pipeline/document_source_unwind.cpp b/src/mongo/db/pipeline/document_source_unwind.cpp index 576541c207b..870394a277c 100644 --- a/src/mongo/db/pipeline/document_source_unwind.cpp +++ b/src/mongo/db/pipeline/document_source_unwind.cpp @@ -286,4 +286,4 @@ intrusive_ptr<DocumentSource> DocumentSourceUnwind::createFromBson( string pathString(Expression::removeFieldPrefix(prefixedPathString)); return DocumentSourceUnwind::create(pExpCtx, pathString, preserveNullAndEmptyArrays, indexPath); } -} +} // namespace mongo diff --git a/src/mongo/db/pipeline/document_source_unwind_test.cpp b/src/mongo/db/pipeline/document_source_unwind_test.cpp index 9eed7c7446b..e55a58a1c3b 100644 --- a/src/mongo/db/pipeline/document_source_unwind_test.cpp +++ b/src/mongo/db/pipeline/document_source_unwind_test.cpp @@ -163,8 +163,7 @@ 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()); @@ -474,8 +473,9 @@ class SeveralMoreDocuments : public CheckResultsBase { deque<DocumentSource::GetNextResult> inputData() override { return {DOC("_id" << 0 << "a" << BSONNULL), DOC("_id" << 1), - DOC("_id" << 2 << "a" << DOC_ARRAY("a"_sd - << "b"_sd)), + DOC("_id" << 2 << "a" + << DOC_ARRAY("a"_sd + << "b"_sd)), DOC("_id" << 3), DOC("_id" << 4 << "a" << DOC_ARRAY(1 << 2 << 3)), DOC("_id" << 5 << "a" << DOC_ARRAY(4 << 5 << 6)), @@ -763,8 +763,7 @@ TEST_F(UnwindStageTest, ShouldRejectNonDollarPrefixedPath) { TEST_F(UnwindStageTest, ShouldRejectNonBoolPreserveNullAndEmptyArrays) { ASSERT_THROWS_CODE(createUnwind(BSON("$unwind" << BSON("path" << "$x" - << "preserveNullAndEmptyArrays" - << 2))), + << "preserveNullAndEmptyArrays" << 2))), AssertionException, 28809); } @@ -772,8 +771,7 @@ TEST_F(UnwindStageTest, ShouldRejectNonBoolPreserveNullAndEmptyArrays) { TEST_F(UnwindStageTest, ShouldRejectNonStringIncludeArrayIndex) { ASSERT_THROWS_CODE(createUnwind(BSON("$unwind" << BSON("path" << "$x" - << "includeArrayIndex" - << 2))), + << "includeArrayIndex" << 2))), AssertionException, 28810); } @@ -805,16 +803,13 @@ TEST_F(UnwindStageTest, ShoudlRejectDollarPrefixedIncludeArrayIndex) { TEST_F(UnwindStageTest, ShouldRejectUnrecognizedOption) { ASSERT_THROWS_CODE(createUnwind(BSON("$unwind" << BSON("path" << "$x" - << "preserveNullAndEmptyArrays" - << true - << "foo" - << 3))), + << "preserveNullAndEmptyArrays" << true + << "foo" << 3))), AssertionException, 28811); ASSERT_THROWS_CODE(createUnwind(BSON("$unwind" << BSON("path" << "$x" - << "foo" - << 3))), + << "foo" << 3))), AssertionException, 28811); } diff --git a/src/mongo/db/pipeline/document_source_writer.h b/src/mongo/db/pipeline/document_source_writer.h index fd10532d469..ada2fc72a53 100644 --- a/src/mongo/db/pipeline/document_source_writer.h +++ b/src/mongo/db/pipeline/document_source_writer.h @@ -193,7 +193,7 @@ DocumentSource::GetNextResult DocumentSourceWriter<B>::getNext() { waitWhileFailPointEnabled(); auto doc = nextInput.releaseDocument(); - auto[obj, objSize] = makeBatchObject(std::move(doc)); + auto [obj, objSize] = makeBatchObject(std::move(doc)); bufferedBytes += objSize; if (!batch.empty() && diff --git a/src/mongo/db/pipeline/document_value_test.cpp b/src/mongo/db/pipeline/document_value_test.cpp index 67d669403da..f3b9e12c8de 100644 --- a/src/mongo/db/pipeline/document_value_test.cpp +++ b/src/mongo/db/pipeline/document_value_test.cpp @@ -597,29 +597,13 @@ TEST(MetaFields, FromBsonWithMetadataAcceptsIndexKeyMetadata) { } TEST(MetaFields, CopyMetadataFromCopiesAllMetadata) { - Document source = Document::fromBsonWithMetaData(BSON( - "a" << 1 << "$textScore" << 9.9 << "b" << 1 << "$randVal" << 42.0 << "c" << 1 << "$sortKey" - << BSON("x" << 1) - << "d" - << 1 - << "$dis" - << 3.2 - << "e" - << 1 - << "$pt" - << BSON_ARRAY(1 << 2) - << "f" - << 1 - << "$searchScore" - << 5.4 - << "g" - << 1 - << "$searchHighlights" - << "foo" - << "h" - << 1 - << "$indexKey" - << BSON("y" << 1))); + Document source = Document::fromBsonWithMetaData( + BSON("a" << 1 << "$textScore" << 9.9 << "b" << 1 << "$randVal" << 42.0 << "c" << 1 + << "$sortKey" << BSON("x" << 1) << "d" << 1 << "$dis" << 3.2 << "e" << 1 << "$pt" + << BSON_ARRAY(1 << 2) << "f" << 1 << "$searchScore" << 5.4 << "g" << 1 + << "$searchHighlights" + << "foo" + << "h" << 1 << "$indexKey" << BSON("y" << 1))); MutableDocument destination{}; destination.copyMetaDataFrom(source); diff --git a/src/mongo/db/pipeline/expression.cpp b/src/mongo/db/pipeline/expression.cpp index 0c0ef86f963..e8b758356d9 100644 --- a/src/mongo/db/pipeline/expression.cpp +++ b/src/mongo/db/pipeline/expression.cpp @@ -112,7 +112,7 @@ struct ParserRegistration { }; StringMap<ParserRegistration> parserMap; -} +} // namespace void Expression::registerExpression( string key, @@ -145,17 +145,16 @@ intrusive_ptr<Expression> Expression::parseExpression( // Make sure we are allowed to use this expression under the current feature compatibility // version. auto& entry = it->second; - uassert( - ErrorCodes::QueryFeatureNotAllowed, - // TODO SERVER-31968 we would like to include the current version and the required minimum - // version in this error message, but using FeatureCompatibilityVersion::toString() would - // introduce a dependency cycle. - str::stream() << opName - << " is not allowed in the current feature compatibility version. See " - << feature_compatibility_version_documentation::kCompatibilityLink - << " for more information.", - !expCtx->maxFeatureCompatibilityVersion || !entry.requiredMinVersion || - (*entry.requiredMinVersion <= *expCtx->maxFeatureCompatibilityVersion)); + uassert(ErrorCodes::QueryFeatureNotAllowed, + // TODO SERVER-31968 we would like to include the current version and the required + // minimum version in this error message, but using + // FeatureCompatibilityVersion::toString() would introduce a dependency cycle. + str::stream() << opName + << " is not allowed in the current feature compatibility version. See " + << feature_compatibility_version_documentation::kCompatibilityLink + << " for more information.", + !expCtx->maxFeatureCompatibilityVersion || !entry.requiredMinVersion || + (*entry.requiredMinVersion <= *expCtx->maxFeatureCompatibilityVersion)); return entry.parser(expCtx, obj.firstElement(), vps); } @@ -522,13 +521,11 @@ Value ExpressionArrayElemAt::evaluate(const Document& root, Variables* variables 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(); @@ -808,7 +805,7 @@ static const CmpLookup cmpLookup[7] = { // CMP is special. Only name is used. /* CMP */ {{false, false, false}, ExpressionCompare::CMP, "$cmp"}, }; -} +} // namespace Value ExpressionCompare::evaluate(const Document& root, Variables* variables) const { Value pLeft(_children[0]->evaluate(root, variables)); @@ -1063,8 +1060,8 @@ intrusive_ptr<Expression> ExpressionDateFromParts::parse( timeZoneElem = arg; } else { uasserted(40518, - str::stream() << "Unrecognized argument to $dateFromParts: " - << arg.fieldName()); + str::stream() + << "Unrecognized argument to $dateFromParts: " << arg.fieldName()); } } @@ -1222,8 +1219,7 @@ bool ExpressionDateFromParts::evaluateNumberWithDefault(const Document& root, uassert(40515, str::stream() << "'" << fieldName << "' must evaluate to an integer, found " - << typeName(fieldValue.getType()) - << " with value " + << typeName(fieldValue.getType()) << " with value " << fieldValue.toString(), fieldValue.integral64Bit()); @@ -1241,17 +1237,12 @@ bool ExpressionDateFromParts::evaluateNumberWithDefaultAndBounds(const Document& bool result = evaluateNumberWithDefault(root, field, fieldName, defaultValue, returnValue, variables); - uassert(31034, - str::stream() << "'" << fieldName << "'" - << " must evaluate to a value in the range [" - << kMinValueForDatePart - << ", " - << kMaxValueForDatePart - << "]; value " - << *returnValue - << " is not in range", - !result || - (*returnValue >= kMinValueForDatePart && *returnValue <= kMaxValueForDatePart)); + uassert( + 31034, + str::stream() << "'" << fieldName << "'" + << " must evaluate to a value in the range [" << kMinValueForDatePart << ", " + << kMaxValueForDatePart << "]; value " << *returnValue << " is not in range", + !result || (*returnValue >= kMinValueForDatePart && *returnValue <= kMaxValueForDatePart)); return result; } @@ -1289,9 +1280,7 @@ Value ExpressionDateFromParts::evaluate(const Document& root, Variables* variabl uassert(40523, str::stream() << "'year' must evaluate to an integer in the range " << 0 << " to " - << 9999 - << ", found " - << year, + << 9999 << ", found " << year, year >= 0 && year <= 9999); return Value( @@ -1313,10 +1302,7 @@ Value ExpressionDateFromParts::evaluate(const Document& root, Variables* variabl uassert(31095, str::stream() << "'isoWeekYear' must evaluate to an integer in the range " << 0 - << " to " - << 9999 - << ", found " - << isoWeekYear, + << " to " << 9999 << ", found " << isoWeekYear, isoWeekYear >= 0 && isoWeekYear <= 9999); return Value(timeZone->createFromIso8601DateParts( @@ -1393,8 +1379,8 @@ intrusive_ptr<Expression> ExpressionDateFromString::parse( onErrorElem = arg; } else { uasserted(40541, - str::stream() << "Unrecognized argument to $dateFromString: " - << arg.fieldName()); + str::stream() + << "Unrecognized argument to $dateFromString: " << arg.fieldName()); } } @@ -1476,8 +1462,7 @@ Value ExpressionDateFromString::evaluate(const Document& root, Variables* variab if (!formatValue.nullish()) { uassert(40684, str::stream() << "$dateFromString requires that 'format' be a string, found: " - << typeName(formatValue.getType()) - << " with value " + << typeName(formatValue.getType()) << " with value " << formatValue.toString(), formatValue.getType() == BSONType::String); @@ -1498,8 +1483,7 @@ Value ExpressionDateFromString::evaluate(const Document& root, Variables* variab try { uassert(ErrorCodes::ConversionFailure, str::stream() << "$dateFromString requires that 'dateString' be a string, found: " - << typeName(dateString.getType()) - << " with value " + << typeName(dateString.getType()) << " with value " << dateString.toString(), dateString.getType() == BSONType::String); @@ -1575,8 +1559,8 @@ intrusive_ptr<Expression> ExpressionDateToParts::parse( isoDateElem = arg; } else { uasserted(40520, - str::stream() << "Unrecognized argument to $dateToParts: " - << arg.fieldName()); + str::stream() + << "Unrecognized argument to $dateToParts: " << arg.fieldName()); } } @@ -1723,8 +1707,8 @@ intrusive_ptr<Expression> ExpressionDateToString::parse( onNullElem = arg; } else { uasserted(18534, - str::stream() << "Unrecognized argument to $dateToString: " - << arg.fieldName()); + str::stream() + << "Unrecognized argument to $dateToString: " << arg.fieldName()); } } @@ -1794,8 +1778,7 @@ Value ExpressionDateToString::evaluate(const Document& root, Variables* variable if (!formatValue.nullish()) { uassert(18533, str::stream() << "$dateToString requires that 'format' be a string, found: " - << typeName(formatValue.getType()) - << " with value " + << typeName(formatValue.getType()) << " with value " << formatValue.toString(), formatValue.getType() == BSONType::String); @@ -1869,9 +1852,7 @@ Value ExpressionDivide::evaluate(const Document& root, Variables* variables) con } 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())); } } @@ -2234,9 +2215,8 @@ 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::evaluate(const Document& root, Variables* variables) const { @@ -2654,9 +2634,7 @@ Value ExpressionMod::evaluate(const Document& root, Variables* variables) 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())); } } @@ -2776,15 +2754,12 @@ 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); } @@ -2894,8 +2869,7 @@ intrusive_ptr<Expression> ExpressionIndexOfArray::optimize() { } uassert(50809, str::stream() << "First operand of $indexOfArray must be an array. First " - << "argument is of type: " - << typeName(valueArray.getType()), + << "argument is of type: " << typeName(valueArray.getType()), valueArray.isArray()); auto arr = valueArray.getArray(); @@ -3451,7 +3425,7 @@ bool representableAsLong(long long base, long long exp) { return base >= kBaseLimits[exp].min && base <= kBaseLimits[exp].max; }; -} +} // namespace /* ----------------------- ExpressionPow ---------------------------- */ @@ -3765,7 +3739,7 @@ ValueSet arrayToSet(const Value& val, const ValueComparator& valueComparator) { valueSet.insert(array.begin(), array.end()); return valueSet; } -} +} // namespace /* ----------------------- ExpressionSetDifference ---------------------------- */ @@ -3779,13 +3753,11 @@ Value ExpressionSetDifference::evaluate(const Document& root, Variables* variabl 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, getExpressionContext()->getValueComparator()); @@ -3824,8 +3796,7 @@ Value ExpressionSetEquals::evaluate(const Document& root, Variables* variables) const Value nextEntry = _children[i]->evaluate(root, variables); 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) { @@ -3863,8 +3834,7 @@ Value ExpressionSetIntersection::evaluate(const Document& root, Variables* varia } 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) { @@ -3908,7 +3878,7 @@ Value setIsSubsetHelper(const vector<Value>& lhs, const ValueSet& rhs) { } return Value(true); } -} +} // namespace Value ExpressionSetIsSubset::evaluate(const Document& root, Variables* variables) const { const Value lhs = _children[0]->evaluate(root, variables); @@ -3916,13 +3886,11 @@ Value ExpressionSetIsSubset::evaluate(const Document& root, Variables* variables 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(), @@ -3950,8 +3918,7 @@ 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); @@ -3973,8 +3940,7 @@ 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()); intrusive_ptr<Expression> optimizedWithConstant( @@ -4003,8 +3969,7 @@ Value ExpressionSetUnion::evaluate(const Document& root, Variables* variables) c } 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()); @@ -4044,18 +4009,15 @@ Value ExpressionSlice::evaluate(const Document& root, Variables* variables) cons 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(); @@ -4095,13 +4057,11 @@ Value ExpressionSlice::evaluate(const Document& root, Variables* variables) cons 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: " @@ -4250,23 +4210,20 @@ Value ExpressionSubstrBytes::evaluate(const Document& root, Variables* variables 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)); const long long signedLower = pLower.coerceToLong(); uassert(50752, - str::stream() << getOpName() << ": starting index must be non-negative (got: " - << signedLower - << ")", + str::stream() << getOpName() + << ": starting index must be non-negative (got: " << signedLower << ")", signedLower >= 0); const string::size_type lower = static_cast<string::size_type>(signedLower); @@ -4314,8 +4271,7 @@ Value ExpressionSubstrCP::evaluate(const Document& root, Variables* variables) c 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() @@ -4324,8 +4280,7 @@ Value ExpressionSubstrCP::evaluate(const Document& root, Variables* variables) c 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() @@ -4460,8 +4415,8 @@ Value ExpressionSubtract::evaluate(const Document& root, Variables* variables) c return Value(lhs.getDate() - Milliseconds(rhs.coerceToLong())); } else { uasserted(16613, - str::stream() << "cant $subtract a " << typeName(rhs.getType()) - << " from a Date"); + str::stream() + << "cant $subtract a " << typeName(rhs.getType()) << " from a Date"); } } else { uasserted(16556, @@ -4587,7 +4542,7 @@ boost::intrusive_ptr<Expression> ExpressionSwitch::optimize() { _default = _default->optimize(); } - for (auto && [ switchCase, switchThen ] : _branches) { + for (auto&& [switchCase, switchThen] : _branches) { switchCase = switchCase->optimize(); switchThen = switchThen->optimize(); } @@ -4744,8 +4699,7 @@ std::vector<StringData> extractCodePointsFromChars(StringData utf8String, } uassert(50697, str::stream() - << "Failed to parse \"chars\" argument to " - << expressionName + << "Failed to parse \"chars\" argument to " << expressionName << ": Detected invalid UTF-8. Missing expected continuation byte at end of string.", i <= utf8String.size()); return codePoints; @@ -4759,10 +4713,8 @@ Value ExpressionTrim::evaluate(const Document& root, Variables* variables) const } uassert(50699, str::stream() << _name << " requires its input to be a string, got " - << unvalidatedInput.toString() - << " (of type " - << typeName(unvalidatedInput.getType()) - << ") instead.", + << unvalidatedInput.toString() << " (of type " + << typeName(unvalidatedInput.getType()) << ") instead.", unvalidatedInput.getType() == BSONType::String); const StringData input(unvalidatedInput.getStringData()); @@ -4775,10 +4727,8 @@ Value ExpressionTrim::evaluate(const Document& root, Variables* variables) const } uassert(50700, str::stream() << _name << " requires 'chars' to be a string, got " - << unvalidatedUserChars.toString() - << " (of type " - << typeName(unvalidatedUserChars.getType()) - << ") instead.", + << unvalidatedUserChars.toString() << " (of type " + << typeName(unvalidatedUserChars.getType()) << ") instead.", unvalidatedUserChars.getType() == BSONType::String); return Value( @@ -4877,11 +4827,8 @@ void assertFlagsValid(uint32_t flags, long long precisionValue) { uassert(51080, str::stream() << "invalid conversion from Decimal128 result in " << opName - << " resulting from arguments: [" - << numericValue - << ", " - << precisionValue - << "]", + << " resulting from arguments: [" << numericValue << ", " + << precisionValue << "]", !Decimal128::hasFlag(flags, Decimal128::kInvalid)); } @@ -4914,8 +4861,7 @@ static Value evaluateRoundOrTrunc(const Document& root, precisionArg.integral()); uassert(51083, str::stream() << "cannot apply " << opName << " with precision value " - << precisionValue - << " value must be in [-20, 100]", + << precisionValue << " value must be in [-20, 100]", minPrecision <= precisionValue && precisionValue <= maxPrecision); } @@ -5163,8 +5109,7 @@ Value ExpressionZip::serialize(bool explain) const { } return Value(DOC("$zip" << DOC("inputs" << Value(serializedInput) << "defaults" - << Value(serializedDefaults) - << "useLongestLength" + << Value(serializedDefaults) << "useLongestLength" << serializedUseLongestLength))); } @@ -5199,9 +5144,10 @@ public: // table[BSONType::NumberDouble][BSONType::NumberDouble] = &performIdentityConversion; table[BSONType::NumberDouble][BSONType::String] = &performFormatDouble; - table[BSONType::NumberDouble] - [BSONType::Bool] = [](const boost::intrusive_ptr<ExpressionContext>& expCtx, - Value inputValue) { return Value(inputValue.coerceToBool()); }; + table[BSONType::NumberDouble][BSONType::Bool] = + [](const boost::intrusive_ptr<ExpressionContext>& expCtx, Value inputValue) { + return Value(inputValue.coerceToBool()); + }; table[BSONType::NumberDouble][BSONType::Date] = &performCastNumberToDate; table[BSONType::NumberDouble][BSONType::NumberInt] = &performCastDoubleToInt; table[BSONType::NumberDouble][BSONType::NumberLong] = &performCastDoubleToLong; @@ -5217,11 +5163,11 @@ public: table[BSONType::String][BSONType::String] = &performIdentityConversion; table[BSONType::String][BSONType::jstOID] = &parseStringToOID; table[BSONType::String][BSONType::Bool] = &performConvertToTrue; - table[BSONType::String][BSONType::Date] = []( - const boost::intrusive_ptr<ExpressionContext>& expCtx, Value inputValue) { - return Value(expCtx->timeZoneDatabase->fromString(inputValue.getStringData(), - mongo::TimeZoneDatabase::utcZone())); - }; + table[BSONType::String][BSONType::Date] = + [](const boost::intrusive_ptr<ExpressionContext>& expCtx, Value inputValue) { + return Value(expCtx->timeZoneDatabase->fromString( + inputValue.getStringData(), mongo::TimeZoneDatabase::utcZone())); + }; table[BSONType::String][BSONType::NumberInt] = &parseStringToNumber<int, 10>; table[BSONType::String][BSONType::NumberLong] = &parseStringToNumber<long long, 10>; table[BSONType::String][BSONType::NumberDecimal] = &parseStringToNumber<Decimal128, 0>; @@ -5278,9 +5224,10 @@ public: inputValue.getDate()); return Value(dateString); }; - table[BSONType::Date] - [BSONType::Bool] = [](const boost::intrusive_ptr<ExpressionContext>& expCtx, - Value inputValue) { return Value(inputValue.coerceToBool()); }; + table[BSONType::Date][BSONType::Bool] = + [](const boost::intrusive_ptr<ExpressionContext>& expCtx, Value inputValue) { + return Value(inputValue.coerceToBool()); + }; table[BSONType::Date][BSONType::Date] = &performIdentityConversion; table[BSONType::Date][BSONType::NumberLong] = [](const boost::intrusive_ptr<ExpressionContext>& expCtx, Value inputValue) { @@ -5303,9 +5250,10 @@ public: [](const boost::intrusive_ptr<ExpressionContext>& expCtx, Value inputValue) { return Value(static_cast<std::string>(str::stream() << inputValue.getInt())); }; - table[BSONType::NumberInt] - [BSONType::Bool] = [](const boost::intrusive_ptr<ExpressionContext>& expCtx, - Value inputValue) { return Value(inputValue.coerceToBool()); }; + table[BSONType::NumberInt][BSONType::Bool] = + [](const boost::intrusive_ptr<ExpressionContext>& expCtx, Value inputValue) { + return Value(inputValue.coerceToBool()); + }; table[BSONType::NumberInt][BSONType::NumberInt] = &performIdentityConversion; table[BSONType::NumberInt][BSONType::NumberLong] = [](const boost::intrusive_ptr<ExpressionContext>& expCtx, Value inputValue) { @@ -5327,9 +5275,10 @@ public: [](const boost::intrusive_ptr<ExpressionContext>& expCtx, Value inputValue) { return Value(static_cast<std::string>(str::stream() << inputValue.getLong())); }; - table[BSONType::NumberLong] - [BSONType::Bool] = [](const boost::intrusive_ptr<ExpressionContext>& expCtx, - Value inputValue) { return Value(inputValue.coerceToBool()); }; + table[BSONType::NumberLong][BSONType::Bool] = + [](const boost::intrusive_ptr<ExpressionContext>& expCtx, Value inputValue) { + return Value(inputValue.coerceToBool()); + }; table[BSONType::NumberLong][BSONType::Date] = &performCastNumberToDate; table[BSONType::NumberLong][BSONType::NumberInt] = &performCastLongToInt; table[BSONType::NumberLong][BSONType::NumberLong] = &performIdentityConversion; @@ -5346,9 +5295,10 @@ public: [](const boost::intrusive_ptr<ExpressionContext>& expCtx, Value inputValue) { return Value(inputValue.getDecimal().toString()); }; - table[BSONType::NumberDecimal] - [BSONType::Bool] = [](const boost::intrusive_ptr<ExpressionContext>& expCtx, - Value inputValue) { return Value(inputValue.coerceToBool()); }; + table[BSONType::NumberDecimal][BSONType::Bool] = + [](const boost::intrusive_ptr<ExpressionContext>& expCtx, Value inputValue) { + return Value(inputValue.coerceToBool()); + }; table[BSONType::NumberDecimal][BSONType::Date] = &performCastNumberToDate; table[BSONType::NumberDecimal][BSONType::NumberInt] = [](const boost::intrusive_ptr<ExpressionContext>& expCtx, Value inputValue) { @@ -5395,8 +5345,7 @@ public: uassert(ErrorCodes::ConversionFailure, str::stream() << "Unsupported conversion from " << typeName(inputType) << " to " - << typeName(targetType) - << " in $convert with no onError value", + << typeName(targetType) << " in $convert with no onError value", foundFunction); return foundFunction; } @@ -5570,8 +5519,7 @@ private: Status parseStatus = NumberParser().base(base)(stringValue, &result); uassert(ErrorCodes::ConversionFailure, str::stream() << "Failed to parse number '" << stringValue - << "' in $convert with no onError value: " - << parseStatus.reason(), + << "' in $convert with no onError value: " << parseStatus.reason(), parseStatus.isOK()); return Value(result); @@ -5586,8 +5534,7 @@ private: // and returned. uasserted(ErrorCodes::ConversionFailure, str::stream() << "Failed to parse objectId '" << inputValue.getString() - << "' in $convert with no onError value: " - << ex.reason()); + << "' in $convert with no onError value: " << ex.reason()); } } @@ -5606,7 +5553,6 @@ Expression::Parser makeConversionAlias(const StringData shortcutName, BSONType t return [=](const intrusive_ptr<ExpressionContext>& expCtx, BSONElement elem, const VariablesParseState& vps) -> intrusive_ptr<Expression> { - // Use parseArguments to allow for a singleton array, or the unwrapped version. auto operands = ExpressionNary::parseArguments(expCtx, elem, vps); @@ -5681,8 +5627,8 @@ intrusive_ptr<Expression> ExpressionConvert::parse( onNull = parseOperand(expCtx, elem, vps); } else { uasserted(ErrorCodes::FailedToParse, - str::stream() << "$convert found an unknown argument: " - << elem.fieldNameStringData()); + str::stream() + << "$convert found an unknown argument: " << elem.fieldNameStringData()); } } @@ -5808,8 +5754,8 @@ auto CommonRegexParse(const boost::intrusive_ptr<ExpressionContext>& expCtx, const VariablesParseState& vpsIn, StringData opName) { uassert(51103, - str::stream() << opName << " expects an object of named arguments but found: " - << expr.type(), + str::stream() << opName + << " expects an object of named arguments but found: " << expr.type(), expr.type() == BSONType::Object); struct { @@ -5881,8 +5827,7 @@ int ExpressionRegex::execute(RegexExecutionState* regexState) const { // capacity is not sufficient to hold all the results. The latter scenario should never occur. uassert(51156, str::stream() << "Error occurred while executing the regular expression in " << _opName - << ". Result code: " - << execResult, + << ". Result code: " << execResult, execResult == -1 || execResult == (regexState->numCaptures + 1)); return execResult; } @@ -6071,7 +6016,7 @@ boost::intrusive_ptr<Expression> ExpressionRegexFind::parse( BSONElement expr, const VariablesParseState& vpsIn) { auto opName = "$regexFind"_sd; - auto[input, regex, options] = CommonRegexParse(expCtx, expr, vpsIn, opName); + auto [input, regex, options] = CommonRegexParse(expCtx, expr, vpsIn, opName); return new ExpressionRegexFind( expCtx, std::move(input), std::move(regex), std::move(options), opName); } @@ -6092,7 +6037,7 @@ boost::intrusive_ptr<Expression> ExpressionRegexFindAll::parse( BSONElement expr, const VariablesParseState& vpsIn) { auto opName = "$regexFindAll"_sd; - auto[input, regex, options] = CommonRegexParse(expCtx, expr, vpsIn, opName); + auto [input, regex, options] = CommonRegexParse(expCtx, expr, vpsIn, opName); return new ExpressionRegexFindAll( expCtx, std::move(input), std::move(regex), std::move(options), opName); } @@ -6153,7 +6098,7 @@ boost::intrusive_ptr<Expression> ExpressionRegexMatch::parse( BSONElement expr, const VariablesParseState& vpsIn) { auto opName = "$regexMatch"_sd; - auto[input, regex, options] = CommonRegexParse(expCtx, expr, vpsIn, opName); + auto [input, regex, options] = CommonRegexParse(expCtx, expr, vpsIn, opName); return new ExpressionRegexMatch( expCtx, std::move(input), std::move(regex), std::move(options), opName); } diff --git a/src/mongo/db/pipeline/expression.h b/src/mongo/db/pipeline/expression.h index 9b54e5e7995..78bd70c5e91 100644 --- a/src/mongo/db/pipeline/expression.h +++ b/src/mongo/db/pipeline/expression.h @@ -369,10 +369,7 @@ public: void validateArguments(const Expression::ExpressionVector& args) const override { uassert(28667, str::stream() << "Expression " << this->getOpName() << " takes at least " << MinArgs - << " arguments, and at most " - << MaxArgs - << ", but " - << args.size() + << " arguments, and at most " << MaxArgs << ", but " << args.size() << " were passed in.", MinArgs <= args.size() && args.size() <= MaxArgs); } @@ -388,9 +385,7 @@ public: void validateArguments(const Expression::ExpressionVector& args) const override { uassert(16020, str::stream() << "Expression " << this->getOpName() << " takes exactly " << NArgs - << " arguments. " - << args.size() - << " were passed in.", + << " arguments. " << args.size() << " were passed in.", args.size() == NArgs); } }; @@ -613,9 +608,7 @@ public: uassert(40533, str::stream() << _opName << " requires a string for the timezone argument, but was given a " - << typeName(timeZoneId.getType()) - << " (" - << timeZoneId.toString() + << typeName(timeZoneId.getType()) << " (" << timeZoneId.toString() << ")", timeZoneId.getType() == BSONType::String); @@ -676,13 +669,12 @@ public: } else { uasserted(40535, str::stream() << "unrecognized option to " << opName << ": \"" - << argName - << "\""); + << argName << "\""); } } uassert(40539, - str::stream() << "missing 'date' argument to " << opName << ", provided: " - << operatorElem, + str::stream() << "missing 'date' argument to " << opName + << ", provided: " << operatorElem, date); return new SubClass(expCtx, std::move(date), std::move(timeZone)); } @@ -2718,4 +2710,4 @@ public: using ExpressionRegex::ExpressionRegex; }; -} +} // namespace mongo diff --git a/src/mongo/db/pipeline/expression_convert_test.cpp b/src/mongo/db/pipeline/expression_convert_test.cpp index acee5cf618b..edd9f1f4ccf 100644 --- a/src/mongo/db/pipeline/expression_convert_test.cpp +++ b/src/mongo/db/pipeline/expression_convert_test.cpp @@ -80,8 +80,7 @@ TEST_F(ExpressionConvertTest, ParseAndSerializeWithOnError) { << "$path1" << "to" << "int" - << "onError" - << 0)); + << "onError" << 0)); auto convertExp = Expression::parseExpression(expCtx, spec, expCtx->variablesParseState); ASSERT_VALUE_EQ( @@ -100,8 +99,7 @@ TEST_F(ExpressionConvertTest, ParseAndSerializeWithOnNull) { << "$path1" << "to" << "int" - << "onNull" - << 0)); + << "onNull" << 0)); auto convertExp = Expression::parseExpression(expCtx, spec, expCtx->variablesParseState); ASSERT_VALUE_EQ( @@ -118,8 +116,7 @@ TEST_F(ExpressionConvertTest, ConvertWithoutInputFailsToParse) { auto spec = BSON("$convert" << BSON("to" << "int" - << "onError" - << 0)); + << "onError" << 0)); ASSERT_THROWS_WITH_CHECK(Expression::parseExpression(expCtx, spec, expCtx->variablesParseState), AssertionException, [](const AssertionException& exception) { @@ -134,8 +131,7 @@ TEST_F(ExpressionConvertTest, ConvertWithoutToFailsToParse) { auto spec = BSON("$convert" << BSON("input" << "$path1" - << "onError" - << 0)); + << "onError" << 0)); ASSERT_THROWS_WITH_CHECK(Expression::parseExpression(expCtx, spec, expCtx->variablesParseState), AssertionException, [](const AssertionException& exception) { @@ -152,8 +148,7 @@ TEST_F(ExpressionConvertTest, InvalidTypeNameFails) { << "$path1" << "to" << "dinosaur" - << "onError" - << 0)); + << "onError" << 0)); auto convertExp = Expression::parseExpression(expCtx, spec, expCtx->variablesParseState); @@ -170,10 +165,7 @@ TEST_F(ExpressionConvertTest, NonIntegralTypeFails) { auto spec = BSON("$convert" << BSON("input" << "$path1" - << "to" - << 3.6 - << "onError" - << 0)); + << "to" << 3.6 << "onError" << 0)); auto convertExp = Expression::parseExpression(expCtx, spec, expCtx->variablesParseState); @@ -195,8 +187,7 @@ TEST_F(ExpressionConvertTest, NonStringNonNumericalTypeFails) { << "to" << BSON("dinosaur" << "Tyrannosaurus rex") - << "onError" - << 0)); + << "onError" << 0)); auto convertExp = Expression::parseExpression(expCtx, spec, expCtx->variablesParseState); @@ -215,10 +206,7 @@ TEST_F(ExpressionConvertTest, InvalidNumericTargetTypeFails) { auto spec = BSON("$convert" << BSON("input" << "$path1" - << "to" - << 100 - << "onError" - << 0)); + << "to" << 100 << "onError" << 0)); auto convertExp = Expression::parseExpression(expCtx, spec, expCtx->variablesParseState); @@ -238,10 +226,7 @@ TEST_F(ExpressionConvertTest, NegativeNumericTargetTypeFails) { auto spec = BSON("$convert" << BSON("input" << "$path1" - << "to" - << -2 - << "onError" - << 0)); + << "to" << -2 << "onError" << 0)); auto convertExp = Expression::parseExpression(expCtx, spec, expCtx->variablesParseState); @@ -297,8 +282,7 @@ TEST_F(ExpressionConvertTest, UnsupportedConversionShouldThrowUnlessOnErrorProvi auto spec = BSON("$convert" << BSON("input" << "$path1" - << "to" - << Value(targetTypeName))); + << "to" << Value(targetTypeName))); Document input{{"path1", inputValue}}; @@ -320,9 +304,7 @@ TEST_F(ExpressionConvertTest, UnsupportedConversionShouldThrowUnlessOnErrorProvi auto spec = BSON("$convert" << BSON("input" << "$path1" - << "to" - << Value(targetTypeName) - << "onError" + << "to" << Value(targetTypeName) << "onError" << "X")); Document input{{"path1", inputValue}}; diff --git a/src/mongo/db/pipeline/expression_date_test.cpp b/src/mongo/db/pipeline/expression_date_test.cpp index 67e798d17af..49099b47b36 100644 --- a/src/mongo/db/pipeline/expression_date_test.cpp +++ b/src/mongo/db/pipeline/expression_date_test.cpp @@ -46,14 +46,10 @@ TEST_F(ExpressionDateFromPartsTest, SerializesToObjectSyntax) { // Test that it serializes to the full format if given an object specification. BSONObj spec = - BSON("$dateFromParts" << BSON( - "year" << 2017 << "month" << 6 << "day" << 27 << "hour" << 14 << "minute" << 37 - << "second" - << 15 - << "millisecond" - << 414 - << "timezone" - << "America/Los_Angeles")); + BSON("$dateFromParts" << BSON("year" << 2017 << "month" << 6 << "day" << 27 << "hour" << 14 + << "minute" << 37 << "second" << 15 << "millisecond" + << 414 << "timezone" + << "America/Los_Angeles")); auto dateExp = Expression::parseExpression(expCtx, spec, expCtx->variablesParseState); auto expectedSerialization = Value(Document{{"$dateFromParts", @@ -84,16 +80,15 @@ TEST_F(ExpressionDateFromPartsTest, OptimizesToConstantIfAllInputsAreConstant) { // Test that it becomes a constant if both year, hour and minute are provided, and are both // expressions which evaluate to constants. spec = BSON("$dateFromParts" << BSON("year" << BSON("$add" << BSON_ARRAY(1900 << 107)) << "hour" - << BSON("$add" << BSON_ARRAY(13 << 1)) - << "minute" + << BSON("$add" << BSON_ARRAY(13 << 1)) << "minute" << BSON("$add" << BSON_ARRAY(40 << 3)))); dateExp = Expression::parseExpression(expCtx, spec, expCtx->variablesParseState); ASSERT(dynamic_cast<ExpressionConstant*>(dateExp->optimize().get())); // Test that it becomes a constant if both year and milliseconds are provided, and year is an // expressions which evaluate to a constant, with milliseconds a constant - spec = BSON("$dateFromParts" << BSON( - "year" << BSON("$add" << BSON_ARRAY(1900 << 107)) << "millisecond" << 514)); + spec = BSON("$dateFromParts" << BSON("year" << BSON("$add" << BSON_ARRAY(1900 << 107)) + << "millisecond" << 514)); dateExp = Expression::parseExpression(expCtx, spec, expCtx->variablesParseState); ASSERT(dynamic_cast<ExpressionConstant*>(dateExp->optimize().get())); @@ -105,11 +100,10 @@ TEST_F(ExpressionDateFromPartsTest, OptimizesToConstantIfAllInputsAreConstant) { // Test that it becomes a constant if both isoWeekYear, isoWeek and isoDayOfWeek are provided, // and are both expressions which evaluate to constants. - spec = BSON("$dateFromParts" << BSON("isoWeekYear" << BSON("$add" << BSON_ARRAY(1017 << 1000)) - << "isoWeek" - << BSON("$add" << BSON_ARRAY(20 << 6)) - << "isoDayOfWeek" - << BSON("$add" << BSON_ARRAY(3 << 2)))); + spec = BSON("$dateFromParts" << BSON("isoWeekYear" + << BSON("$add" << BSON_ARRAY(1017 << 1000)) << "isoWeek" + << BSON("$add" << BSON_ARRAY(20 << 6)) << "isoDayOfWeek" + << BSON("$add" << BSON_ARRAY(3 << 2)))); dateExp = Expression::parseExpression(expCtx, spec, expCtx->variablesParseState); ASSERT(dynamic_cast<ExpressionConstant*>(dateExp->optimize().get())); @@ -117,8 +111,7 @@ TEST_F(ExpressionDateFromPartsTest, OptimizesToConstantIfAllInputsAreConstant) { // year is not a constant. spec = BSON("$dateFromParts" << BSON("year" << "$year" - << "month" - << 6)); + << "month" << 6)); dateExp = Expression::parseExpression(expCtx, spec, expCtx->variablesParseState); ASSERT_FALSE(dynamic_cast<ExpressionConstant*>(dateExp->optimize().get())); @@ -180,8 +173,7 @@ TEST_F(ExpressionDateToPartsTest, SerializesToObjectSyntax) { // Test that it serializes to the full format if given an object specification. BSONObj spec = BSON("$dateToParts" << BSON("date" << Date_t{} << "timezone" << "Europe/London" - << "iso8601" - << false)); + << "iso8601" << false)); auto dateExp = Expression::parseExpression(expCtx, spec, expCtx->variablesParseState); auto expectedSerialization = Value(Document{{"$dateToParts", @@ -224,8 +216,7 @@ TEST_F(ExpressionDateToPartsTest, OptimizesToConstantIfAllInputsAreConstant) { // Test that it becomes a constant if both date and iso8601 are provided, and are both // expressions which evaluate to constants. spec = BSON("$dateToParts" << BSON("date" << BSON("$add" << BSON_ARRAY(Date_t{} << 1000)) - << "iso8601" - << BSON("$not" << false))); + << "iso8601" << BSON("$not" << false))); dateExp = Expression::parseExpression(expCtx, spec, expCtx->variablesParseState); ASSERT(dynamic_cast<ExpressionConstant*>(dateExp->optimize().get())); @@ -305,8 +296,7 @@ TEST_F(DateExpressionTest, ParsingRejectsUnrecognizedFieldsInObjectSpecification for (auto&& expName : dateExpressions) { BSONObj spec = BSON(expName << BSON("date" << Date_t{} << "timezone" << "Europe/London" - << "extra" - << 4)); + << "extra" << 4)); ASSERT_THROWS_CODE(Expression::parseExpression(expCtx, spec, expCtx->variablesParseState), AssertionException, 40535); @@ -561,8 +551,7 @@ TEST_F(DateExpressionTest, DoesResultInNullIfGivenNullishInput) { // Test that the expression results in null if the date and timezone both nullish. spec = BSON(expName << BSON("date" << "$missing" - << "timezone" - << BSONUndefined)); + << "timezone" << BSONUndefined)); dateExp = Expression::parseExpression(expCtx, spec, expCtx->variablesParseState); ASSERT_VALUE_EQ(Value(BSONNULL), dateExp->evaluate(contextDoc, &expCtx->variables)); @@ -619,8 +608,7 @@ TEST_F(ExpressionDateToStringTest, OptimizesToConstantIfAllInputsAreConstant) { // missing. spec = BSON("$dateToString" << BSON("format" << "%Y-%m-%d" - << "date" - << Date_t{})); + << "date" << Date_t{})); dateExp = Expression::parseExpression(expCtx, spec, expCtx->variablesParseState); ASSERT(dynamic_cast<ExpressionConstant*>(dateExp->optimize().get())); @@ -628,9 +616,7 @@ TEST_F(ExpressionDateToStringTest, OptimizesToConstantIfAllInputsAreConstant) { // constants. spec = BSON("$dateToString" << BSON("format" << "%Y-%m-%d" - << "date" - << Date_t{} - << "timezone" + << "date" << Date_t{} << "timezone" << "Europe/Amsterdam")); dateExp = Expression::parseExpression(expCtx, spec, expCtx->variablesParseState); ASSERT(dynamic_cast<ExpressionConstant*>(dateExp->optimize().get())); @@ -639,8 +625,7 @@ TEST_F(ExpressionDateToStringTest, OptimizesToConstantIfAllInputsAreConstant) { // expressions which evaluate to constants. spec = BSON("$dateToString" << BSON("format" << "%Y-%m%d" - << "date" - << BSON("$add" << BSON_ARRAY(Date_t{} << 1000)) + << "date" << BSON("$add" << BSON_ARRAY(Date_t{} << 1000)) << "timezone" << BSON("$concat" << BSON_ARRAY("Europe" << "/" @@ -652,9 +637,7 @@ TEST_F(ExpressionDateToStringTest, OptimizesToConstantIfAllInputsAreConstant) { // 'onNull'. spec = BSON("$dateToString" << BSON("format" << "%Y-%m-%d" - << "date" - << Date_t{} - << "timezone" + << "date" << Date_t{} << "timezone" << "Europe/Amsterdam" << "onNull" << "null default")); @@ -676,9 +659,7 @@ TEST_F(ExpressionDateToStringTest, OptimizesToConstantIfAllInputsAreConstant) { // timezone is not a constant. spec = BSON("$dateToString" << BSON("format" << "%Y-%m-%d" - << "date" - << Date_t{} - << "timezone" + << "date" << Date_t{} << "timezone" << "$tz")); dateExp = Expression::parseExpression(expCtx, spec, expCtx->variablesParseState); ASSERT_FALSE(dynamic_cast<ExpressionConstant*>(dateExp->optimize().get())); @@ -686,9 +667,7 @@ TEST_F(ExpressionDateToStringTest, OptimizesToConstantIfAllInputsAreConstant) { // Test that it does *not* become a constant if 'onNull' does not evaluate to a constant. spec = BSON("$dateToString" << BSON("format" << "%Y-%m-%d" - << "date" - << Date_t{} - << "onNull" + << "date" << Date_t{} << "onNull" << "$onNull")); dateExp = Expression::parseExpression(expCtx, spec, expCtx->variablesParseState); ASSERT_FALSE(dynamic_cast<ExpressionConstant*>(dateExp->optimize().get())); @@ -696,8 +675,7 @@ TEST_F(ExpressionDateToStringTest, OptimizesToConstantIfAllInputsAreConstant) { // Test that it does *not* become a constant if 'format' does not evaluate to a constant. spec = BSON("$dateToString" << BSON("format" << "$format" - << "date" - << Date_t{})); + << "date" << Date_t{})); dateExp = Expression::parseExpression(expCtx, spec, expCtx->variablesParseState); ASSERT_FALSE(dynamic_cast<ExpressionConstant*>(dateExp->optimize().get())); } @@ -707,19 +685,14 @@ TEST_F(ExpressionDateToStringTest, ReturnsOnNullValueWhenInputIsNullish) { auto spec = BSON("$dateToString" << BSON("format" << "%Y-%m-%d" - << "date" - << BSONNULL - << "onNull" + << "date" << BSONNULL << "onNull" << "null default")); auto dateExp = Expression::parseExpression(expCtx, spec, expCtx->variablesParseState); ASSERT_VALUE_EQ(Value("null default"_sd), dateExp->evaluate({}, &expCtx->variables)); spec = BSON("$dateToString" << BSON("format" << "%Y-%m-%d" - << "date" - << BSONNULL - << "onNull" - << BSONNULL)); + << "date" << BSONNULL << "onNull" << BSONNULL)); dateExp = Expression::parseExpression(expCtx, spec, expCtx->variablesParseState); ASSERT_VALUE_EQ(Value(BSONNULL), dateExp->evaluate({}, &expCtx->variables)); @@ -1074,15 +1047,13 @@ TEST_F(ExpressionDateFromStringTest, RejectsNonStringFormat) { auto spec = BSON("$dateFromString" << BSON("dateString" << "2017-07-13T10:02:57" - << "format" - << 2)); + << "format" << 2)); auto dateExp = Expression::parseExpression(expCtx, spec, expCtx->variablesParseState); ASSERT_THROWS_CODE(dateExp->evaluate({}, &expCtx->variables), AssertionException, 40684); spec = BSON("$dateFromString" << BSON("dateString" << "July 4, 2017" - << "format" - << true)); + << "format" << true)); dateExp = Expression::parseExpression(expCtx, spec, expCtx->variablesParseState); ASSERT_THROWS_CODE(dateExp->evaluate({}, &expCtx->variables), AssertionException, 40684); } @@ -1126,8 +1097,7 @@ TEST_F(ExpressionDateFromStringTest, EvaluatesToNullIfFormatIsNullish) { auto spec = BSON("$dateFromString" << BSON("dateString" << "1/1/2017" - << "format" - << BSONNULL)); + << "format" << BSONNULL)); auto dateExp = Expression::parseExpression(expCtx, spec, expCtx->variablesParseState); ASSERT_VALUE_EQ(Value(BSONNULL), dateExp->evaluate({}, &expCtx->variables)); @@ -1140,8 +1110,7 @@ TEST_F(ExpressionDateFromStringTest, EvaluatesToNullIfFormatIsNullish) { spec = BSON("$dateFromString" << BSON("dateString" << "1/1/2017" - << "format" - << BSONUndefined)); + << "format" << BSONUndefined)); dateExp = Expression::parseExpression(expCtx, spec, expCtx->variablesParseState); ASSERT_VALUE_EQ(Value(BSONNULL), dateExp->evaluate({}, &expCtx->variables)); } @@ -1265,8 +1234,7 @@ TEST_F(ExpressionDateFromStringTest, InvalidFormatTakesPrecedenceOverOnNull) { auto spec = BSON("$dateFromString" << BSON("dateString" << BSONNULL << "onNull" << "Null default" - << "format" - << 5)); + << "format" << 5)); auto dateExp = Expression::parseExpression(expCtx, spec, expCtx->variablesParseState); ASSERT_THROWS_CODE(dateExp->evaluate({}, &expCtx->variables), AssertionException, 40684); @@ -1285,8 +1253,7 @@ TEST_F(ExpressionDateFromStringTest, InvalidFormatTakesPrecedenceOverOnError) { << "Invalid dateString" << "onError" << "Not used default" - << "format" - << 5)); + << "format" << 5)); auto dateExp = Expression::parseExpression(expCtx, spec, expCtx->variablesParseState); ASSERT_THROWS_CODE(dateExp->evaluate({}, &expCtx->variables), AssertionException, 40684); @@ -1303,8 +1270,7 @@ TEST_F(ExpressionDateFromStringTest, InvalidTimezoneTakesPrecedenceOverOnNull) { auto spec = BSON("$dateFromString" << BSON("dateString" << BSONNULL << "onNull" << "Null default" - << "timezone" - << 5)); + << "timezone" << 5)); auto dateExp = Expression::parseExpression(expCtx, spec, expCtx->variablesParseState); ASSERT_THROWS_CODE(dateExp->evaluate({}, &expCtx->variables), AssertionException, 40517); @@ -1323,8 +1289,7 @@ TEST_F(ExpressionDateFromStringTest, InvalidTimezoneTakesPrecedenceOverOnError) << "Invalid dateString" << "onError" << "On error default" - << "timezone" - << 5)); + << "timezone" << 5)); auto dateExp = Expression::parseExpression(expCtx, spec, expCtx->variablesParseState); ASSERT_THROWS_CODE(dateExp->evaluate({}, &expCtx->variables), AssertionException, 40517); @@ -1341,15 +1306,13 @@ TEST_F(ExpressionDateFromStringTest, OnNullTakesPrecedenceOverOtherNullishParame auto spec = BSON("$dateFromString" << BSON("dateString" << BSONNULL << "onNull" << "Null default" - << "timezone" - << BSONNULL)); + << "timezone" << BSONNULL)); auto dateExp = Expression::parseExpression(expCtx, spec, expCtx->variablesParseState); ASSERT_VALUE_EQ(Value("Null default"_sd), dateExp->evaluate({}, &expCtx->variables)); spec = BSON("$dateFromString" << BSON("dateString" << BSONNULL << "onNull" << "Null default" - << "format" - << BSONNULL)); + << "format" << BSONNULL)); dateExp = Expression::parseExpression(expCtx, spec, expCtx->variablesParseState); ASSERT_VALUE_EQ(Value("Null default"_sd), dateExp->evaluate({}, &expCtx->variables)); } @@ -1361,8 +1324,7 @@ TEST_F(ExpressionDateFromStringTest, OnNullOnlyUsedIfInputStringIsNullish) { << "2018-02-14" << "onNull" << "Null default" - << "timezone" - << BSONNULL)); + << "timezone" << BSONNULL)); auto dateExp = Expression::parseExpression(expCtx, spec, expCtx->variablesParseState); ASSERT_VALUE_EQ(Value(BSONNULL), dateExp->evaluate({}, &expCtx->variables)); @@ -1370,8 +1332,7 @@ TEST_F(ExpressionDateFromStringTest, OnNullOnlyUsedIfInputStringIsNullish) { << "2018-02-14" << "onNull" << "Null default" - << "format" - << BSONNULL)); + << "format" << BSONNULL)); dateExp = Expression::parseExpression(expCtx, spec, expCtx->variablesParseState); ASSERT_VALUE_EQ(Value(BSONNULL), dateExp->evaluate({}, &expCtx->variables)); } @@ -1406,10 +1367,10 @@ TEST_F(ExpressionDateFromStringTest, ReturnsOnErrorForFormatMismatch) { TEST_F(ExpressionDateFromStringTest, OnNullEvaluatedLazily) { auto expCtx = getExpCtx(); - auto spec = BSON("$dateFromString" << BSON("dateString" - << "$date" - << "onNull" - << BSON("$divide" << BSON_ARRAY(1 << 0)))); + auto spec = + BSON("$dateFromString" << BSON("dateString" + << "$date" + << "onNull" << BSON("$divide" << BSON_ARRAY(1 << 0)))); auto dateExp = Expression::parseExpression(expCtx, spec, expCtx->variablesParseState); ASSERT_EQ( "2018-02-14T00:00:00.000Z", @@ -1420,10 +1381,10 @@ TEST_F(ExpressionDateFromStringTest, OnNullEvaluatedLazily) { TEST_F(ExpressionDateFromStringTest, OnErrorEvaluatedLazily) { auto expCtx = getExpCtx(); - auto spec = BSON("$dateFromString" << BSON("dateString" - << "$date" - << "onError" - << BSON("$divide" << BSON_ARRAY(1 << 0)))); + auto spec = + BSON("$dateFromString" << BSON("dateString" + << "$date" + << "onError" << BSON("$divide" << BSON_ARRAY(1 << 0)))); auto dateExp = Expression::parseExpression(expCtx, spec, expCtx->variablesParseState); ASSERT_EQ( "2018-02-14T00:00:00.000Z", diff --git a/src/mongo/db/pipeline/expression_test.cpp b/src/mongo/db/pipeline/expression_test.cpp index 34cd1a61335..98800c2af63 100644 --- a/src/mongo/db/pipeline/expression_test.cpp +++ b/src/mongo/db/pipeline/expression_test.cpp @@ -47,13 +47,13 @@ namespace ExpressionTests { using boost::intrusive_ptr; using std::initializer_list; +using std::list; using std::numeric_limits; using std::pair; using std::set; using std::sort; using std::string; using std::vector; -using std::list; /** * Creates an expression given by 'expressionName' and evaluates it using @@ -590,8 +590,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); } @@ -737,12 +737,10 @@ TEST(ExpressionArrayToObjectTest, KVFormatSimple) { assertExpectedResults("$arrayToObject", {{{Value(BSON_ARRAY(BSON("k" << "key1" - << "v" - << 2) + << "v" << 2) << BSON("k" << "key2" - << "v" - << 3)))}, + << "v" << 3)))}, {Value(BSON("key1" << 2 << "key2" << 3))}}}); } @@ -750,12 +748,10 @@ TEST(ExpressionArrayToObjectTest, KVFormatWithDuplicates) { assertExpectedResults("$arrayToObject", {{{Value(BSON_ARRAY(BSON("k" << "hi" - << "v" - << 2) + << "v" << 2) << BSON("k" << "hi" - << "v" - << 3)))}, + << "v" << 3)))}, {Value(BSON("hi" << 3))}}}); } @@ -1888,8 +1884,7 @@ 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" @@ -1901,8 +1896,7 @@ 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); @@ -3261,8 +3255,7 @@ TEST(ExpressionObjectParse, ShouldAcceptLiteralsAsValues) { auto object = ExpressionObject::parse(expCtx, BSON("a" << 5 << "b" << "string" - << "c" - << BSONNULL), + << "c" << BSONNULL), vps); auto expectedResult = Value(Document{{"a", literal(5)}, {"b", literal("string"_sd)}, {"c", literal(BSONNULL)}}); @@ -3386,10 +3379,10 @@ auto expressionObjectCreateHelper( expressionsWithChildrenInPlace) { std::vector<boost::intrusive_ptr<Expression>> children; std::vector<std::pair<std::string, boost::intrusive_ptr<Expression>&>> expressions; - for (auto & [ unused, expression ] : expressionsWithChildrenInPlace) + for (auto& [unused, expression] : expressionsWithChildrenInPlace) children.push_back(std::move(expression)); std::vector<boost::intrusive_ptr<Expression>>::size_type index = 0; - for (auto & [ fieldName, unused ] : expressionsWithChildrenInPlace) { + for (auto& [fieldName, unused] : expressionsWithChildrenInPlace) { expressions.emplace_back(fieldName, children[index]); ++index; } @@ -3840,8 +3833,7 @@ 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); @@ -3852,8 +3844,7 @@ 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" @@ -4174,12 +4165,9 @@ 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>())); } }; @@ -4187,12 +4175,9 @@ 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>())); } }; @@ -4201,11 +4186,8 @@ 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>())); } }; @@ -4213,12 +4195,9 @@ 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))); } }; @@ -4226,12 +4205,9 @@ 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))); } }; @@ -4239,12 +4215,9 @@ 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>())); } }; @@ -4252,12 +4225,9 @@ 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>())); } }; @@ -4265,12 +4235,9 @@ 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))); } }; @@ -4278,12 +4245,9 @@ 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))); } }; @@ -4291,8 +4255,7 @@ 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) + << "$setDifference" << BSONNULL) << "error" << DOC_ARRAY("$setEquals"_sd << "$setIsSubset"_sd)); @@ -4303,8 +4266,7 @@ 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) + << "$setDifference" << BSONNULL) << "error" << DOC_ARRAY("$setEquals"_sd << "$setIsSubset"_sd)); @@ -4315,8 +4277,7 @@ class LeftNullAndRightEmpty : public ExpectedResultBase { Document getSpec() { return DOC("input" << DOC_ARRAY(Value(BSONNULL) << vector<Value>()) << "expected" << DOC("$setIntersection" << BSONNULL << "$setUnion" << BSONNULL - << "$setDifference" - << BSONNULL) + << "$setDifference" << BSONNULL) << "error" << DOC_ARRAY("$setEquals"_sd << "$setIsSubset"_sd)); @@ -4327,8 +4288,7 @@ class RightNullAndLeftEmpty : public ExpectedResultBase { Document getSpec() { return DOC("input" << DOC_ARRAY(vector<Value>() << Value(BSONNULL)) << "expected" << DOC("$setIntersection" << BSONNULL << "$setUnion" << BSONNULL - << "$setDifference" - << BSONNULL) + << "$setDifference" << BSONNULL) << "error" << DOC_ARRAY("$setEquals"_sd << "$setIsSubset"_sd)); @@ -4375,12 +4335,8 @@ 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>())); } }; @@ -4389,45 +4345,39 @@ 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))); } }; class ManyArgs : public ExpectedResultBase { Document getSpec() { - return DOC( - "input" << DOC_ARRAY(DOC_ARRAY(8 << 3) << DOC_ARRAY("asdf"_sd - << "foo"_sd) - << DOC_ARRAY(80.3 << 34) - << vector<Value>() - << DOC_ARRAY(80.3 << "foo"_sd << 11 << "yay"_sd)) - << "expected" - << DOC("$setIntersection" << vector<Value>() << "$setEquals" << false - << "$setUnion" - << DOC_ARRAY(3 << 8 << 11 << 34 << 80.3 << "asdf"_sd - << "foo"_sd - << "yay"_sd)) - << "error" - << DOC_ARRAY("$setIsSubset"_sd - << "$setDifference"_sd)); + return DOC("input" << DOC_ARRAY(DOC_ARRAY(8 << 3) + << DOC_ARRAY("asdf"_sd + << "foo"_sd) + << DOC_ARRAY(80.3 << 34) << vector<Value>() + << DOC_ARRAY(80.3 << "foo"_sd << 11 << "yay"_sd)) + << "expected" + << DOC("$setIntersection" + << vector<Value>() << "$setEquals" << false << "$setUnion" + << DOC_ARRAY(3 << 8 << 11 << 34 << 80.3 << "asdf"_sd + << "foo"_sd + << "yay"_sd)) + << "error" + << DOC_ARRAY("$setIsSubset"_sd + << "$setDifference"_sd)); } }; 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)) + 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" + << true << "$setUnion" << DOC_ARRAY(1 << 2 << 4)) << "error" << DOC_ARRAY("$setIsSubset"_sd @@ -4714,7 +4664,7 @@ TEST(ExpressionSubstrTest, ThrowsWithNegativeStart) { ASSERT_THROWS([&] { expr->evaluate({}, &expCtx->variables); }(), AssertionException); } -} // namespace Substr +} // namespace SubstrBytes namespace SubstrCP { @@ -4829,8 +4779,7 @@ TEST(ExpressionTrimParsingTest, ThrowsIfSpecContainsUnrecognizedField) { ASSERT_THROWS(Expression::parseExpression(expCtx, BSON("$ltrim" << BSON("chars" << "xyz" - << "other" - << 1)), + << "other" << 1)), expCtx->variablesParseState), AssertionException); ASSERT_THROWS(Expression::parseExpression(expCtx, @@ -4838,8 +4787,7 @@ TEST(ExpressionTrimParsingTest, ThrowsIfSpecContainsUnrecognizedField) { << "$x" << "chars" << "xyz" - << "other" - << 1)), + << "other" << 1)), expCtx->variablesParseState), AssertionException); } @@ -5357,8 +5305,7 @@ TEST(ExpressionTrimTest, DoesOptimizeToConstantWithCustomChars) { expCtx, BSON("$trim" << BSON("input" << " abc " - << "chars" - << BSON("$substrCP" << BSON_ARRAY(" " << 1 << 1)))), + << "chars" << BSON("$substrCP" << BSON_ARRAY(" " << 1 << 1)))), expCtx->variablesParseState); optimized = trim->optimize(); constant = dynamic_cast<ExpressionConstant*>(optimized.get()); @@ -5903,8 +5850,9 @@ class FalseViaInt : public ExpectedResultBase { class Null : public ExpectedResultBase { Document getSpec() { - return DOC("input" << DOC_ARRAY(BSONNULL) << "error" << DOC_ARRAY("$allElementsTrue"_sd - << "$anyElementTrue"_sd)); + return DOC("input" << DOC_ARRAY(BSONNULL) << "error" + << DOC_ARRAY("$allElementsTrue"_sd + << "$anyElementTrue"_sd)); } }; @@ -6491,5 +6439,5 @@ TEST(NowAndClusterTime, BasicTest) { ASSERT_VALUE_EQ(result, Value{true}); } } -} +} // namespace NowAndClusterTime } // namespace ExpressionTests diff --git a/src/mongo/db/pipeline/expression_trigonometric.h b/src/mongo/db/pipeline/expression_trigonometric.h index 41f10ca2e29..cc8ca852f8b 100644 --- a/src/mongo/db/pipeline/expression_trigonometric.h +++ b/src/mongo/db/pipeline/expression_trigonometric.h @@ -135,12 +135,8 @@ public: void assertBounds(T input) const { uassert(50989, str::stream() << "cannot apply " << getOpName() << " to " << toString(input) - << ", value must in " - << BoundType::leftBracket() - << getLowerBound() - << "," - << getUpperBound() - << BoundType::rightBracket(), + << ", value must in " << BoundType::leftBracket() << getLowerBound() + << "," << getUpperBound() << BoundType::rightBracket(), checkBounds(input)); } diff --git a/src/mongo/db/pipeline/expression_trigonometric_test.cpp b/src/mongo/db/pipeline/expression_trigonometric_test.cpp index 49ea60e1f9b..b9356e60bae 100644 --- a/src/mongo/db/pipeline/expression_trigonometric_test.cpp +++ b/src/mongo/db/pipeline/expression_trigonometric_test.cpp @@ -1403,4 +1403,4 @@ TEST(ExpressionDegreesToRadiansTest, DecimalArg) { TEST(ExpressionDegreesToRadiansTest, NullArg) { assertEvaluates("$degreesToRadians", Value(BSONNULL), Value(BSONNULL)); } -} // namespace expression_trigonometric_test +} // namespace expression_tests diff --git a/src/mongo/db/pipeline/field_path.cpp b/src/mongo/db/pipeline/field_path.cpp index bb26fc478ca..4c9e23a86df 100644 --- a/src/mongo/db/pipeline/field_path.cpp +++ b/src/mongo/db/pipeline/field_path.cpp @@ -81,4 +81,4 @@ void FieldPath::uassertValidFieldName(StringData fieldName) { uassert( 16412, "FieldPath field names may not contain '.'.", fieldName.find('.') == string::npos); } -} +} // namespace mongo diff --git a/src/mongo/db/pipeline/field_path.h b/src/mongo/db/pipeline/field_path.h index 347b236fb6b..bbc775be9db 100644 --- a/src/mongo/db/pipeline/field_path.h +++ b/src/mongo/db/pipeline/field_path.h @@ -136,4 +136,4 @@ inline bool operator<(const FieldPath& lhs, const FieldPath& rhs) { inline bool operator==(const FieldPath& lhs, const FieldPath& rhs) { return lhs.fullPath() == rhs.fullPath(); } -} +} // namespace mongo diff --git a/src/mongo/db/pipeline/granularity_rounder_preferred_numbers_test.cpp b/src/mongo/db/pipeline/granularity_rounder_preferred_numbers_test.cpp index 6db3d45ea78..56164da1b21 100644 --- a/src/mongo/db/pipeline/granularity_rounder_preferred_numbers_test.cpp +++ b/src/mongo/db/pipeline/granularity_rounder_preferred_numbers_test.cpp @@ -106,13 +106,9 @@ void testRoundingUpInSeries(intrusive_ptr<GranularityRounder> rounder) { testEquals(roundedValue, expectedValue); } catch (...) { FAIL(str::stream() << "The GranularityRounder for " << rounder->getName() - << " failed rounding up the value " - << input.coerceToDouble() - << " at multiplier level " - << multiplier - << ". Expected " - << expectedValue.coerceToDouble() - << ", but got " + << " failed rounding up the value " << input.coerceToDouble() + << " at multiplier level " << multiplier << ". Expected " + << expectedValue.coerceToDouble() << ", but got " << roundedValue.coerceToDouble()); } } @@ -140,15 +136,12 @@ void testRoundingUpInSeriesDecimal(intrusive_ptr<GranularityRounder> rounder) { try { testEquals(roundedValue, expectedValue); } catch (...) { - FAIL(str::stream() << "The GranularityRounder for " << rounder->getName() - << " failed rounding up the value " - << input.coerceToDecimal().toString() - << " at multiplier level " - << multiplier.toString() - << ". Expected " - << expectedValue.coerceToDecimal().toString() - << ", but got " - << roundedValue.coerceToDecimal().toString()); + FAIL(str::stream() + << "The GranularityRounder for " << rounder->getName() + << " failed rounding up the value " << input.coerceToDecimal().toString() + << " at multiplier level " << multiplier.toString() << ". Expected " + << expectedValue.coerceToDecimal().toString() << ", but got " + << roundedValue.coerceToDecimal().toString()); } } multiplier = multiplier.multiply(Decimal128(10)); @@ -175,15 +168,11 @@ void testRoundingUpBetweenSeries(intrusive_ptr<GranularityRounder> rounder) { try { testEquals(roundedValue, expectedValue); } catch (...) { - FAIL(str::stream() << "The GranularityRounder for " << rounder->getName() - << " failed rounding up the value " - << middle - << " at multiplier level " - << multiplier - << ". Expected " - << expectedValue.coerceToDouble() - << ", but got " - << roundedValue.coerceToDouble()); + FAIL(str::stream() + << "The GranularityRounder for " << rounder->getName() + << " failed rounding up the value " << middle << " at multiplier level " + << multiplier << ". Expected " << expectedValue.coerceToDouble() + << ", but got " << roundedValue.coerceToDouble()); } } multiplier *= 10.0; @@ -212,14 +201,10 @@ void testRoundingUpBetweenSeriesDecimal(intrusive_ptr<GranularityRounder> rounde testEquals(roundedValue, expectedValue); } catch (...) { FAIL(str::stream() << "The GranularityRounder for " << rounder->getName() - << " failed rounding up the value " - << middle.toString() - << " at multiplier level " - << multiplier.toString() - << ". Expected " - << expectedValue.coerceToDecimal().toString() - << ", but got " - << roundedValue.coerceToDecimal().toString()); + << " failed rounding up the value " << middle.toString() + << " at multiplier level " << multiplier.toString() + << ". Expected " << expectedValue.coerceToDecimal().toString() + << ", but got " << roundedValue.coerceToDecimal().toString()); } } multiplier = multiplier.multiply(Decimal128(10)); @@ -244,13 +229,9 @@ void testRoundingDownInSeries(intrusive_ptr<GranularityRounder> rounder) { testEquals(roundedValue, expectedValue); } catch (...) { FAIL(str::stream() << "The GranularityRounder for " << rounder->getName() - << " failed rounding down the value " - << input.coerceToDouble() - << " at multiplier level " - << multiplier - << ". Expected " - << expectedValue.coerceToDouble() - << ", but got " + << " failed rounding down the value " << input.coerceToDouble() + << " at multiplier level " << multiplier << ". Expected " + << expectedValue.coerceToDouble() << ", but got " << roundedValue.coerceToDouble()); } } @@ -277,15 +258,12 @@ void testRoundingDownInSeriesDecimal(intrusive_ptr<GranularityRounder> rounder) try { testEquals(roundedValue, expectedValue); } catch (...) { - FAIL(str::stream() << "The GranularityRounder for " << rounder->getName() - << " failed rounding down the value " - << input.coerceToDecimal().toString() - << " at multiplier level " - << multiplier.toString() - << ". Expected " - << expectedValue.coerceToDecimal().toString() - << ", but got " - << roundedValue.coerceToDecimal().toString()); + FAIL(str::stream() + << "The GranularityRounder for " << rounder->getName() + << " failed rounding down the value " << input.coerceToDecimal().toString() + << " at multiplier level " << multiplier.toString() << ". Expected " + << expectedValue.coerceToDecimal().toString() << ", but got " + << roundedValue.coerceToDecimal().toString()); } } multiplier = multiplier.multiply(Decimal128(10)); @@ -312,15 +290,11 @@ void testRoundingDownBetweenSeries(intrusive_ptr<GranularityRounder> rounder) { try { testEquals(roundedValue, expectedValue); } catch (...) { - FAIL(str::stream() << "The GranularityRounder for " << rounder->getName() - << " failed rounding down the value " - << middle - << " at multiplier level " - << multiplier - << ". Expected " - << expectedValue.coerceToDouble() - << ", but got " - << roundedValue.coerceToDouble()); + FAIL(str::stream() + << "The GranularityRounder for " << rounder->getName() + << " failed rounding down the value " << middle << " at multiplier level " + << multiplier << ". Expected " << expectedValue.coerceToDouble() + << ", but got " << roundedValue.coerceToDouble()); } } multiplier *= 10.0; @@ -349,14 +323,10 @@ void testRoundingDownBetweenSeriesDecimal(intrusive_ptr<GranularityRounder> roun testEquals(roundedValue, expectedValue); } catch (...) { FAIL(str::stream() << "The GranularityRounder for " << rounder->getName() - << " failed rounding down the value " - << middle.toString() - << " at multiplier level " - << multiplier.toString() - << ". Expected " - << expectedValue.coerceToDecimal().toString() - << ", but got " - << roundedValue.coerceToDecimal().toString()); + << " failed rounding down the value " << middle.toString() + << " at multiplier level " << multiplier.toString() + << ". Expected " << expectedValue.coerceToDecimal().toString() + << ", but got " << roundedValue.coerceToDecimal().toString()); } } multiplier = multiplier.multiply(Decimal128(10)); @@ -383,13 +353,9 @@ void testSeriesWrappingAround(intrusive_ptr<GranularityRounder> rounder) { testEquals(roundedValue, expectedValue); } catch (...) { FAIL(str::stream() << "The GranularityRounder for " << rounder->getName() - << " failed rounding up the value " - << input.coerceToDouble() - << " at multiplier level " - << multiplier - << ". Expected " - << expectedValue.coerceToDouble() - << ", but got " + << " failed rounding up the value " << input.coerceToDouble() + << " at multiplier level " << multiplier << ". Expected " + << expectedValue.coerceToDouble() << ", but got " << roundedValue.coerceToDouble()); } @@ -400,13 +366,9 @@ void testSeriesWrappingAround(intrusive_ptr<GranularityRounder> rounder) { testEquals(roundedValue, expectedValue); } catch (...) { FAIL(str::stream() << "The GranularityRounder for " << rounder->getName() - << " failed rounding down the value " - << input.coerceToDouble() - << " at multiplier level " - << multiplier - << ". Expected " - << expectedValue.coerceToDouble() - << ", but got " + << " failed rounding down the value " << input.coerceToDouble() + << " at multiplier level " << multiplier << ". Expected " + << expectedValue.coerceToDouble() << ", but got " << roundedValue.coerceToDouble()); } multiplier *= 10.0; @@ -430,12 +392,9 @@ void testSeriesWrappingAroundDecimal(intrusive_ptr<GranularityRounder> rounder) } catch (...) { FAIL(str::stream() << "The GranularityRounder for " << rounder->getName() << " failed rounding up the value " - << input.coerceToDecimal().toString() - << " at multiplier level " - << multiplier.toString() - << ". Expected " - << expectedValue.coerceToDecimal().toString() - << ", but got " + << input.coerceToDecimal().toString() << " at multiplier level " + << multiplier.toString() << ". Expected " + << expectedValue.coerceToDecimal().toString() << ", but got " << roundedValue.coerceToDecimal().toString()); } @@ -449,12 +408,9 @@ void testSeriesWrappingAroundDecimal(intrusive_ptr<GranularityRounder> rounder) } catch (...) { FAIL(str::stream() << "The GranularityRounder for " << rounder->getName() << " failed rounding down the value " - << input.coerceToDecimal().toString() - << " at multiplier level " - << multiplier.toString() - << ". Expected " - << expectedValue.coerceToDecimal().toString() - << ", but got " + << input.coerceToDecimal().toString() << " at multiplier level " + << multiplier.toString() << ". Expected " + << expectedValue.coerceToDecimal().toString() << ", but got " << roundedValue.coerceToDecimal().toString()); } multiplier.multiply(Decimal128(10)); diff --git a/src/mongo/db/pipeline/lite_parsed_document_source.cpp b/src/mongo/db/pipeline/lite_parsed_document_source.cpp index 87aebb72238..28b5b133a65 100644 --- a/src/mongo/db/pipeline/lite_parsed_document_source.cpp +++ b/src/mongo/db/pipeline/lite_parsed_document_source.cpp @@ -61,4 +61,4 @@ std::unique_ptr<LiteParsedDocumentSource> LiteParsedDocumentSource::parse( return it->second(request, specElem); } -} +} // namespace mongo diff --git a/src/mongo/db/pipeline/lite_parsed_pipeline.cpp b/src/mongo/db/pipeline/lite_parsed_pipeline.cpp index b1802c91970..81a10467a58 100644 --- a/src/mongo/db/pipeline/lite_parsed_pipeline.cpp +++ b/src/mongo/db/pipeline/lite_parsed_pipeline.cpp @@ -54,8 +54,7 @@ void LiteParsedPipeline::assertSupportsReadConcern( uassert(ErrorCodes::InvalidOptions, str::stream() << "Explain for the aggregate command cannot run with a readConcern " << "other than 'local', or in a multi-document transaction. Current " - << "readConcern: " - << readConcern.toString(), + << "readConcern: " << readConcern.toString(), !explain || readConcern.getLevel() == repl::ReadConcernLevel::kLocalReadConcern); for (auto&& spec : _stageSpecs) { diff --git a/src/mongo/db/pipeline/lookup_set_cache.h b/src/mongo/db/pipeline/lookup_set_cache.h index 11c28852f34..54b75d03934 100644 --- a/src/mongo/db/pipeline/lookup_set_cache.h +++ b/src/mongo/db/pipeline/lookup_set_cache.h @@ -47,10 +47,10 @@ namespace mongo { using boost::multi_index_container; -using boost::multi_index::sequenced; using boost::multi_index::hashed_unique; -using boost::multi_index::member; using boost::multi_index::indexed_by; +using boost::multi_index::member; +using boost::multi_index::sequenced; /** * A least-recently-used cache from key to a vector of values. It does not implement any default diff --git a/src/mongo/db/pipeline/mongos_process_interface.cpp b/src/mongo/db/pipeline/mongos_process_interface.cpp index d91233c52db..05395e2c7ca 100644 --- a/src/mongo/db/pipeline/mongos_process_interface.cpp +++ b/src/mongo/db/pipeline/mongos_process_interface.cpp @@ -227,15 +227,12 @@ boost::optional<Document> MongoSInterface::lookupSingleDocument( uassert(ErrorCodes::InternalError, str::stream() << "Shard cursor was unexpectedly open after lookup: " << shardResult.front().getHostAndPort() - << ", id: " - << cursor.getCursorId(), + << ", id: " << cursor.getCursorId(), cursor.getCursorId() == 0); uassert(ErrorCodes::TooManyMatchingDocuments, str::stream() << "found more than one document matching " << filter.toString() << " [" - << batch.begin()->toString() - << ", " - << std::next(batch.begin())->toString() - << "]", + << batch.begin()->toString() << ", " + << std::next(batch.begin())->toString() << "]", batch.size() <= 1u); return (!batch.empty() ? Document(batch.front()) : boost::optional<Document>{}); diff --git a/src/mongo/db/pipeline/parsed_aggregation_projection.cpp b/src/mongo/db/pipeline/parsed_aggregation_projection.cpp index 058e20b6d0b..75e0a95cd5d 100644 --- a/src/mongo/db/pipeline/parsed_aggregation_projection.cpp +++ b/src/mongo/db/pipeline/parsed_aggregation_projection.cpp @@ -81,11 +81,7 @@ void ProjectionSpecValidator::ensurePathDoesNotConflictOrThrow(const std::string uassert(40176, str::stream() << "specification contains two conflicting paths. " "Cannot specify both '" - << path - << "' and '" - << *conflictingPath - << "': " - << _rawObj.toString(), + << path << "' and '" << *conflictingPath << "': " << _rawObj.toString(), !conflictingPath); } @@ -124,10 +120,8 @@ void ProjectionSpecValidator::parseNestedObject(const BSONObj& thisLevelSpec, uasserted(40181, str::stream() << "an expression specification must contain exactly " "one field, the name of the expression. Found " - << thisLevelSpec.nFields() - << " fields in " - << thisLevelSpec.toString() - << ", while parsing object " + << thisLevelSpec.nFields() << " fields in " + << thisLevelSpec.toString() << ", while parsing object " << _rawObj.toString()); } ensurePathDoesNotConflictOrThrow(prefix.fullPath()); @@ -136,8 +130,7 @@ void ProjectionSpecValidator::parseNestedObject(const BSONObj& thisLevelSpec, if (fieldName.find('.') != std::string::npos) { uasserted(40183, str::stream() << "cannot use dotted field name '" << fieldName - << "' in a sub object: " - << _rawObj.toString()); + << "' in a sub object: " << _rawObj.toString()); } parseElement(elem, FieldPath::getFullyQualifiedPath(prefix.fullPath(), fieldName)); } @@ -240,23 +233,25 @@ private: } else if ((elem.isBoolean() || elem.isNumber()) && !elem.trueValue()) { // If this is an excluded field other than '_id', ensure that the projection type has // not already been set to kInclusionProjection. - uassert(40178, - str::stream() << "Bad projection specification, cannot exclude fields " - "other than '_id' in an inclusion projection: " - << _rawObj.toString(), - !_parsedType || (*_parsedType == - TransformerInterface::TransformerType::kExclusionProjection)); + uassert( + 40178, + str::stream() << "Bad projection specification, cannot exclude fields " + "other than '_id' in an inclusion projection: " + << _rawObj.toString(), + !_parsedType || + (*_parsedType == TransformerInterface::TransformerType::kExclusionProjection)); _parsedType = TransformerInterface::TransformerType::kExclusionProjection; } else { // A boolean true, a truthy numeric value, or any expression can only be used with an // inclusion projection. Note that literal values like "string" or null are also treated // as expressions. - uassert(40179, - str::stream() << "Bad projection specification, cannot include fields or " - "add computed fields during an exclusion projection: " - << _rawObj.toString(), - !_parsedType || (*_parsedType == - TransformerInterface::TransformerType::kInclusionProjection)); + uassert( + 40179, + str::stream() << "Bad projection specification, cannot include fields or " + "add computed fields during an exclusion projection: " + << _rawObj.toString(), + !_parsedType || + (*_parsedType == TransformerInterface::TransformerType::kInclusionProjection)); _parsedType = TransformerInterface::TransformerType::kInclusionProjection; } } diff --git a/src/mongo/db/pipeline/parsed_aggregation_projection_test.cpp b/src/mongo/db/pipeline/parsed_aggregation_projection_test.cpp index 15efa442726..27ce39b9c86 100644 --- a/src/mongo/db/pipeline/parsed_aggregation_projection_test.cpp +++ b/src/mongo/db/pipeline/parsed_aggregation_projection_test.cpp @@ -149,15 +149,13 @@ TEST(ParsedAggregationProjectionErrors, ShouldRejectPathConflictsWithNonAlphaNum // Then assert that we throw when we introduce a prefixed field. ASSERT_THROWS( - makeProjectionWithDefaultPolicies( - BSON("a.b-c" << true << "a.b" << true << "a.b?c" << true << "a.b c" << true << "a.b.d" - << true)), - AssertionException); - ASSERT_THROWS( - makeProjectionWithDefaultPolicies(BSON( - "a.b.d" << false << "a.b c" << false << "a.b?c" << false << "a.b" << false << "a.b-c" - << false)), + makeProjectionWithDefaultPolicies(BSON("a.b-c" << true << "a.b" << true << "a.b?c" << true + << "a.b c" << true << "a.b.d" << true)), AssertionException); + ASSERT_THROWS(makeProjectionWithDefaultPolicies(BSON("a.b.d" << false << "a.b c" << false + << "a.b?c" << false << "a.b" + << false << "a.b-c" << false)), + AssertionException); // Adding the same field twice. ASSERT_THROWS(makeProjectionWithDefaultPolicies( @@ -168,34 +166,24 @@ TEST(ParsedAggregationProjectionErrors, ShouldRejectPathConflictsWithNonAlphaNum AssertionException); // Mix of include/exclude and adding a shared prefix. - ASSERT_THROWS( - makeProjectionWithDefaultPolicies( - BSON("a.b-c" << true << "a.b" << wrapInLiteral(1) << "a.b?c" << true << "a.b c" << true - << "a.b.d" - << true)), - AssertionException); + ASSERT_THROWS(makeProjectionWithDefaultPolicies( + BSON("a.b-c" << true << "a.b" << wrapInLiteral(1) << "a.b?c" << true + << "a.b c" << true << "a.b.d" << true)), + AssertionException); ASSERT_THROWS(makeProjectionWithDefaultPolicies( BSON("a.b.d" << false << "a.b c" << false << "a.b?c" << false << "a.b" - << wrapInLiteral(0) - << "a.b-c" - << false)), + << wrapInLiteral(0) << "a.b-c" << false)), AssertionException); // Adding a shared prefix twice. ASSERT_THROWS(makeProjectionWithDefaultPolicies( BSON("a.b-c" << wrapInLiteral(1) << "a.b" << wrapInLiteral(1) << "a.b?c" - << wrapInLiteral(1) - << "a.b c" - << wrapInLiteral(1) - << "a.b.d" + << wrapInLiteral(1) << "a.b c" << wrapInLiteral(1) << "a.b.d" << wrapInLiteral(0))), AssertionException); ASSERT_THROWS(makeProjectionWithDefaultPolicies( BSON("a.b.d" << wrapInLiteral(1) << "a.b c" << wrapInLiteral(1) << "a.b?c" - << wrapInLiteral(1) - << "a.b" - << wrapInLiteral(0) - << "a.b-c" + << wrapInLiteral(1) << "a.b" << wrapInLiteral(0) << "a.b-c" << wrapInLiteral(1))), AssertionException); } diff --git a/src/mongo/db/pipeline/parsed_inclusion_projection_test.cpp b/src/mongo/db/pipeline/parsed_inclusion_projection_test.cpp index 09d4b0cb4d6..f99a82c7546 100644 --- a/src/mongo/db/pipeline/parsed_inclusion_projection_test.cpp +++ b/src/mongo/db/pipeline/parsed_inclusion_projection_test.cpp @@ -240,10 +240,8 @@ TEST(InclusionProjectionExecutionTest, ShouldOptimizeNestedExpressions) { TEST(InclusionProjectionExecutionTest, ShouldReportThatAllExceptIncludedFieldsAreModified) { auto inclusion = makeInclusionProjectionWithDefaultPolicies(); - inclusion.parse(BSON( - "a" << wrapInLiteral("computedVal") << "b.c" << wrapInLiteral("computedVal") << "d" << true - << "e.f" - << true)); + inclusion.parse(BSON("a" << wrapInLiteral("computedVal") << "b.c" + << wrapInLiteral("computedVal") << "d" << true << "e.f" << true)); auto modifiedPaths = inclusion.getModifiedPaths(); ASSERT(modifiedPaths.type == DocumentSource::GetModPathsReturn::Type::kAllExcept); @@ -261,11 +259,7 @@ TEST(InclusionProjectionExecutionTest, ShouldReportThatAllExceptIncludedFieldsAreModifiedWithIdExclusion) { auto inclusion = makeInclusionProjectionWithDefaultPolicies(); inclusion.parse(BSON("_id" << false << "a" << wrapInLiteral("computedVal") << "b.c" - << wrapInLiteral("computedVal") - << "d" - << true - << "e.f" - << true)); + << wrapInLiteral("computedVal") << "d" << true << "e.f" << true)); auto modifiedPaths = inclusion.getModifiedPaths(); ASSERT(modifiedPaths.type == DocumentSource::GetModPathsReturn::Type::kAllExcept); @@ -573,11 +567,10 @@ TEST(InclusionProjectionExecutionTest, ShouldAllowMixedNestedAndDottedFields) { auto inclusion = makeInclusionProjectionWithDefaultPolicies(); // Include all of "a.b", "a.c", "a.d", and "a.e". // Add new computed fields "a.W", "a.X", "a.Y", and "a.Z". - inclusion.parse(BSON( - "a.b" << true << "a.c" << true << "a.W" << wrapInLiteral("W") << "a.X" << wrapInLiteral("X") - << "a" - << BSON("d" << true << "e" << true << "Y" << wrapInLiteral("Y") << "Z" - << wrapInLiteral("Z")))); + inclusion.parse(BSON("a.b" << true << "a.c" << true << "a.W" << wrapInLiteral("W") << "a.X" + << wrapInLiteral("X") << "a" + << BSON("d" << true << "e" << true << "Y" << wrapInLiteral("Y") + << "Z" << wrapInLiteral("Z")))); auto result = inclusion.applyProjection(Document{ {"a", Document{{"b", "b"_sd}, {"c", "c"_sd}, {"d", "d"_sd}, {"e", "e"_sd}, {"f", "f"_sd}}}}); diff --git a/src/mongo/db/pipeline/pipeline.cpp b/src/mongo/db/pipeline/pipeline.cpp index 73b14b80262..3337a79e4b8 100644 --- a/src/mongo/db/pipeline/pipeline.cpp +++ b/src/mongo/db/pipeline/pipeline.cpp @@ -169,9 +169,9 @@ void Pipeline::validateTopLevelPipeline() const { if (nss.isCollectionlessAggregateNS() && !firstStageConstraints.isIndependentOfAnyCollection) { uasserted(ErrorCodes::InvalidNamespace, - str::stream() << "{aggregate: 1} is not valid for '" - << _sources.front()->getSourceName() - << "'; a collection is required."); + str::stream() + << "{aggregate: 1} is not valid for '" + << _sources.front()->getSourceName() << "'; a collection is required."); } if (!nss.isCollectionlessAggregateNS() && diff --git a/src/mongo/db/pipeline/pipeline_d.cpp b/src/mongo/db/pipeline/pipeline_d.cpp index f133a67c9bc..3efb9b5813f 100644 --- a/src/mongo/db/pipeline/pipeline_d.cpp +++ b/src/mongo/db/pipeline/pipeline_d.cpp @@ -508,9 +508,9 @@ PipelineD::buildInnerQueryExecutorGeneric(Collection* collection, (pipeline->peekFront() && pipeline->peekFront()->constraints().isChangeStreamStage()); auto attachExecutorCallback = [deps, queryObj, sortObj, projForQuery, trackOplogTS]( - Collection* collection, - std::unique_ptr<PlanExecutor, PlanExecutor::Deleter> exec, - Pipeline* pipeline) { + Collection* collection, + std::unique_ptr<PlanExecutor, PlanExecutor::Deleter> exec, + Pipeline* pipeline) { auto cursor = DocumentSourceCursor::create( collection, std::move(exec), pipeline->getContext(), trackOplogTS); addCursorSource( @@ -566,15 +566,14 @@ PipelineD::buildInnerQueryExecutorGeoNear(Collection* collection, str::stream() << "Unexpectedly got the following sort from the query system: " << sortFromQuerySystem.jsonString()); - auto attachExecutorCallback = - [ - deps, - distanceField = geoNearStage->getDistanceField(), - locationField = geoNearStage->getLocationField(), - distanceMultiplier = geoNearStage->getDistanceMultiplier().value_or(1.0) - ](Collection * collection, - std::unique_ptr<PlanExecutor, PlanExecutor::Deleter> exec, - Pipeline * pipeline) { + auto attachExecutorCallback = [deps, + distanceField = geoNearStage->getDistanceField(), + locationField = geoNearStage->getLocationField(), + distanceMultiplier = + geoNearStage->getDistanceMultiplier().value_or(1.0)]( + Collection* collection, + std::unique_ptr<PlanExecutor, PlanExecutor::Deleter> exec, + Pipeline* pipeline) { auto cursor = DocumentSourceGeoNearCursor::create(collection, std::move(exec), pipeline->getContext(), diff --git a/src/mongo/db/pipeline/pipeline_metadata_tree.h b/src/mongo/db/pipeline/pipeline_metadata_tree.h index fe8c1f02770..1a22c452590 100644 --- a/src/mongo/db/pipeline/pipeline_metadata_tree.h +++ b/src/mongo/db/pipeline/pipeline_metadata_tree.h @@ -117,8 +117,7 @@ inline auto findStageContents(const NamespaceString& ns, auto it = initialStageContents.find(ns); uassert(51213, str::stream() << "Metadata to initialize an aggregation pipeline associated with " - << ns.coll() - << " is missing.", + << ns.coll() << " is missing.", it != initialStageContents.end()); return it->second; } @@ -154,7 +153,7 @@ inline auto makeAdditionalChildren( std::vector<T> offTheEndContents; if (auto lookupSource = dynamic_cast<const DocumentSourceLookUp*>(&source); lookupSource && lookupSource->wasConstructedWithPipelineSyntax()) { - auto[child, offTheEndReshaper] = + auto [child, offTheEndReshaper] = makeTreeWithOffTheEndStage(std::move(initialStageContents), lookupSource->getResolvedIntrospectionPipeline(), propagator); @@ -166,7 +165,7 @@ inline auto makeAdditionalChildren( facetSource->getFacetPipelines().end(), std::back_inserter(children), [&](const auto& fPipe) { - auto[child, offTheEndReshaper] = makeTreeWithOffTheEndStage( + auto [child, offTheEndReshaper] = makeTreeWithOffTheEndStage( std::move(initialStageContents), *fPipe.pipeline, propagator); offTheEndContents.push_back(offTheEndReshaper(child.get().contents)); return std::move(*child); @@ -192,13 +191,15 @@ inline auto makeStage( auto contents = (previous) ? reshapeContents(previous.get().contents) : findStageContents(source.getContext()->ns, initialStageContents); - auto[additionalChildren, offTheEndContents] = + auto [additionalChildren, offTheEndContents] = makeAdditionalChildren(std::move(initialStageContents), source, propagator, contents); auto principalChild = previous ? std::make_unique<Stage<T>>(std::move(previous.get())) : std::unique_ptr<Stage<T>>(); - std::function<T(const T&)> reshaper([&, offTheEndContents{std::move(offTheEndContents)} ]( - const T& reshapable) { return propagator(reshapable, offTheEndContents, source); }); + std::function<T(const T&)> reshaper( + [&, offTheEndContents{std::move(offTheEndContents)}](const T& reshapable) { + return propagator(reshapable, offTheEndContents, source); + }); return std::pair( boost::optional<Stage<T>>( Stage(std::move(contents), std::move(principalChild), std::move(additionalChildren))), @@ -278,7 +279,7 @@ inline std::pair<boost::optional<Stage<T>>, T> makeTree( findStageContents(pipeline.getContext()->ns, initialStageContents)); } - auto && [ finalStage, reshaper ] = + auto&& [finalStage, reshaper] = detail::makeTreeWithOffTheEndStage(std::move(initialStageContents), pipeline, propagator); return std::pair(std::move(*finalStage), reshaper(finalStage.get().contents)); diff --git a/src/mongo/db/pipeline/pipeline_metadata_tree_test.cpp b/src/mongo/db/pipeline/pipeline_metadata_tree_test.cpp index 25a161c2048..5a15074b361 100644 --- a/src/mongo/db/pipeline/pipeline_metadata_tree_test.cpp +++ b/src/mongo/db/pipeline/pipeline_metadata_tree_test.cpp @@ -129,7 +129,8 @@ TEST_F(PipelineMetadataTreeTest, LinearPipelinesConstructProperTrees) { auto pipePtr = jsonToPipeline("[{$project: {name: 1}}]"); return makeTree<TestThing>( {{NamespaceString("test.collection"), initial}}, *pipePtr, ignoreDocumentSourceAddOne); - }().first.get() == Stage(TestThing{23}, {}, {})); + }() + .first.get() == Stage(TestThing{23}, {}, {})); ASSERT([&]() { auto pipePtr = jsonToPipeline( @@ -137,7 +138,8 @@ TEST_F(PipelineMetadataTreeTest, LinearPipelinesConstructProperTrees) { "{$match: {status: \"completed\"}}]"); return makeTree<TestThing>( {{NamespaceString("test.collection"), initial}}, *pipePtr, ignoreDocumentSourceAddOne); - }().first.get() == Stage(TestThing{24}, makeUniqueStage(TestThing{23}, {}, {}), {})); + }() + .first.get() == Stage(TestThing{24}, makeUniqueStage(TestThing{23}, {}, {}), {})); ASSERT([&]() { auto pipePtr = jsonToPipeline( @@ -149,7 +151,8 @@ TEST_F(PipelineMetadataTreeTest, LinearPipelinesConstructProperTrees) { "{$match: {status: \"completed\"}}]"); return makeTree<TestThing>( {{NamespaceString("test.collection"), initial}}, *pipePtr, ignoreDocumentSourceAddOne); - }().first.get() == + }() + .first.get() == Stage(TestThing{28}, makeUniqueStage( TestThing{27}, @@ -247,7 +250,8 @@ TEST_F(PipelineMetadataTreeTest, BranchingPipelinesConstructProperTrees) { {NamespaceString("test.instruments"), {"2"}}}, *pipePtr, buildRepresentativeString); - }().first.get() == + }() + .first.get() == Stage(TestThing{"1mpxul[2m]ulu"}, makeUniqueStage( TestThing{"1mpxul[2m]ul"}, @@ -283,7 +287,8 @@ TEST_F(PipelineMetadataTreeTest, BranchingPipelinesConstructProperTrees) { "{$limit: 12}]"); return makeTree<TestThing>( {{NamespaceString("test.collection"), {""}}}, *pipePtr, buildRepresentativeString); - }().first.get() == + }() + .first.get() == Stage(TestThing{"f[tugs, tmgs, tb]"}, makeUniqueStage( TestThing{""}, diff --git a/src/mongo/db/pipeline/process_interface_standalone.cpp b/src/mongo/db/pipeline/process_interface_standalone.cpp index b81ee5a435d..0cb6ebc6ec9 100644 --- a/src/mongo/db/pipeline/process_interface_standalone.cpp +++ b/src/mongo/db/pipeline/process_interface_standalone.cpp @@ -187,7 +187,7 @@ Update MongoInterfaceStandalone::buildUpdateOp( for (auto&& obj : batch) { updateEntries.push_back([&] { UpdateOpEntry entry; - auto && [ q, u, c ] = obj; + auto&& [q, u, c] = obj; entry.setQ(std::move(q)); entry.setU(std::move(u)); entry.setC(std::move(c)); @@ -339,8 +339,7 @@ void MongoInterfaceStandalone::renameIfOptionsAndIndexesHaveNotChanged( str::stream() << "collection options of target collection " << targetNs.ns() << " changed during processing. Original options: " << originalCollectionOptions - << ", new options: " - << getCollectionOptions(targetNs), + << ", new options: " << getCollectionOptions(targetNs), SimpleBSONObjComparator::kInstance.evaluate(originalCollectionOptions == getCollectionOptions(targetNs))); @@ -465,12 +464,8 @@ boost::optional<Document> MongoInterfaceStandalone::lookupSingleDocument( if (auto next = pipeline->getNext()) { uasserted(ErrorCodes::TooManyMatchingDocuments, str::stream() << "found more than one document with document key " - << documentKey.toString() - << " [" - << lookedUpDocument->toString() - << ", " - << next->toString() - << "]"); + << documentKey.toString() << " [" << lookedUpDocument->toString() + << ", " << next->toString() << "]"); } // Set the speculative read timestamp appropriately after we do a document lookup locally. We @@ -620,14 +615,12 @@ void MongoInterfaceStandalone::_reportCurrentOpsForIdleSessions(OperationContext ? makeSessionFilterForAuthenticatedUsers(opCtx) : KillAllSessionsByPatternSet{{}}); - sessionCatalog->scanSessions( - {std::move(sessionFilter)}, - [&](const ObservableSession& session) { - auto op = TransactionParticipant::get(session).reportStashedState(opCtx); - if (!op.isEmpty()) { - ops->emplace_back(op); - } - }); + sessionCatalog->scanSessions({std::move(sessionFilter)}, [&](const ObservableSession& session) { + auto op = TransactionParticipant::get(session).reportStashedState(opCtx); + if (!op.isEmpty()) { + ops->emplace_back(op); + } + }); } std::unique_ptr<CollatorInterface> MongoInterfaceStandalone::_getCollectionDefaultCollator( diff --git a/src/mongo/db/pipeline/process_interface_standalone_test.cpp b/src/mongo/db/pipeline/process_interface_standalone_test.cpp index fa246fc2e9d..e522111e395 100644 --- a/src/mongo/db/pipeline/process_interface_standalone_test.cpp +++ b/src/mongo/db/pipeline/process_interface_standalone_test.cpp @@ -93,7 +93,7 @@ TEST_F(ProcessInterfaceStandaloneTest, // Test that 'targetCollectionVersion' is accepted if from mongos. expCtx->fromMongos = true; - auto[joinKey, chunkVersion] = processInterface->ensureFieldsUniqueOrResolveDocumentKey( + auto [joinKey, chunkVersion] = processInterface->ensureFieldsUniqueOrResolveDocumentKey( expCtx, {{"_id"}}, targetCollectionVersion, expCtx->ns); ASSERT_EQ(joinKey.size(), 1UL); ASSERT_EQ(joinKey.count(FieldPath("_id")), 1UL); diff --git a/src/mongo/db/pipeline/resume_token.cpp b/src/mongo/db/pipeline/resume_token.cpp index 48bb9ee1678..bc9787c4d92 100644 --- a/src/mongo/db/pipeline/resume_token.cpp +++ b/src/mongo/db/pipeline/resume_token.cpp @@ -90,8 +90,9 @@ ResumeToken::ResumeToken(const Document& resumeDoc) { _typeBits = resumeDoc[kTypeBitsFieldName]; uassert(40648, str::stream() << "Bad resume token: _typeBits of wrong type " << resumeDoc.toString(), - _typeBits.missing() || (_typeBits.getType() == BSONType::BinData && - _typeBits.getBinData().type == BinDataGeneral)); + _typeBits.missing() || + (_typeBits.getType() == BSONType::BinData && + _typeBits.getBinData().type == BinDataGeneral)); } // We encode the resume token as a KeyString with the sequence: diff --git a/src/mongo/db/pipeline/resume_token_test.cpp b/src/mongo/db/pipeline/resume_token_test.cpp index 72894880953..d684e30cc26 100644 --- a/src/mongo/db/pipeline/resume_token_test.cpp +++ b/src/mongo/db/pipeline/resume_token_test.cpp @@ -360,5 +360,5 @@ TEST(ResumeToken, StringEncodingSortsCorrectly) { {ts10_4, 0, 0, lower_uuid, Value(Document{{"_id", 0}})}); } -} // namspace -} // namspace mongo +} // namespace +} // namespace mongo diff --git a/src/mongo/db/pipeline/semantic_analysis.cpp b/src/mongo/db/pipeline/semantic_analysis.cpp index 256fbf9acbf..e44b0af957a 100644 --- a/src/mongo/db/pipeline/semantic_analysis.cpp +++ b/src/mongo/db/pipeline/semantic_analysis.cpp @@ -92,7 +92,7 @@ StringMap<std::string> computeNamesAssumingAnyPathsNotRenamedAreUnmodified( StringMap<std::string> invertRenameMap(const StringMap<std::string>& originalMap) { StringMap<std::string> reversedMap; - for (auto && [ newName, oldName ] : originalMap) { + for (auto&& [newName, oldName] : originalMap) { reversedMap[oldName] = newName; } return reversedMap; @@ -206,7 +206,7 @@ boost::optional<StringMap<std::string>> renamedPaths(const std::set<std::string> } case DocumentSource::GetModPathsReturn::Type::kAllExcept: { auto preservedPaths = modifiedPathsRet.paths; - for (auto && [ newName, oldName ] : modifiedPathsRet.renames) { + for (auto&& [newName, oldName] : modifiedPathsRet.renames) { // For the purposes of checking which paths are modified, consider renames to // preserve the path. We'll circle back later to figure out the new name if // appropriate. If we are going forward, we want to consider the name of the path diff --git a/src/mongo/db/pipeline/sharded_agg_helpers.cpp b/src/mongo/db/pipeline/sharded_agg_helpers.cpp index afff96bab8b..aac03df6de4 100644 --- a/src/mongo/db/pipeline/sharded_agg_helpers.cpp +++ b/src/mongo/db/pipeline/sharded_agg_helpers.cpp @@ -37,7 +37,6 @@ #include "mongo/db/pipeline/document_source_out.h" #include "mongo/s/catalog_cache.h" #include "mongo/s/cluster_commands_helpers.h" -#include "mongo/s/cluster_commands_helpers.h" #include "mongo/s/query/cluster_query_knobs_gen.h" #include "mongo/s/query/document_source_merge_cursors.h" #include "mongo/util/fail_point.h" @@ -113,8 +112,7 @@ BSONObj genericTransformForShards(MutableDocument&& cmdForShards, invariant(cmdForShards.peek()[OperationSessionInfo::kTxnNumberFieldName].missing(), str::stream() << "Command for shards unexpectedly had the " << OperationSessionInfo::kTxnNumberFieldName - << " field set: " - << cmdForShards.peek().toString()); + << " field set: " << cmdForShards.peek().toString()); cmdForShards[OperationSessionInfo::kTxnNumberFieldName] = Value(static_cast<long long>(*opCtx->getTxnNumber())); } @@ -332,9 +330,7 @@ DispatchShardPipelineResults dispatchShardPipeline( shardQuery); invariant(cursors.size() % shardIds.size() == 0, str::stream() << "Number of cursors (" << cursors.size() - << ") is not a multiple of producers (" - << shardIds.size() - << ")"); + << ") is not a multiple of producers (" << shardIds.size() << ")"); } // Convert remote cursors into a vector of "owned" cursors. @@ -346,9 +342,9 @@ DispatchShardPipelineResults dispatchShardPipeline( // Record the number of shards involved in the aggregation. If we are required to merge on // the primary shard, but the primary shard was not in the set of targeted shards, then we // must increment the number of involved shards. - CurOp::get(opCtx)->debug().nShards = - shardIds.size() + (needsPrimaryShardMerge && executionNsRoutingInfo && - !shardIds.count(executionNsRoutingInfo->db().primaryId())); + CurOp::get(opCtx)->debug().nShards = shardIds.size() + + (needsPrimaryShardMerge && executionNsRoutingInfo && + !shardIds.count(executionNsRoutingInfo->db().primaryId())); return DispatchShardPipelineResults{needsPrimaryShardMerge, std::move(ownedCursors), diff --git a/src/mongo/db/pipeline/stub_mongo_process_interface_lookup_single_document.cpp b/src/mongo/db/pipeline/stub_mongo_process_interface_lookup_single_document.cpp index a5b877a9e49..506acd514e8 100644 --- a/src/mongo/db/pipeline/stub_mongo_process_interface_lookup_single_document.cpp +++ b/src/mongo/db/pipeline/stub_mongo_process_interface_lookup_single_document.cpp @@ -93,12 +93,8 @@ boost::optional<Document> StubMongoProcessInterfaceLookupSingleDocument::lookupS if (auto next = pipeline->getNext()) { uasserted(ErrorCodes::TooManyMatchingDocuments, str::stream() << "found more than one document matching " - << documentKey.toString() - << " [" - << lookedUpDocument->toString() - << ", " - << next->toString() - << "]"); + << documentKey.toString() << " [" << lookedUpDocument->toString() + << ", " << next->toString() << "]"); } return lookedUpDocument; } diff --git a/src/mongo/db/pipeline/value.cpp b/src/mongo/db/pipeline/value.cpp index 52a1c5fd71d..b804adaf797 100644 --- a/src/mongo/db/pipeline/value.cpp +++ b/src/mongo/db/pipeline/value.cpp @@ -389,8 +389,7 @@ void Value::addToBsonObj(BSONObjBuilder* builder, size_t recursionLevel) const { uassert(ErrorCodes::Overflow, str::stream() << "cannot convert document to BSON because it exceeds the limit of " - << BSONDepth::getMaxAllowableDepth() - << " levels of nesting", + << BSONDepth::getMaxAllowableDepth() << " levels of nesting", recursionLevel <= BSONDepth::getMaxAllowableDepth()); if (getType() == BSONType::Object) { @@ -411,8 +410,7 @@ void Value::addToBsonObj(BSONObjBuilder* builder, void Value::addToBsonArray(BSONArrayBuilder* builder, size_t recursionLevel) const { uassert(ErrorCodes::Overflow, str::stream() << "cannot convert document to BSON because it exceeds the limit of " - << BSONDepth::getMaxAllowableDepth() - << " levels of nesting", + << BSONDepth::getMaxAllowableDepth() << " levels of nesting", recursionLevel <= BSONDepth::getMaxAllowableDepth()); // If this Value is empty, do nothing to avoid incrementing the builder's counter. @@ -704,7 +702,7 @@ int Value::compare(const Value& rL, case Date: // signed return cmp(rL._storage.dateValue, rR._storage.dateValue); - // Numbers should compare by equivalence even if different types + // Numbers should compare by equivalence even if different types case NumberDecimal: { switch (rType) { @@ -1078,9 +1076,9 @@ size_t Value::getApproximateSize() const { case Symbol: case BinData: case String: - return sizeof(Value) + (_storage.shortStr - ? 0 // string stored inline, so no extra mem usage - : sizeof(RCString) + _storage.getString().size()); + return sizeof(Value) + + (_storage.shortStr ? 0 // string stored inline, so no extra mem usage + : sizeof(RCString) + _storage.getString().size()); case Object: return sizeof(Value) + getDocument().getApproximateSize(); diff --git a/src/mongo/db/pipeline/value.h b/src/mongo/db/pipeline/value.h index ef0ac8b6afd..296d6d08480 100644 --- a/src/mongo/db/pipeline/value.h +++ b/src/mongo/db/pipeline/value.h @@ -146,7 +146,7 @@ public: * Used when preforming arithmetic operations with int where the * result may be too large and need to be stored as long. The Value * will be an int if value fits, otherwise it will be a long. - */ + */ static Value createIntOrLong(long long value); /** A "missing" value indicates the lack of a Value. @@ -396,7 +396,7 @@ public: return Value(values); } }; -} +} // namespace mongo /* ======================= INLINED IMPLEMENTATIONS ========================== */ diff --git a/src/mongo/db/pipeline/variables.cpp b/src/mongo/db/pipeline/variables.cpp index cf6b81e9605..8a37fecc10f 100644 --- a/src/mongo/db/pipeline/variables.cpp +++ b/src/mongo/db/pipeline/variables.cpp @@ -68,9 +68,7 @@ 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); } } @@ -95,9 +93,7 @@ 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); } } @@ -258,4 +254,4 @@ std::set<Variables::Id> VariablesParseState::getDefinedVariableIDs() const { return ids; } -} +} // namespace mongo diff --git a/src/mongo/db/pipeline/variables.h b/src/mongo/db/pipeline/variables.h index 2a606ac0572..ddb76457cac 100644 --- a/src/mongo/db/pipeline/variables.h +++ b/src/mongo/db/pipeline/variables.h @@ -157,7 +157,7 @@ private: void setValue(Id id, const Value& value, bool isConstant); static auto getBuiltinVariableName(Variables::Id variable) { - for (auto & [ name, id ] : kBuiltinVarNameToId) { + for (auto& [name, id] : kBuiltinVarNameToId) { if (variable == id) { return name; } |