diff options
author | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2016-05-28 17:55:12 -0400 |
---|---|---|
committer | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2016-05-28 17:55:12 -0400 |
commit | 6dcdd23dd37ef12c87e71cf59ef01cd82432efe0 (patch) | |
tree | c8cfb5acb62c80f375bc37e7d4350382deea6a37 /src/mongo/db/query | |
parent | d4ac5673ea3f6cef4ce9dbcec90e31813997a528 (diff) | |
download | mongo-6dcdd23dd37ef12c87e71cf59ef01cd82432efe0.tar.gz |
SERVER-23971 Clang-Format code
Diffstat (limited to 'src/mongo/db/query')
51 files changed, 1302 insertions, 874 deletions
diff --git a/src/mongo/db/query/canonical_query_test.cpp b/src/mongo/db/query/canonical_query_test.cpp index 3dc4386f412..c5e54fedf31 100644 --- a/src/mongo/db/query/canonical_query_test.cpp +++ b/src/mongo/db/query/canonical_query_test.cpp @@ -112,12 +112,12 @@ TEST(CanonicalQueryTest, IsValidText) { ASSERT_OK(isValid("{$text: {$search: 's'}}", *lpq)); // Valid: TEXT inside OR. - ASSERT_OK(isValid( - "{$or: [" - " {$text: {$search: 's'}}," - " {a: 1}" - "]}", - *lpq)); + ASSERT_OK( + isValid("{$or: [" + " {$text: {$search: 's'}}," + " {a: 1}" + "]}", + *lpq)); // Valid: TEXT outside NOR. ASSERT_OK(isValid("{$text: {$search: 's'}, $nor: [{a: 1}, {b: 1}]}", *lpq)); @@ -126,37 +126,37 @@ TEST(CanonicalQueryTest, IsValidText) { ASSERT_NOT_OK(isValid("{$nor: [{$text: {$search: 's'}}, {a: 1}]}", *lpq)); // Invalid: TEXT inside NOR. - ASSERT_NOT_OK(isValid( - "{$nor: [" - " {$or: [" - " {$text: {$search: 's'}}," - " {a: 1}" - " ]}," - " {a: 2}" - "]}", - *lpq)); + ASSERT_NOT_OK( + isValid("{$nor: [" + " {$or: [" + " {$text: {$search: 's'}}," + " {a: 1}" + " ]}," + " {a: 2}" + "]}", + *lpq)); // Invalid: >1 TEXT. - ASSERT_NOT_OK(isValid( - "{$and: [" - " {$text: {$search: 's'}}," - " {$text: {$search: 't'}}" - "]}", - *lpq)); + ASSERT_NOT_OK( + isValid("{$and: [" + " {$text: {$search: 's'}}," + " {$text: {$search: 't'}}" + "]}", + *lpq)); // Invalid: >1 TEXT. - ASSERT_NOT_OK(isValid( - "{$and: [" - " {$or: [" - " {$text: {$search: 's'}}," - " {a: 1}" - " ]}," - " {$or: [" - " {$text: {$search: 't'}}," - " {b: 1}" - " ]}" - "]}", - *lpq)); + ASSERT_NOT_OK( + isValid("{$and: [" + " {$or: [" + " {$text: {$search: 's'}}," + " {a: 1}" + " ]}," + " {$or: [" + " {$text: {$search: 't'}}," + " {b: 1}" + " ]}" + "]}", + *lpq)); } TEST(CanonicalQueryTest, IsValidTextTailable) { @@ -178,61 +178,61 @@ TEST(CanonicalQueryTest, IsValidGeo) { ASSERT_OK(isValid("{a: {$near: [0, 0]}}", *lpq)); // Valid: GEO_NEAR inside nested AND. - ASSERT_OK(isValid( - "{$and: [" - " {$and: [" - " {a: {$near: [0, 0]}}," - " {b: 1}" - " ]}," - " {c: 1}" - "]}", - *lpq)); + ASSERT_OK( + isValid("{$and: [" + " {$and: [" + " {a: {$near: [0, 0]}}," + " {b: 1}" + " ]}," + " {c: 1}" + "]}", + *lpq)); // Invalid: >1 GEO_NEAR. - ASSERT_NOT_OK(isValid( - "{$and: [" - " {a: {$near: [0, 0]}}," - " {b: {$near: [0, 0]}}" - "]}", - *lpq)); + ASSERT_NOT_OK( + isValid("{$and: [" + " {a: {$near: [0, 0]}}," + " {b: {$near: [0, 0]}}" + "]}", + *lpq)); // Invalid: >1 GEO_NEAR. - ASSERT_NOT_OK(isValid( - "{$and: [" - " {a: {$geoNear: [0, 0]}}," - " {b: {$near: [0, 0]}}" - "]}", - *lpq)); + ASSERT_NOT_OK( + isValid("{$and: [" + " {a: {$geoNear: [0, 0]}}," + " {b: {$near: [0, 0]}}" + "]}", + *lpq)); // Invalid: >1 GEO_NEAR. - ASSERT_NOT_OK(isValid( - "{$and: [" - " {$and: [" - " {a: {$near: [0, 0]}}," - " {b: 1}" - " ]}," - " {$and: [" - " {c: {$near: [0, 0]}}," - " {d: 1}" - " ]}" - "]}", - *lpq)); + ASSERT_NOT_OK( + isValid("{$and: [" + " {$and: [" + " {a: {$near: [0, 0]}}," + " {b: 1}" + " ]}," + " {$and: [" + " {c: {$near: [0, 0]}}," + " {d: 1}" + " ]}" + "]}", + *lpq)); // Invalid: GEO_NEAR inside NOR. - ASSERT_NOT_OK(isValid( - "{$nor: [" - " {a: {$near: [0, 0]}}," - " {b: 1}" - "]}", - *lpq)); + ASSERT_NOT_OK( + isValid("{$nor: [" + " {a: {$near: [0, 0]}}," + " {b: 1}" + "]}", + *lpq)); // Invalid: GEO_NEAR inside OR. - ASSERT_NOT_OK(isValid( - "{$or: [" - " {a: {$near: [0, 0]}}," - " {b: 1}" - "]}", - *lpq)); + ASSERT_NOT_OK( + isValid("{$or: [" + " {a: {$near: [0, 0]}}," + " {b: 1}" + "]}", + *lpq)); } TEST(CanonicalQueryTest, IsValidTextAndGeo) { @@ -247,13 +247,13 @@ TEST(CanonicalQueryTest, IsValidTextAndGeo) { ASSERT_NOT_OK(isValid("{$text: {$search: 's'}, a: {$geoNear: [0, 0]}}", *lpq)); // Invalid: TEXT and GEO_NEAR. - ASSERT_NOT_OK(isValid( - "{$or: [" - " {$text: {$search: 's'}}," - " {a: 1}" - " ]," - " b: {$near: [0, 0]}}", - *lpq)); + ASSERT_NOT_OK( + isValid("{$or: [" + " {$text: {$search: 's'}}," + " {a: 1}" + " ]," + " b: {$near: [0, 0]}}", + *lpq)); } TEST(CanonicalQueryTest, IsValidTextAndNaturalAscending) { diff --git a/src/mongo/db/query/collation/collation_serializer_test.cpp b/src/mongo/db/query/collation/collation_serializer_test.cpp index 60e1e63d9f6..fd961b158a0 100644 --- a/src/mongo/db/query/collation/collation_serializer_test.cpp +++ b/src/mongo/db/query/collation/collation_serializer_test.cpp @@ -44,13 +44,22 @@ TEST(CollationSerializerTest, ToBSONCorrectlySerializesDefaults) { BSONObj expectedObj = BSON("locale" << "myLocale" - << "caseLevel" << false << "caseFirst" + << "caseLevel" + << false + << "caseFirst" << "off" - << "strength" << 3 << "numericOrdering" << false << "alternate" + << "strength" + << 3 + << "numericOrdering" + << false + << "alternate" << "non-ignorable" << "maxVariable" << "punct" - << "normalization" << false << "backwards" << false); + << "normalization" + << false + << "backwards" + << false); ASSERT_EQ(expectedObj, CollationSerializer::specToBSON(collationSpec)); } @@ -62,13 +71,22 @@ TEST(CollationSerializerTest, ToBSONCorrectlySerializesCaseFirstUpper) { BSONObj expectedObj = BSON("locale" << "myLocale" - << "caseLevel" << false << "caseFirst" + << "caseLevel" + << false + << "caseFirst" << "upper" - << "strength" << 3 << "numericOrdering" << false << "alternate" + << "strength" + << 3 + << "numericOrdering" + << false + << "alternate" << "non-ignorable" << "maxVariable" << "punct" - << "normalization" << false << "backwards" << false); + << "normalization" + << false + << "backwards" + << false); ASSERT_EQ(expectedObj, CollationSerializer::specToBSON(collationSpec)); } @@ -80,13 +98,22 @@ TEST(CollationSerializerTest, ToBSONCorrectlySerializesCaseFirstLower) { BSONObj expectedObj = BSON("locale" << "myLocale" - << "caseLevel" << false << "caseFirst" + << "caseLevel" + << false + << "caseFirst" << "lower" - << "strength" << 3 << "numericOrdering" << false << "alternate" + << "strength" + << 3 + << "numericOrdering" + << false + << "alternate" << "non-ignorable" << "maxVariable" << "punct" - << "normalization" << false << "backwards" << false); + << "normalization" + << false + << "backwards" + << false); ASSERT_EQ(expectedObj, CollationSerializer::specToBSON(collationSpec)); } @@ -98,13 +125,22 @@ TEST(CollationSerializerTest, ToBSONCorrectlySerializesPrimaryStrength) { BSONObj expectedObj = BSON("locale" << "myLocale" - << "caseLevel" << false << "caseFirst" + << "caseLevel" + << false + << "caseFirst" << "off" - << "strength" << 1 << "numericOrdering" << false << "alternate" + << "strength" + << 1 + << "numericOrdering" + << false + << "alternate" << "non-ignorable" << "maxVariable" << "punct" - << "normalization" << false << "backwards" << false); + << "normalization" + << false + << "backwards" + << false); ASSERT_EQ(expectedObj, CollationSerializer::specToBSON(collationSpec)); } @@ -116,13 +152,22 @@ TEST(CollationSerializerTest, ToBSONCorrectlySerializesSecondaryStrength) { BSONObj expectedObj = BSON("locale" << "myLocale" - << "caseLevel" << false << "caseFirst" + << "caseLevel" + << false + << "caseFirst" << "off" - << "strength" << 2 << "numericOrdering" << false << "alternate" + << "strength" + << 2 + << "numericOrdering" + << false + << "alternate" << "non-ignorable" << "maxVariable" << "punct" - << "normalization" << false << "backwards" << false); + << "normalization" + << false + << "backwards" + << false); ASSERT_EQ(expectedObj, CollationSerializer::specToBSON(collationSpec)); } @@ -134,13 +179,22 @@ TEST(CollationSerializerTest, ToBSONCorrectlySerializesQuaternaryStrength) { BSONObj expectedObj = BSON("locale" << "myLocale" - << "caseLevel" << false << "caseFirst" + << "caseLevel" + << false + << "caseFirst" << "off" - << "strength" << 4 << "numericOrdering" << false << "alternate" + << "strength" + << 4 + << "numericOrdering" + << false + << "alternate" << "non-ignorable" << "maxVariable" << "punct" - << "normalization" << false << "backwards" << false); + << "normalization" + << false + << "backwards" + << false); ASSERT_EQ(expectedObj, CollationSerializer::specToBSON(collationSpec)); } @@ -152,13 +206,22 @@ TEST(CollationSerializerTest, ToBSONCorrectlySerializesIdenticalStrength) { BSONObj expectedObj = BSON("locale" << "myLocale" - << "caseLevel" << false << "caseFirst" + << "caseLevel" + << false + << "caseFirst" << "off" - << "strength" << 5 << "numericOrdering" << false << "alternate" + << "strength" + << 5 + << "numericOrdering" + << false + << "alternate" << "non-ignorable" << "maxVariable" << "punct" - << "normalization" << false << "backwards" << false); + << "normalization" + << false + << "backwards" + << false); ASSERT_EQ(expectedObj, CollationSerializer::specToBSON(collationSpec)); } @@ -170,13 +233,22 @@ TEST(CollationSerializerTest, ToBSONCorrectlySerializesAlternateShifted) { BSONObj expectedObj = BSON("locale" << "myLocale" - << "caseLevel" << false << "caseFirst" + << "caseLevel" + << false + << "caseFirst" << "off" - << "strength" << 3 << "numericOrdering" << false << "alternate" + << "strength" + << 3 + << "numericOrdering" + << false + << "alternate" << "shifted" << "maxVariable" << "punct" - << "normalization" << false << "backwards" << false); + << "normalization" + << false + << "backwards" + << false); ASSERT_EQ(expectedObj, CollationSerializer::specToBSON(collationSpec)); } @@ -188,13 +260,22 @@ TEST(CollationSerializerTest, ToBSONCorrectlySerializesMaxVariableSpace) { BSONObj expectedObj = BSON("locale" << "myLocale" - << "caseLevel" << false << "caseFirst" + << "caseLevel" + << false + << "caseFirst" << "off" - << "strength" << 3 << "numericOrdering" << false << "alternate" + << "strength" + << 3 + << "numericOrdering" + << false + << "alternate" << "non-ignorable" << "maxVariable" << "space" - << "normalization" << false << "backwards" << false); + << "normalization" + << false + << "backwards" + << false); ASSERT_EQ(expectedObj, CollationSerializer::specToBSON(collationSpec)); } diff --git a/src/mongo/db/query/collation/collator_factory_icu.cpp b/src/mongo/db/query/collation/collator_factory_icu.cpp index f72731d6e9b..5a4470d4bf5 100644 --- a/src/mongo/db/query/collation/collator_factory_icu.cpp +++ b/src/mongo/db/query/collation/collator_factory_icu.cpp @@ -183,9 +183,13 @@ StatusWith<CollationSpec::CaseFirstType> stringToCaseFirstType(const std::string } else { return {ErrorCodes::FailedToParse, str::stream() << "Field '" << CollationSpec::kCaseFirstField << "' must be '" - << CollationSpec::kCaseFirstUpper << "', '" - << CollationSpec::kCaseFirstLower << "', or '" - << CollationSpec::kCaseFirstOff << "'. Got: " << caseFirst}; + << CollationSpec::kCaseFirstUpper + << "', '" + << CollationSpec::kCaseFirstLower + << "', or '" + << CollationSpec::kCaseFirstOff + << "'. Got: " + << caseFirst}; } } @@ -204,7 +208,8 @@ StatusWith<CollationSpec::StrengthType> integerToStrengthType(long long strength } return {ErrorCodes::FailedToParse, str::stream() << "Field '" << CollationSpec::kStrengthField - << "' must be an integer 1 through 5. Got: " << strength}; + << "' must be an integer 1 through 5. Got: " + << strength}; } StatusWith<CollationSpec::AlternateType> stringToAlternateType(const std::string& alternate) { @@ -215,8 +220,11 @@ StatusWith<CollationSpec::AlternateType> stringToAlternateType(const std::string } else { return {ErrorCodes::FailedToParse, str::stream() << "Field '" << CollationSpec::kAlternateField << "' must be '" - << CollationSpec::kAlternateNonIgnorable << "' or '" - << CollationSpec::kAlternateShifted << "'. Got: " << alternate}; + << CollationSpec::kAlternateNonIgnorable + << "' or '" + << CollationSpec::kAlternateShifted + << "'. Got: " + << alternate}; } } @@ -228,8 +236,11 @@ StatusWith<CollationSpec::MaxVariableType> stringToMaxVariableType(const std::st } else { return {ErrorCodes::FailedToParse, str::stream() << "Field '" << CollationSpec::kMaxVariableField << "' must be '" - << CollationSpec::kMaxVariablePunct << "' or '" - << CollationSpec::kMaxVariableSpace << "'. Got: " << maxVariable}; + << CollationSpec::kMaxVariablePunct + << "' or '" + << CollationSpec::kMaxVariableSpace + << "'. Got: " + << maxVariable}; } } @@ -259,8 +270,10 @@ StatusWith<CollationSpec> parseToCollationSpec(const BSONObj& spec, icuError.set(status); return {ErrorCodes::OperationFailed, str::stream() << "Failed to get '" << CollationSpec::kCaseLevelField - << "' attribute from icu::Collator: " << icuError.errorName() - << ". Collation spec: " << spec}; + << "' attribute from icu::Collator: " + << icuError.errorName() + << ". Collation spec: " + << spec}; } parsedSpec.caseLevel = attributeToBool(caseLevelAttribute); } else if (!parseStatus.isOK()) { @@ -274,8 +287,10 @@ StatusWith<CollationSpec> parseToCollationSpec(const BSONObj& spec, icuError.set(status); return {ErrorCodes::OperationFailed, str::stream() << "Failed to set '" << CollationSpec::kCaseLevelField - << "' attribute: " << icuError.errorName() - << ". Collation spec: " << spec}; + << "' attribute: " + << icuError.errorName() + << ". Collation spec: " + << spec}; } } @@ -290,8 +305,10 @@ StatusWith<CollationSpec> parseToCollationSpec(const BSONObj& spec, icuError.set(status); return {ErrorCodes::OperationFailed, str::stream() << "Failed to get '" << CollationSpec::kCaseFirstField - << "' attribute from icu::Collator: " << icuError.errorName() - << ". Collation spec: " << spec}; + << "' attribute from icu::Collator: " + << icuError.errorName() + << ". Collation spec: " + << spec}; } parsedSpec.caseFirst = getCaseFirstFromAttribute(caseFirstAttribute); } else if (!parseStatus.isOK()) { @@ -313,8 +330,10 @@ StatusWith<CollationSpec> parseToCollationSpec(const BSONObj& spec, icuError.set(status); return {ErrorCodes::OperationFailed, str::stream() << "Failed to set '" << CollationSpec::kCaseFirstField - << "' attribute: " << icuError.errorName() - << ". Collation spec: " << spec}; + << "' attribute: " + << icuError.errorName() + << ". Collation spec: " + << spec}; } } @@ -329,8 +348,10 @@ StatusWith<CollationSpec> parseToCollationSpec(const BSONObj& spec, icuError.set(status); return {ErrorCodes::OperationFailed, str::stream() << "Failed to get '" << CollationSpec::kStrengthField - << "' attribute from icu::Collator: " << icuError.errorName() - << ". Collation spec: " << spec}; + << "' attribute from icu::Collator: " + << icuError.errorName() + << ". Collation spec: " + << spec}; } parsedSpec.strength = getStrengthFromAttribute(strengthAttribute); } else if (!parseStatus.isOK()) { @@ -351,8 +372,10 @@ StatusWith<CollationSpec> parseToCollationSpec(const BSONObj& spec, icuError.set(status); return {ErrorCodes::OperationFailed, str::stream() << "Failed to set '" << CollationSpec::kStrengthField - << "' attribute: " << icuError.errorName() - << ". Collation spec: " << spec}; + << "' attribute: " + << icuError.errorName() + << ". Collation spec: " + << spec}; } } @@ -368,8 +391,10 @@ StatusWith<CollationSpec> parseToCollationSpec(const BSONObj& spec, icuError.set(status); return {ErrorCodes::OperationFailed, str::stream() << "Failed to get '" << CollationSpec::kNumericOrderingField - << "' attribute from icu::Collator: " << icuError.errorName() - << ". Collation spec: " << spec}; + << "' attribute from icu::Collator: " + << icuError.errorName() + << ". Collation spec: " + << spec}; } parsedSpec.numericOrdering = attributeToBool(numericOrderingAttribute); } else if (!parseStatus.isOK()) { @@ -384,8 +409,10 @@ StatusWith<CollationSpec> parseToCollationSpec(const BSONObj& spec, icuError.set(status); return {ErrorCodes::OperationFailed, str::stream() << "Failed to set '" << CollationSpec::kNumericOrderingField - << "' attribute: " << icuError.errorName() - << ". Collation spec: " << spec}; + << "' attribute: " + << icuError.errorName() + << ". Collation spec: " + << spec}; } } @@ -401,8 +428,10 @@ StatusWith<CollationSpec> parseToCollationSpec(const BSONObj& spec, icuError.set(status); return {ErrorCodes::OperationFailed, str::stream() << "Failed to get '" << CollationSpec::kAlternateField - << "' attribute from icu::Collator: " << icuError.errorName() - << ". Collation spec: " << spec}; + << "' attribute from icu::Collator: " + << icuError.errorName() + << ". Collation spec: " + << spec}; } parsedSpec.alternate = getAlternateFromAttribute(alternateAttribute); } else if (!parseStatus.isOK()) { @@ -424,8 +453,10 @@ StatusWith<CollationSpec> parseToCollationSpec(const BSONObj& spec, icuError.set(status); return {ErrorCodes::OperationFailed, str::stream() << "Failed to set '" << CollationSpec::kAlternateField - << "' attribute: " << icuError.errorName() - << ". Collation spec: " << spec}; + << "' attribute: " + << icuError.errorName() + << ". Collation spec: " + << spec}; } } @@ -452,8 +483,10 @@ StatusWith<CollationSpec> parseToCollationSpec(const BSONObj& spec, icuError.set(status); return {ErrorCodes::OperationFailed, str::stream() << "Failed to set '" << CollationSpec::kMaxVariableField - << "' attribute: " << icuError.errorName() - << ". Collation spec: " << spec}; + << "' attribute: " + << icuError.errorName() + << ". Collation spec: " + << spec}; } } @@ -469,8 +502,10 @@ StatusWith<CollationSpec> parseToCollationSpec(const BSONObj& spec, icuError.set(status); return {ErrorCodes::OperationFailed, str::stream() << "Failed to get '" << CollationSpec::kNormalizationField - << "' attribute from icu::Collator: " << icuError.errorName() - << ". Collation spec: " << spec}; + << "' attribute from icu::Collator: " + << icuError.errorName() + << ". Collation spec: " + << spec}; } parsedSpec.normalization = attributeToBool(normalizationAttribute); } else if (!parseStatus.isOK()) { @@ -485,8 +520,10 @@ StatusWith<CollationSpec> parseToCollationSpec(const BSONObj& spec, icuError.set(status); return {ErrorCodes::OperationFailed, str::stream() << "Failed to set '" << CollationSpec::kNormalizationField - << "' attribute: " << icuError.errorName() - << ". Collation spec: " << spec}; + << "' attribute: " + << icuError.errorName() + << ". Collation spec: " + << spec}; } } @@ -502,8 +539,10 @@ StatusWith<CollationSpec> parseToCollationSpec(const BSONObj& spec, icuError.set(status); return {ErrorCodes::OperationFailed, str::stream() << "Failed to get '" << CollationSpec::kBackwardsField - << "' attribute from icu::Collator: " << icuError.errorName() - << ". Collation spec: " << spec}; + << "' attribute from icu::Collator: " + << icuError.errorName() + << ". Collation spec: " + << spec}; } parsedSpec.backwards = attributeToBool(backwardsAttribute); } else if (!parseStatus.isOK()) { @@ -518,8 +557,10 @@ StatusWith<CollationSpec> parseToCollationSpec(const BSONObj& spec, icuError.set(status); return {ErrorCodes::OperationFailed, str::stream() << "Failed to set '" << CollationSpec::kBackwardsField - << "' attribute: " << icuError.errorName() - << ". Collation spec: " << spec}; + << "' attribute: " + << icuError.errorName() + << ". Collation spec: " + << spec}; } } @@ -543,7 +584,8 @@ StatusWith<std::string> parseLocaleID(const BSONObj& spec) { if (localeID.find('\0') != std::string::npos) { return {ErrorCodes::BadValue, str::stream() << "Field '" << CollationSpec::kLocaleField - << "' cannot contain null byte. Collation spec: " << spec}; + << "' cannot contain null byte. Collation spec: " + << spec}; } return localeID; } @@ -559,13 +601,15 @@ Status validateLocaleID(const BSONObj& spec, icuError.set(status); return {ErrorCodes::OperationFailed, str::stream() << "Failed to get locale from icu::Collator: " << icuError.errorName() - << ". Collation spec: " << spec}; + << ". Collation spec: " + << spec}; } if (originalID.empty()) { return {ErrorCodes::BadValue, str::stream() << "Field '" << CollationSpec::kLocaleField - << "' cannot be the empty string in: " << spec}; + << "' cannot be the empty string in: " + << spec}; } // Check that each component of the locale ID is recognized by ICU. If ICU 1) cannot parse the @@ -607,7 +651,8 @@ StatusWith<std::unique_ptr<CollatorInterface>> CollatorFactoryICU::makeFromBSON( return {ErrorCodes::FailedToParse, str::stream() << "If " << CollationSpec::kLocaleField << "=" << CollationSpec::kSimpleBinaryComparison - << ", no other fields should be present in: " << spec}; + << ", no other fields should be present in: " + << spec}; } return {nullptr}; } @@ -616,8 +661,8 @@ StatusWith<std::unique_ptr<CollatorInterface>> CollatorFactoryICU::makeFromBSON( auto userLocale = icu::Locale::createFromName(parsedLocaleID.getValue().c_str()); if (userLocale.isBogus()) { return {ErrorCodes::BadValue, - str::stream() << "Field '" << CollationSpec::kLocaleField - << "' is not valid in: " << spec}; + str::stream() << "Field '" << CollationSpec::kLocaleField << "' is not valid in: " + << spec}; } // Construct an icu::Collator. @@ -628,7 +673,8 @@ StatusWith<std::unique_ptr<CollatorInterface>> CollatorFactoryICU::makeFromBSON( icuError.set(status); return {ErrorCodes::OperationFailed, str::stream() << "Failed to create collator: " << icuError.errorName() - << ". Collation spec: " << spec}; + << ". Collation spec: " + << spec}; } Status localeValidationStatus = validateLocaleID(spec, parsedLocaleID.getValue(), *icuCollator); diff --git a/src/mongo/db/query/collation/collator_factory_icu_decoration.cpp b/src/mongo/db/query/collation/collator_factory_icu_decoration.cpp index 62d1432b899..46ddbf54d8b 100644 --- a/src/mongo/db/query/collation/collator_factory_icu_decoration.cpp +++ b/src/mongo/db/query/collation/collator_factory_icu_decoration.cpp @@ -37,9 +37,8 @@ namespace mongo { namespace { -MONGO_INITIALIZER_WITH_PREREQUISITES(CreateCollatorFactory, - ("SetGlobalEnvironment", - "LoadICUData"))(InitializerContext* context) { +MONGO_INITIALIZER_WITH_PREREQUISITES(CreateCollatorFactory, ("SetGlobalEnvironment", "LoadICUData")) +(InitializerContext* context) { CollatorFactoryInterface::set(getGlobalServiceContext(), stdx::make_unique<CollatorFactoryICU>()); return Status::OK(); diff --git a/src/mongo/db/query/collation/collator_factory_icu_test.cpp b/src/mongo/db/query/collation/collator_factory_icu_test.cpp index db829fb359a..aa77665040f 100644 --- a/src/mongo/db/query/collation/collator_factory_icu_test.cpp +++ b/src/mongo/db/query/collation/collator_factory_icu_test.cpp @@ -59,7 +59,8 @@ TEST(CollatorFactoryICUTest, SimpleLocaleWithOtherFieldsFailsToParse) { CollatorFactoryICU factory; auto collator = factory.makeFromBSON(BSON("locale" << "simple" - << "caseLevel" << true)); + << "caseLevel" + << true)); ASSERT_NOT_OK(collator.getStatus()); ASSERT_EQ(collator.getStatus(), ErrorCodes::FailedToParse); } @@ -354,8 +355,10 @@ TEST(CollatorFactoryICUTest, TaiwanLocaleWithCollationStrokeDisallowed) { TEST(CollatorFactoryICUTest, LocaleWithValidLanguageCountryAndVariantAllowed) { CollatorFactoryICU factory; - ASSERT_OK(factory.makeFromBSON(BSON("locale" - << "en_US_POSIX")).getStatus()); + ASSERT_OK(factory + .makeFromBSON(BSON("locale" + << "en_US_POSIX")) + .getStatus()); } TEST(CollatorFactoryICUTest, USLocaleWithCollationPhonebookDisallowed) { @@ -368,14 +371,18 @@ TEST(CollatorFactoryICUTest, USLocaleWithCollationPhonebookDisallowed) { TEST(CollatorFactoryICUTest, GermanLocaleWithCollationPhonebookAllowed) { CollatorFactoryICU factory; - ASSERT_OK(factory.makeFromBSON(BSON("locale" - << "de@collation=phonebook")).getStatus()); + ASSERT_OK(factory + .makeFromBSON(BSON("locale" + << "de@collation=phonebook")) + .getStatus()); } TEST(CollatorFactoryICUTest, ChineseTraditionalLocaleWithCollationPinyinAllowed) { CollatorFactoryICU factory; - ASSERT_OK(factory.makeFromBSON(BSON("locale" - << "zh_Hant@collation=pinyin")).getStatus()); + ASSERT_OK(factory + .makeFromBSON(BSON("locale" + << "zh_Hant@collation=pinyin")) + .getStatus()); } TEST(CollatorFactoryICUTest, LocaleStringCannotContainNullByte) { @@ -435,7 +442,8 @@ TEST(CollatorFactoryICUTest, CaseLevelFalseParsesSuccessfully) { CollatorFactoryICU factory; auto collator = factory.makeFromBSON(BSON("locale" << "en_US" - << "caseLevel" << false)); + << "caseLevel" + << false)); ASSERT_OK(collator.getStatus()); ASSERT_FALSE(collator.getValue()->getSpec().caseLevel); } @@ -444,7 +452,8 @@ TEST(CollatorFactoryICUTest, CaseLevelTrueParsesSuccessfully) { CollatorFactoryICU factory; auto collator = factory.makeFromBSON(BSON("locale" << "en_US" - << "caseLevel" << true)); + << "caseLevel" + << true)); ASSERT_OK(collator.getStatus()); ASSERT_TRUE(collator.getValue()->getSpec().caseLevel); } @@ -486,7 +495,8 @@ TEST(CollatorFactoryICUTest, PrimaryStrengthParsesSuccessfully) { CollatorFactoryICU factory; auto collator = factory.makeFromBSON(BSON("locale" << "en_US" - << "strength" << 1)); + << "strength" + << 1)); ASSERT_OK(collator.getStatus()); ASSERT_EQ(static_cast<int>(CollationSpec::StrengthType::kPrimary), static_cast<int>(collator.getValue()->getSpec().strength)); @@ -496,7 +506,8 @@ TEST(CollatorFactoryICUTest, SecondaryStrengthParsesSuccessfully) { CollatorFactoryICU factory; auto collator = factory.makeFromBSON(BSON("locale" << "en_US" - << "strength" << 2)); + << "strength" + << 2)); ASSERT_OK(collator.getStatus()); ASSERT_EQ(static_cast<int>(CollationSpec::StrengthType::kSecondary), static_cast<int>(collator.getValue()->getSpec().strength)); @@ -506,7 +517,8 @@ TEST(CollatorFactoryICUTest, TertiaryStrengthParsesSuccessfully) { CollatorFactoryICU factory; auto collator = factory.makeFromBSON(BSON("locale" << "en_US" - << "strength" << 3)); + << "strength" + << 3)); ASSERT_OK(collator.getStatus()); ASSERT_EQ(static_cast<int>(CollationSpec::StrengthType::kTertiary), static_cast<int>(collator.getValue()->getSpec().strength)); @@ -516,7 +528,8 @@ TEST(CollatorFactoryICUTest, QuaternaryStrengthParsesSuccessfully) { CollatorFactoryICU factory; auto collator = factory.makeFromBSON(BSON("locale" << "en_US" - << "strength" << 4)); + << "strength" + << 4)); ASSERT_OK(collator.getStatus()); ASSERT_EQ(static_cast<int>(CollationSpec::StrengthType::kQuaternary), static_cast<int>(collator.getValue()->getSpec().strength)); @@ -526,7 +539,8 @@ TEST(CollatorFactoryICUTest, IdenticalStrengthParsesSuccessfully) { CollatorFactoryICU factory; auto collator = factory.makeFromBSON(BSON("locale" << "en_US" - << "strength" << 5)); + << "strength" + << 5)); ASSERT_OK(collator.getStatus()); ASSERT_EQ(static_cast<int>(CollationSpec::StrengthType::kIdentical), static_cast<int>(collator.getValue()->getSpec().strength)); @@ -536,7 +550,8 @@ TEST(CollatorFactoryICUTest, NumericOrderingFalseParsesSuccessfully) { CollatorFactoryICU factory; auto collator = factory.makeFromBSON(BSON("locale" << "en_US" - << "numericOrdering" << false)); + << "numericOrdering" + << false)); ASSERT_OK(collator.getStatus()); ASSERT_FALSE(collator.getValue()->getSpec().numericOrdering); } @@ -545,7 +560,8 @@ TEST(CollatorFactoryICUTest, NumericOrderingTrueParsesSuccessfully) { CollatorFactoryICU factory; auto collator = factory.makeFromBSON(BSON("locale" << "en_US" - << "numericOrdering" << true)); + << "numericOrdering" + << true)); ASSERT_OK(collator.getStatus()); ASSERT_TRUE(collator.getValue()->getSpec().numericOrdering); } @@ -598,7 +614,8 @@ TEST(CollatorFactoryICUTest, NormalizationFalseParsesSuccessfully) { CollatorFactoryICU factory; auto collator = factory.makeFromBSON(BSON("locale" << "en_US" - << "normalization" << false)); + << "normalization" + << false)); ASSERT_OK(collator.getStatus()); ASSERT_FALSE(collator.getValue()->getSpec().normalization); } @@ -607,7 +624,8 @@ TEST(CollatorFactoryICUTest, NormalizationTrueParsesSuccessfully) { CollatorFactoryICU factory; auto collator = factory.makeFromBSON(BSON("locale" << "en_US" - << "normalization" << true)); + << "normalization" + << true)); ASSERT_OK(collator.getStatus()); ASSERT_TRUE(collator.getValue()->getSpec().normalization); } @@ -616,7 +634,8 @@ TEST(CollatorFactoryICUTest, BackwardsFalseParsesSuccessfully) { CollatorFactoryICU factory; auto collator = factory.makeFromBSON(BSON("locale" << "en_US" - << "backwards" << false)); + << "backwards" + << false)); ASSERT_OK(collator.getStatus()); ASSERT_FALSE(collator.getValue()->getSpec().backwards); } @@ -625,7 +644,8 @@ TEST(CollatorFactoryICUTest, BackwardsTrueParsesSuccessfully) { CollatorFactoryICU factory; auto collator = factory.makeFromBSON(BSON("locale" << "en_US" - << "backwards" << true)); + << "backwards" + << true)); ASSERT_OK(collator.getStatus()); ASSERT_TRUE(collator.getValue()->getSpec().backwards); } @@ -634,7 +654,8 @@ TEST(CollatorFactoryICUTest, LongStrengthFieldParsesSuccessfully) { CollatorFactoryICU factory; auto collator = factory.makeFromBSON(BSON("locale" << "en_US" - << "strength" << 1LL)); + << "strength" + << 1LL)); ASSERT_OK(collator.getStatus()); ASSERT_EQ(static_cast<int>(CollationSpec::StrengthType::kPrimary), static_cast<int>(collator.getValue()->getSpec().strength)); @@ -644,7 +665,8 @@ TEST(CollatorFactoryICUTest, DoubleStrengthFieldParsesSuccessfully) { CollatorFactoryICU factory; auto collator = factory.makeFromBSON(BSON("locale" << "en_US" - << "strength" << 1.0)); + << "strength" + << 1.0)); ASSERT_OK(collator.getStatus()); ASSERT_EQ(static_cast<int>(CollationSpec::StrengthType::kPrimary), static_cast<int>(collator.getValue()->getSpec().strength)); @@ -664,7 +686,8 @@ TEST(CollatorFactoryICUTest, NonStringCaseFirstFieldFailsToParse) { CollatorFactoryICU factory; auto collator = factory.makeFromBSON(BSON("locale" << "en_US" - << "caseFirst" << 1)); + << "caseFirst" + << 1)); ASSERT_NOT_OK(collator.getStatus()); ASSERT_EQ(collator.getStatus(), ErrorCodes::TypeMismatch); } @@ -693,7 +716,8 @@ TEST(CollatorFactoryICUTest, TooLargeStrengthFieldFailsToParse) { CollatorFactoryICU factory; auto collator = factory.makeFromBSON(BSON("locale" << "en_US" - << "strength" << 2147483648LL)); + << "strength" + << 2147483648LL)); ASSERT_NOT_OK(collator.getStatus()); ASSERT_EQ(collator.getStatus(), ErrorCodes::FailedToParse); } @@ -702,7 +726,8 @@ TEST(CollatorFactoryICUTest, FractionalStrengthFieldFailsToParse) { CollatorFactoryICU factory; auto collator = factory.makeFromBSON(BSON("locale" << "en_US" - << "strength" << 0.5)); + << "strength" + << 0.5)); ASSERT_NOT_OK(collator.getStatus()); ASSERT_EQ(collator.getStatus(), ErrorCodes::BadValue); } @@ -711,7 +736,8 @@ TEST(CollatorFactoryICUTest, NegativeStrengthFieldFailsToParse) { CollatorFactoryICU factory; auto collator = factory.makeFromBSON(BSON("locale" << "en_US" - << "strength" << -1)); + << "strength" + << -1)); ASSERT_NOT_OK(collator.getStatus()); ASSERT_EQ(collator.getStatus(), ErrorCodes::FailedToParse); } @@ -720,7 +746,8 @@ TEST(CollatorFactoryICUTest, InvalidIntegerStrengthFieldFailsToParse) { CollatorFactoryICU factory; auto collator = factory.makeFromBSON(BSON("locale" << "en_US" - << "strength" << 6)); + << "strength" + << 6)); ASSERT_NOT_OK(collator.getStatus()); ASSERT_EQ(collator.getStatus(), ErrorCodes::FailedToParse); } @@ -739,7 +766,8 @@ TEST(CollatorFactoryICUTest, NonStringAlternateFieldFailsToParse) { CollatorFactoryICU factory; auto collator = factory.makeFromBSON(BSON("locale" << "en_US" - << "alternate" << 1)); + << "alternate" + << 1)); ASSERT_NOT_OK(collator.getStatus()); ASSERT_EQ(collator.getStatus(), ErrorCodes::TypeMismatch); } @@ -758,7 +786,8 @@ TEST(CollatorFactoryICUTest, NonStringMaxVariableFieldFailsToParse) { CollatorFactoryICU factory; auto collator = factory.makeFromBSON(BSON("locale" << "en_US" - << "maxVariable" << 1)); + << "maxVariable" + << 1)); ASSERT_NOT_OK(collator.getStatus()); ASSERT_EQ(collator.getStatus(), ErrorCodes::TypeMismatch); } @@ -810,7 +839,8 @@ TEST(CollatorFactoryICUTest, PrimaryStrengthCollatorIgnoresCaseAndAccents) { CollatorFactoryICU factory; auto collator = factory.makeFromBSON(BSON("locale" << "en_US" - << "strength" << 1)); + << "strength" + << 1)); ASSERT_OK(collator.getStatus()); // u8"\u00E1" is latin small letter a with acute. @@ -822,7 +852,8 @@ TEST(CollatorFactoryICUTest, SecondaryStrengthCollatorsIgnoresCaseButNotAccents) CollatorFactoryICU factory; auto collator = factory.makeFromBSON(BSON("locale" << "en_US" - << "strength" << 2)); + << "strength" + << 2)); ASSERT_OK(collator.getStatus()); // u8"\u00E1" is latin small letter a with acute. @@ -834,7 +865,8 @@ TEST(CollatorFactoryICUTest, TertiaryStrengthCollatorConsidersCaseAndAccents) { CollatorFactoryICU factory; auto collator = factory.makeFromBSON(BSON("locale" << "en_US" - << "strength" << 3)); + << "strength" + << 3)); ASSERT_OK(collator.getStatus()); // u8"\u00E1" is latin small letter a with acute. @@ -846,7 +878,10 @@ TEST(CollatorFactoryICUTest, PrimaryStrengthCaseLevelTrue) { CollatorFactoryICU factory; auto collator = factory.makeFromBSON(BSON("locale" << "en_US" - << "strength" << 1 << "caseLevel" << true)); + << "strength" + << 1 + << "caseLevel" + << true)); ASSERT_OK(collator.getStatus()); // u8"\u00E1" is latin small letter a with acute. @@ -856,11 +891,14 @@ TEST(CollatorFactoryICUTest, PrimaryStrengthCaseLevelTrue) { TEST(CollatorFactoryICUTest, PrimaryStrengthCaseLevelTrueCaseFirstUpper) { CollatorFactoryICU factory; - auto collator = - factory.makeFromBSON(BSON("locale" - << "en_US" - << "strength" << 1 << "caseLevel" << true << "caseFirst" - << "upper")); + auto collator = factory.makeFromBSON(BSON("locale" + << "en_US" + << "strength" + << 1 + << "caseLevel" + << true + << "caseFirst" + << "upper")); ASSERT_OK(collator.getStatus()); // u8"\u00E1" is latin small letter a with acute. @@ -870,11 +908,14 @@ TEST(CollatorFactoryICUTest, PrimaryStrengthCaseLevelTrueCaseFirstUpper) { TEST(CollatorFactoryICUTest, TertiaryStrengthCaseLevelTrueCaseFirstUpper) { CollatorFactoryICU factory; - auto collator = - factory.makeFromBSON(BSON("locale" - << "en_US" - << "strength" << 3 << "caseLevel" << true << "caseFirst" - << "upper")); + auto collator = factory.makeFromBSON(BSON("locale" + << "en_US" + << "strength" + << 3 + << "caseLevel" + << true + << "caseFirst" + << "upper")); ASSERT_OK(collator.getStatus()); ASSERT_LT(collator.getValue()->compare("A", "a"), 0); } @@ -891,7 +932,8 @@ TEST(CollatorFactoryICUTest, NumericOrderingTrue) { CollatorFactoryICU factory; auto collator = factory.makeFromBSON(BSON("locale" << "en_US" - << "numericOrdering" << true)); + << "numericOrdering" + << true)); ASSERT_OK(collator.getStatus()); ASSERT_LT(collator.getValue()->compare("2", "10"), 0); } @@ -900,7 +942,9 @@ TEST(CollatorFactoryICUTest, PrimaryStrengthAlternateShifted) { CollatorFactoryICU factory; auto collator = factory.makeFromBSON(BSON("locale" << "en_US" - << "strength" << 1 << "alternate" + << "strength" + << 1 + << "alternate" << "shifted")); ASSERT_OK(collator.getStatus()); ASSERT_EQ(collator.getValue()->compare("a b", "ab"), 0); @@ -911,7 +955,9 @@ TEST(CollatorFactoryICUTest, QuaternaryStrengthAlternateShifted) { CollatorFactoryICU factory; auto collator = factory.makeFromBSON(BSON("locale" << "en_US" - << "strength" << 4 << "alternate" + << "strength" + << 4 + << "alternate" << "shifted")); ASSERT_OK(collator.getStatus()); ASSERT_LT(collator.getValue()->compare("a b", "ab"), 0); @@ -922,7 +968,9 @@ TEST(CollatorFactoryICUTest, PrimaryStrengthAlternateShiftedMaxVariableSpace) { CollatorFactoryICU factory; auto collator = factory.makeFromBSON(BSON("locale" << "en_US" - << "strength" << 1 << "alternate" + << "strength" + << 1 + << "alternate" << "shifted" << "maxVariable" << "space")); @@ -935,7 +983,8 @@ TEST(CollatorFactoryICUTest, SecondaryStrengthBackwardsFalse) { CollatorFactoryICU factory; auto collator = factory.makeFromBSON(BSON("locale" << "en_US" - << "strength" << 2)); + << "strength" + << 2)); ASSERT_OK(collator.getStatus()); // u8"\u00E1" is latin small letter a with acute. @@ -946,7 +995,10 @@ TEST(CollatorFactoryICUTest, SecondaryStrengthBackwardsTrue) { CollatorFactoryICU factory; auto collator = factory.makeFromBSON(BSON("locale" << "en_US" - << "strength" << 2 << "backwards" << true)); + << "strength" + << 2 + << "backwards" + << true)); ASSERT_OK(collator.getStatus()); // u8"\u00E1" is latin small letter a with acute. @@ -975,320 +1027,426 @@ TEST(CollatorFactoryICUTest, FactoryMadeCollatorComparisonKeysCorrectEnUS) { TEST(CollatorFactoryICUTest, FactoryInitializationSucceedsWithArabicLocale) { CollatorFactoryICU factory; - ASSERT_OK(factory.makeFromBSON(BSON("locale" - << "ar")).getStatus()); + ASSERT_OK(factory + .makeFromBSON(BSON("locale" + << "ar")) + .getStatus()); } TEST(CollatorFactoryICUTest, FactoryInitializationSucceedsWithArmenianLocale) { CollatorFactoryICU factory; - ASSERT_OK(factory.makeFromBSON(BSON("locale" - << "hy")).getStatus()); + ASSERT_OK(factory + .makeFromBSON(BSON("locale" + << "hy")) + .getStatus()); } TEST(CollatorFactoryICUTest, FactoryInitializationSucceedsWithBengaliLocale) { CollatorFactoryICU factory; - ASSERT_OK(factory.makeFromBSON(BSON("locale" - << "bn")).getStatus()); + ASSERT_OK(factory + .makeFromBSON(BSON("locale" + << "bn")) + .getStatus()); } TEST(CollatorFactoryICUTest, FactoryInitializationSucceedsWithCatalanLocale) { CollatorFactoryICU factory; - ASSERT_OK(factory.makeFromBSON(BSON("locale" - << "ca")).getStatus()); + ASSERT_OK(factory + .makeFromBSON(BSON("locale" + << "ca")) + .getStatus()); } TEST(CollatorFactoryICUTest, FactoryInitializationSucceedsWithChineseLocale) { CollatorFactoryICU factory; - ASSERT_OK(factory.makeFromBSON(BSON("locale" - << "zh")).getStatus()); + ASSERT_OK(factory + .makeFromBSON(BSON("locale" + << "zh")) + .getStatus()); } TEST(CollatorFactoryICUTest, FactoryInitializationSucceedsWithChineseTraditionalLocale) { CollatorFactoryICU factory; - ASSERT_OK(factory.makeFromBSON(BSON("locale" - << "zh_Hant")).getStatus()); + ASSERT_OK(factory + .makeFromBSON(BSON("locale" + << "zh_Hant")) + .getStatus()); } TEST(CollatorFactoryICUTest, FactoryInitializationSucceedsWithCroatianLocale) { CollatorFactoryICU factory; - ASSERT_OK(factory.makeFromBSON(BSON("locale" - << "hr")).getStatus()); + ASSERT_OK(factory + .makeFromBSON(BSON("locale" + << "hr")) + .getStatus()); } TEST(CollatorFactoryICUTest, FactoryInitializationSucceedsWithCzechLocale) { CollatorFactoryICU factory; - ASSERT_OK(factory.makeFromBSON(BSON("locale" - << "cs")).getStatus()); + ASSERT_OK(factory + .makeFromBSON(BSON("locale" + << "cs")) + .getStatus()); } TEST(CollatorFactoryICUTest, FactoryInitializationSucceedsWithDanishLocale) { CollatorFactoryICU factory; - ASSERT_OK(factory.makeFromBSON(BSON("locale" - << "da")).getStatus()); + ASSERT_OK(factory + .makeFromBSON(BSON("locale" + << "da")) + .getStatus()); } TEST(CollatorFactoryICUTest, FactoryInitializationSucceedsWithEnglishLocale) { CollatorFactoryICU factory; - ASSERT_OK(factory.makeFromBSON(BSON("locale" - << "en")).getStatus()); + ASSERT_OK(factory + .makeFromBSON(BSON("locale" + << "en")) + .getStatus()); } TEST(CollatorFactoryICUTest, FactoryInitializationSucceedsWithEnglishUnitedStatesLocale) { CollatorFactoryICU factory; - ASSERT_OK(factory.makeFromBSON(BSON("locale" - << "en_US")).getStatus()); + ASSERT_OK(factory + .makeFromBSON(BSON("locale" + << "en_US")) + .getStatus()); } TEST(CollatorFactoryICUTest, FactoryInitializationSucceedsWithEnglishUnitedStatesComputerLocale) { CollatorFactoryICU factory; - ASSERT_OK(factory.makeFromBSON(BSON("locale" - << "en_US_POSIX")).getStatus()); + ASSERT_OK(factory + .makeFromBSON(BSON("locale" + << "en_US_POSIX")) + .getStatus()); } TEST(CollatorFactoryICUTest, FactoryInitializationSucceedsWithEstonianLocale) { CollatorFactoryICU factory; - ASSERT_OK(factory.makeFromBSON(BSON("locale" - << "et")).getStatus()); + ASSERT_OK(factory + .makeFromBSON(BSON("locale" + << "et")) + .getStatus()); } TEST(CollatorFactoryICUTest, FactoryInitializationSucceedsWithFilipinoLocale) { CollatorFactoryICU factory; - ASSERT_OK(factory.makeFromBSON(BSON("locale" - << "fil")).getStatus()); + ASSERT_OK(factory + .makeFromBSON(BSON("locale" + << "fil")) + .getStatus()); } TEST(CollatorFactoryICUTest, FactoryInitializationSucceedsWithFinnishLocale) { CollatorFactoryICU factory; - ASSERT_OK(factory.makeFromBSON(BSON("locale" - << "fi")).getStatus()); + ASSERT_OK(factory + .makeFromBSON(BSON("locale" + << "fi")) + .getStatus()); } TEST(CollatorFactoryICUTest, FactoryInitializationSucceedsWithFrenchLocale) { CollatorFactoryICU factory; - ASSERT_OK(factory.makeFromBSON(BSON("locale" - << "fr")).getStatus()); + ASSERT_OK(factory + .makeFromBSON(BSON("locale" + << "fr")) + .getStatus()); } TEST(CollatorFactoryICUTest, FactoryInitializationSucceedsWithFrenchCanadaLocale) { CollatorFactoryICU factory; - ASSERT_OK(factory.makeFromBSON(BSON("locale" - << "fr_CA")).getStatus()); + ASSERT_OK(factory + .makeFromBSON(BSON("locale" + << "fr_CA")) + .getStatus()); } TEST(CollatorFactoryICUTest, FactoryInitializationSucceedsWithGeorgianLocale) { CollatorFactoryICU factory; - ASSERT_OK(factory.makeFromBSON(BSON("locale" - << "ka")).getStatus()); + ASSERT_OK(factory + .makeFromBSON(BSON("locale" + << "ka")) + .getStatus()); } TEST(CollatorFactoryICUTest, FactoryInitializationSucceedsWithGermanLocale) { CollatorFactoryICU factory; - ASSERT_OK(factory.makeFromBSON(BSON("locale" - << "de")).getStatus()); + ASSERT_OK(factory + .makeFromBSON(BSON("locale" + << "de")) + .getStatus()); } TEST(CollatorFactoryICUTest, FactoryInitializationSucceedsWithGermanAustriaLocale) { CollatorFactoryICU factory; - ASSERT_OK(factory.makeFromBSON(BSON("locale" - << "de_AT")).getStatus()); + ASSERT_OK(factory + .makeFromBSON(BSON("locale" + << "de_AT")) + .getStatus()); } TEST(CollatorFactoryICUTest, FactoryInitializationSucceedsWithGreekLocale) { CollatorFactoryICU factory; - ASSERT_OK(factory.makeFromBSON(BSON("locale" - << "el")).getStatus()); + ASSERT_OK(factory + .makeFromBSON(BSON("locale" + << "el")) + .getStatus()); } TEST(CollatorFactoryICUTest, FactoryInitializationSucceedsWithHebrewLocale) { CollatorFactoryICU factory; - ASSERT_OK(factory.makeFromBSON(BSON("locale" - << "he")).getStatus()); + ASSERT_OK(factory + .makeFromBSON(BSON("locale" + << "he")) + .getStatus()); } TEST(CollatorFactoryICUTest, FactoryInitializationSucceedsWithHindiLocale) { CollatorFactoryICU factory; - ASSERT_OK(factory.makeFromBSON(BSON("locale" - << "hi")).getStatus()); + ASSERT_OK(factory + .makeFromBSON(BSON("locale" + << "hi")) + .getStatus()); } TEST(CollatorFactoryICUTest, FactoryInitializationSucceedsWithHungarianLocale) { CollatorFactoryICU factory; - ASSERT_OK(factory.makeFromBSON(BSON("locale" - << "hu")).getStatus()); + ASSERT_OK(factory + .makeFromBSON(BSON("locale" + << "hu")) + .getStatus()); } TEST(CollatorFactoryICUTest, FactoryInitializationSucceedsWithIcelandicLocale) { CollatorFactoryICU factory; - ASSERT_OK(factory.makeFromBSON(BSON("locale" - << "is")).getStatus()); + ASSERT_OK(factory + .makeFromBSON(BSON("locale" + << "is")) + .getStatus()); } TEST(CollatorFactoryICUTest, FactoryInitializationSucceedsWithIndonesianLocale) { CollatorFactoryICU factory; - ASSERT_OK(factory.makeFromBSON(BSON("locale" - << "id")).getStatus()); + ASSERT_OK(factory + .makeFromBSON(BSON("locale" + << "id")) + .getStatus()); } TEST(CollatorFactoryICUTest, FactoryInitializationSucceedsWithIrishLocale) { CollatorFactoryICU factory; - ASSERT_OK(factory.makeFromBSON(BSON("locale" - << "ga")).getStatus()); + ASSERT_OK(factory + .makeFromBSON(BSON("locale" + << "ga")) + .getStatus()); } TEST(CollatorFactoryICUTest, FactoryInitializationSucceedsWithItalianLocale) { CollatorFactoryICU factory; - ASSERT_OK(factory.makeFromBSON(BSON("locale" - << "it")).getStatus()); + ASSERT_OK(factory + .makeFromBSON(BSON("locale" + << "it")) + .getStatus()); } TEST(CollatorFactoryICUTest, FactoryInitializationSucceedsWithJapaneseLocale) { CollatorFactoryICU factory; - ASSERT_OK(factory.makeFromBSON(BSON("locale" - << "ja")).getStatus()); + ASSERT_OK(factory + .makeFromBSON(BSON("locale" + << "ja")) + .getStatus()); } TEST(CollatorFactoryICUTest, FactoryInitializationSucceedsWithKoreanLocale) { CollatorFactoryICU factory; - ASSERT_OK(factory.makeFromBSON(BSON("locale" - << "ko")).getStatus()); + ASSERT_OK(factory + .makeFromBSON(BSON("locale" + << "ko")) + .getStatus()); } TEST(CollatorFactoryICUTest, FactoryInitializationSucceedsWithLatvianLocale) { CollatorFactoryICU factory; - ASSERT_OK(factory.makeFromBSON(BSON("locale" - << "lv")).getStatus()); + ASSERT_OK(factory + .makeFromBSON(BSON("locale" + << "lv")) + .getStatus()); } TEST(CollatorFactoryICUTest, FactoryInitializationSucceedsWithLithuanianLocale) { CollatorFactoryICU factory; - ASSERT_OK(factory.makeFromBSON(BSON("locale" - << "lt")).getStatus()); + ASSERT_OK(factory + .makeFromBSON(BSON("locale" + << "lt")) + .getStatus()); } TEST(CollatorFactoryICUTest, FactoryInitializationSucceedsWithNorwegianNynorskLocale) { CollatorFactoryICU factory; - ASSERT_OK(factory.makeFromBSON(BSON("locale" - << "nn")).getStatus()); + ASSERT_OK(factory + .makeFromBSON(BSON("locale" + << "nn")) + .getStatus()); } TEST(CollatorFactoryICUTest, FactoryInitializationSucceedsWithPashtoLocale) { CollatorFactoryICU factory; - ASSERT_OK(factory.makeFromBSON(BSON("locale" - << "ps")).getStatus()); + ASSERT_OK(factory + .makeFromBSON(BSON("locale" + << "ps")) + .getStatus()); } TEST(CollatorFactoryICUTest, FactoryInitializationSucceedsWithPersianLocale) { CollatorFactoryICU factory; - ASSERT_OK(factory.makeFromBSON(BSON("locale" - << "fa")).getStatus()); + ASSERT_OK(factory + .makeFromBSON(BSON("locale" + << "fa")) + .getStatus()); } TEST(CollatorFactoryICUTest, FactoryInitializationSucceedsWithPersianAfghanistanLocale) { CollatorFactoryICU factory; - ASSERT_OK(factory.makeFromBSON(BSON("locale" - << "fa_AF")).getStatus()); + ASSERT_OK(factory + .makeFromBSON(BSON("locale" + << "fa_AF")) + .getStatus()); } TEST(CollatorFactoryICUTest, FactoryInitializationSucceedsWithPolishLocale) { CollatorFactoryICU factory; - ASSERT_OK(factory.makeFromBSON(BSON("locale" - << "pl")).getStatus()); + ASSERT_OK(factory + .makeFromBSON(BSON("locale" + << "pl")) + .getStatus()); } TEST(CollatorFactoryICUTest, FactoryInitializationSucceedsWithPortugueseLocale) { CollatorFactoryICU factory; - ASSERT_OK(factory.makeFromBSON(BSON("locale" - << "pt")).getStatus()); + ASSERT_OK(factory + .makeFromBSON(BSON("locale" + << "pt")) + .getStatus()); } TEST(CollatorFactoryICUTest, FactoryInitializationSucceedsWithPunjabiLocale) { CollatorFactoryICU factory; - ASSERT_OK(factory.makeFromBSON(BSON("locale" - << "pa")).getStatus()); + ASSERT_OK(factory + .makeFromBSON(BSON("locale" + << "pa")) + .getStatus()); } TEST(CollatorFactoryICUTest, FactoryInitializationSucceedsWithRomanianLocale) { CollatorFactoryICU factory; - ASSERT_OK(factory.makeFromBSON(BSON("locale" - << "ro")).getStatus()); + ASSERT_OK(factory + .makeFromBSON(BSON("locale" + << "ro")) + .getStatus()); } TEST(CollatorFactoryICUTest, FactoryInitializationSucceedsWithRussianLocale) { CollatorFactoryICU factory; - ASSERT_OK(factory.makeFromBSON(BSON("locale" - << "ru")).getStatus()); + ASSERT_OK(factory + .makeFromBSON(BSON("locale" + << "ru")) + .getStatus()); } TEST(CollatorFactoryICUTest, FactoryInitializationSucceedsWithSlovakLocale) { CollatorFactoryICU factory; - ASSERT_OK(factory.makeFromBSON(BSON("locale" - << "sk")).getStatus()); + ASSERT_OK(factory + .makeFromBSON(BSON("locale" + << "sk")) + .getStatus()); } TEST(CollatorFactoryICUTest, FactoryInitializationSucceedsWithSlovenianLocale) { CollatorFactoryICU factory; - ASSERT_OK(factory.makeFromBSON(BSON("locale" - << "sl")).getStatus()); + ASSERT_OK(factory + .makeFromBSON(BSON("locale" + << "sl")) + .getStatus()); } TEST(CollatorFactoryICUTest, FactoryInitializationSucceedsWithSpanishLocale) { CollatorFactoryICU factory; - ASSERT_OK(factory.makeFromBSON(BSON("locale" - << "es")).getStatus()); + ASSERT_OK(factory + .makeFromBSON(BSON("locale" + << "es")) + .getStatus()); } TEST(CollatorFactoryICUTest, FactoryInitializationSucceedsWithSwedishLocale) { CollatorFactoryICU factory; - ASSERT_OK(factory.makeFromBSON(BSON("locale" - << "sv")).getStatus()); + ASSERT_OK(factory + .makeFromBSON(BSON("locale" + << "sv")) + .getStatus()); } TEST(CollatorFactoryICUTest, FactoryInitializationSucceedsWithThaiLocale) { CollatorFactoryICU factory; - ASSERT_OK(factory.makeFromBSON(BSON("locale" - << "th")).getStatus()); + ASSERT_OK(factory + .makeFromBSON(BSON("locale" + << "th")) + .getStatus()); } TEST(CollatorFactoryICUTest, FactoryInitializationSucceedsWithTurkishLocale) { CollatorFactoryICU factory; - ASSERT_OK(factory.makeFromBSON(BSON("locale" - << "tr")).getStatus()); + ASSERT_OK(factory + .makeFromBSON(BSON("locale" + << "tr")) + .getStatus()); } TEST(CollatorFactoryICUTest, FactoryInitializationSucceedsWithUkrainianLocale) { CollatorFactoryICU factory; - ASSERT_OK(factory.makeFromBSON(BSON("locale" - << "uk")).getStatus()); + ASSERT_OK(factory + .makeFromBSON(BSON("locale" + << "uk")) + .getStatus()); } TEST(CollatorFactoryICUTest, FactoryInitializationSucceedsWithUrduLocale) { CollatorFactoryICU factory; - ASSERT_OK(factory.makeFromBSON(BSON("locale" - << "ur")).getStatus()); + ASSERT_OK(factory + .makeFromBSON(BSON("locale" + << "ur")) + .getStatus()); } TEST(CollatorFactoryICUTest, FactoryInitializationSucceedsWithVietnameseLocale) { CollatorFactoryICU factory; - ASSERT_OK(factory.makeFromBSON(BSON("locale" - << "vi")).getStatus()); + ASSERT_OK(factory + .makeFromBSON(BSON("locale" + << "vi")) + .getStatus()); } TEST(CollatorFactoryICUTest, FactoryInitializationFailsWithAfrikaansLocale) { CollatorFactoryICU factory; - ASSERT_NOT_OK(factory.makeFromBSON(BSON("locale" - << "af")).getStatus()); + ASSERT_NOT_OK(factory + .makeFromBSON(BSON("locale" + << "af")) + .getStatus()); } TEST(CollatorFactoryICUTest, FactoryInitializationFailsWithEsperantoLocale) { CollatorFactoryICU factory; - ASSERT_NOT_OK(factory.makeFromBSON(BSON("locale" - << "eo")).getStatus()); + ASSERT_NOT_OK(factory + .makeFromBSON(BSON("locale" + << "eo")) + .getStatus()); } TEST(CollatorFactoryICUTest, FactoryInitializationFailsWithSwahiliLocale) { CollatorFactoryICU factory; - ASSERT_NOT_OK(factory.makeFromBSON(BSON("locale" - << "sw")).getStatus()); + ASSERT_NOT_OK(factory + .makeFromBSON(BSON("locale" + << "sw")) + .getStatus()); } } // namespace diff --git a/src/mongo/db/query/collation/collator_factory_mock.cpp b/src/mongo/db/query/collation/collator_factory_mock.cpp index 503b84c7f79..f6d10450de9 100644 --- a/src/mongo/db/query/collation/collator_factory_mock.cpp +++ b/src/mongo/db/query/collation/collator_factory_mock.cpp @@ -30,8 +30,8 @@ #include "mongo/db/query/collation/collator_factory_mock.h" -#include "mongo/bson/bsonobj.h" #include "mongo/base/status_with.h" +#include "mongo/bson/bsonobj.h" #include "mongo/db/query/collation/collator_interface_mock.h" #include "mongo/stdx/memory.h" diff --git a/src/mongo/db/query/count_request_test.cpp b/src/mongo/db/query/count_request_test.cpp index cea7d0e3885..3b7ceeb400b 100644 --- a/src/mongo/db/query/count_request_test.cpp +++ b/src/mongo/db/query/count_request_test.cpp @@ -30,8 +30,8 @@ #include "mongo/bson/json.h" #include "mongo/db/query/count_request.h" -#include "mongo/util/mongoutils/str.h" #include "mongo/unittest/unittest.h" +#include "mongo/util/mongoutils/str.h" namespace mongo { namespace { @@ -41,7 +41,8 @@ TEST(CountRequest, ParseDefaults) { CountRequest::parseFromBSON("TestDB", BSON("count" << "TestColl" - << "query" << BSON("a" << BSON("$lte" << 10)))); + << "query" + << BSON("a" << BSON("$lte" << 10)))); ASSERT_OK(countRequestStatus.getStatus()); @@ -62,10 +63,17 @@ TEST(CountRequest, ParseComplete) { CountRequest::parseFromBSON("TestDB", BSON("count" << "TestColl" - << "query" << BSON("a" << BSON("$gte" << 11)) << "limit" - << 100 << "skip" << 1000 << "hint" << BSON("b" << 5) - << "collation" << BSON("locale" - << "en_US"))); + << "query" + << BSON("a" << BSON("$gte" << 11)) + << "limit" + << 100 + << "skip" + << 1000 + << "hint" + << BSON("b" << 5) + << "collation" + << BSON("locale" + << "en_US"))); ASSERT_OK(countRequestStatus.getStatus()); @@ -84,10 +92,17 @@ TEST(CountRequest, ParseNegativeLimit) { CountRequest::parseFromBSON("TestDB", BSON("count" << "TestColl" - << "query" << BSON("a" << BSON("$gte" << 11)) << "limit" - << -100 << "skip" << 1000 << "hint" << BSON("b" << 5) - << "collation" << BSON("locale" - << "en_US"))); + << "query" + << BSON("a" << BSON("$gte" << 11)) + << "limit" + << -100 + << "skip" + << 1000 + << "hint" + << BSON("b" << 5) + << "collation" + << BSON("locale" + << "en_US"))); ASSERT_OK(countRequestStatus.getStatus()); @@ -113,7 +128,9 @@ TEST(CountRequest, FailParseBadSkipValue) { CountRequest::parseFromBSON("TestDB", BSON("count" << "TestColl" - << "query" << BSON("a" << BSON("$gte" << 11)) << "skip" + << "query" + << BSON("a" << BSON("$gte" << 11)) + << "skip" << -1000)); ASSERT_EQUALS(countRequestStatus.getStatus(), ErrorCodes::BadValue); @@ -124,7 +141,8 @@ TEST(CountRequest, FailParseBadCollationValue) { CountRequest::parseFromBSON("TestDB", BSON("count" << "TestColl" - << "query" << BSON("a" << BSON("$gte" << 11)) + << "query" + << BSON("a" << BSON("$gte" << 11)) << "collation" << "en_US")); @@ -140,13 +158,13 @@ TEST(CountRequest, ToBSON) { << "en_US")); BSONObj actualObj = countRequest.toBSON(); - BSONObj expectedObj(fromjson( - "{ count : 'TestDB.TestColl'," - " query : { a : { '$gte' : 11 } }," - " limit : 100," - " skip : 1000," - " hint : { b : 5 }," - " collation : { locale : 'en_US' } },")); + BSONObj expectedObj( + fromjson("{ count : 'TestDB.TestColl'," + " query : { a : { '$gte' : 11 } }," + " limit : 100," + " skip : 1000," + " hint : { b : 5 }," + " collation : { locale : 'en_US' } },")); ASSERT_EQUALS(actualObj, expectedObj); } diff --git a/src/mongo/db/query/cursor_response.cpp b/src/mongo/db/query/cursor_response.cpp index bf812d302a8..33a1661ea0b 100644 --- a/src/mongo/db/query/cursor_response.cpp +++ b/src/mongo/db/query/cursor_response.cpp @@ -123,24 +123,24 @@ StatusWith<CursorResponse> CursorResponse::parseFromBSON(const BSONObj& cmdRespo BSONElement cursorElt = cmdResponse[kCursorField]; if (cursorElt.type() != BSONType::Object) { return {ErrorCodes::TypeMismatch, - str::stream() << "Field '" << kCursorField - << "' must be a nested object in: " << cmdResponse}; + str::stream() << "Field '" << kCursorField << "' must be a nested object in: " + << cmdResponse}; } BSONObj cursorObj = cursorElt.Obj(); BSONElement idElt = cursorObj[kIdField]; if (idElt.type() != BSONType::NumberLong) { - return {ErrorCodes::TypeMismatch, - str::stream() << "Field '" << kIdField - << "' must be of type long in: " << cmdResponse}; + return { + ErrorCodes::TypeMismatch, + str::stream() << "Field '" << kIdField << "' must be of type long in: " << cmdResponse}; } cursorId = idElt.Long(); BSONElement nsElt = cursorObj[kNsField]; if (nsElt.type() != BSONType::String) { return {ErrorCodes::TypeMismatch, - str::stream() << "Field '" << kNsField - << "' must be of type string in: " << cmdResponse}; + str::stream() << "Field '" << kNsField << "' must be of type string in: " + << cmdResponse}; } fullns = nsElt.String(); @@ -152,16 +152,18 @@ StatusWith<CursorResponse> CursorResponse::parseFromBSON(const BSONObj& cmdRespo if (batchElt.type() != BSONType::Array) { return {ErrorCodes::TypeMismatch, str::stream() << "Must have array field '" << kBatchFieldInitial << "' or '" - << kBatchField << "' in: " << cmdResponse}; + << kBatchField + << "' in: " + << cmdResponse}; } batchObj = batchElt.Obj(); std::vector<BSONObj> batch; for (BSONElement elt : batchObj) { if (elt.type() != BSONType::Object) { - return { - ErrorCodes::BadValue, - str::stream() << "getMore response batch contains a non-object element: " << elt}; + return {ErrorCodes::BadValue, + str::stream() << "getMore response batch contains a non-object element: " + << elt}; } batch.push_back(elt.Obj().getOwned()); diff --git a/src/mongo/db/query/cursor_response_test.cpp b/src/mongo/db/query/cursor_response_test.cpp index 0229f526ca4..711d83d4213 100644 --- a/src/mongo/db/query/cursor_response_test.cpp +++ b/src/mongo/db/query/cursor_response_test.cpp @@ -37,11 +37,13 @@ namespace mongo { namespace { TEST(CursorResponseTest, parseFromBSONFirstBatch) { - StatusWith<CursorResponse> result = CursorResponse::parseFromBSON(BSON( - "cursor" << BSON("id" << CursorId(123) << "ns" - << "db.coll" - << "firstBatch" << BSON_ARRAY(BSON("_id" << 1) << BSON("_id" << 2))) - << "ok" << 1)); + StatusWith<CursorResponse> result = CursorResponse::parseFromBSON( + BSON("cursor" << BSON("id" << CursorId(123) << "ns" + << "db.coll" + << "firstBatch" + << BSON_ARRAY(BSON("_id" << 1) << BSON("_id" << 2))) + << "ok" + << 1)); ASSERT_OK(result.getStatus()); CursorResponse response = std::move(result.getValue()); @@ -53,11 +55,13 @@ TEST(CursorResponseTest, parseFromBSONFirstBatch) { } TEST(CursorResponseTest, parseFromBSONNextBatch) { - StatusWith<CursorResponse> result = CursorResponse::parseFromBSON(BSON( - "cursor" << BSON("id" << CursorId(123) << "ns" - << "db.coll" - << "nextBatch" << BSON_ARRAY(BSON("_id" << 1) << BSON("_id" << 2))) - << "ok" << 1)); + StatusWith<CursorResponse> result = CursorResponse::parseFromBSON( + BSON("cursor" << BSON("id" << CursorId(123) << "ns" + << "db.coll" + << "nextBatch" + << BSON_ARRAY(BSON("_id" << 1) << BSON("_id" << 2))) + << "ok" + << 1)); ASSERT_OK(result.getStatus()); CursorResponse response = std::move(result.getValue()); @@ -69,11 +73,13 @@ TEST(CursorResponseTest, parseFromBSONNextBatch) { } TEST(CursorResponseTest, parseFromBSONCursorIdZero) { - StatusWith<CursorResponse> result = CursorResponse::parseFromBSON(BSON( - "cursor" << BSON("id" << CursorId(0) << "ns" - << "db.coll" - << "nextBatch" << BSON_ARRAY(BSON("_id" << 1) << BSON("_id" << 2))) - << "ok" << 1)); + StatusWith<CursorResponse> result = CursorResponse::parseFromBSON( + BSON("cursor" << BSON("id" << CursorId(0) << "ns" + << "db.coll" + << "nextBatch" + << BSON_ARRAY(BSON("_id" << 1) << BSON("_id" << 2))) + << "ok" + << 1)); ASSERT_OK(result.getStatus()); CursorResponse response = std::move(result.getValue()); @@ -85,10 +91,13 @@ TEST(CursorResponseTest, parseFromBSONCursorIdZero) { } TEST(CursorResponseTest, parseFromBSONEmptyBatch) { - StatusWith<CursorResponse> result = CursorResponse::parseFromBSON( - BSON("cursor" << BSON("id" << CursorId(123) << "ns" - << "db.coll" - << "nextBatch" << BSONArrayBuilder().arr()) << "ok" << 1)); + StatusWith<CursorResponse> result = + CursorResponse::parseFromBSON(BSON("cursor" << BSON("id" << CursorId(123) << "ns" + << "db.coll" + << "nextBatch" + << BSONArrayBuilder().arr()) + << "ok" + << 1)); ASSERT_OK(result.getStatus()); CursorResponse response = std::move(result.getValue()); @@ -109,16 +118,20 @@ TEST(CursorResponseTest, parseFromBSONCursorFieldWrongType) { } TEST(CursorResponseTest, parseFromBSONNsFieldMissing) { - StatusWith<CursorResponse> result = CursorResponse::parseFromBSON(BSON( - "cursor" << BSON("id" << CursorId(123) << "firstBatch" - << BSON_ARRAY(BSON("_id" << 1) << BSON("_id" << 2))) << "ok" << 1)); + StatusWith<CursorResponse> result = CursorResponse::parseFromBSON( + BSON("cursor" << BSON("id" << CursorId(123) << "firstBatch" + << BSON_ARRAY(BSON("_id" << 1) << BSON("_id" << 2))) + << "ok" + << 1)); ASSERT_NOT_OK(result.getStatus()); } TEST(CursorResponseTest, parseFromBSONNsFieldWrongType) { - StatusWith<CursorResponse> result = CursorResponse::parseFromBSON(BSON( - "cursor" << BSON("id" << CursorId(123) << "ns" << 456 << "firstBatch" - << BSON_ARRAY(BSON("_id" << 1) << BSON("_id" << 2))) << "ok" << 1)); + StatusWith<CursorResponse> result = CursorResponse::parseFromBSON( + BSON("cursor" << BSON("id" << CursorId(123) << "ns" << 456 << "firstBatch" + << BSON_ARRAY(BSON("_id" << 1) << BSON("_id" << 2))) + << "ok" + << 1)); ASSERT_NOT_OK(result.getStatus()); } @@ -126,8 +139,10 @@ TEST(CursorResponseTest, parseFromBSONIdFieldMissing) { StatusWith<CursorResponse> result = CursorResponse::parseFromBSON( BSON("cursor" << BSON("ns" << "db.coll" - << "nextBatch" << BSON_ARRAY(BSON("_id" << 1) << BSON("_id" << 2))) - << "ok" << 1)); + << "nextBatch" + << BSON_ARRAY(BSON("_id" << 1) << BSON("_id" << 2))) + << "ok" + << 1)); ASSERT_NOT_OK(result.getStatus()); } @@ -137,39 +152,50 @@ TEST(CursorResponseTest, parseFromBSONIdFieldWrongType) { << "123" << "ns" << "db.coll" - << "nextBatch" << BSON_ARRAY(BSON("_id" << 1) << BSON("_id" << 2))) - << "ok" << 1)); + << "nextBatch" + << BSON_ARRAY(BSON("_id" << 1) << BSON("_id" << 2))) + << "ok" + << 1)); ASSERT_NOT_OK(result.getStatus()); } TEST(CursorResponseTest, parseFromBSONBatchFieldMissing) { StatusWith<CursorResponse> result = CursorResponse::parseFromBSON(BSON("cursor" << BSON("id" << CursorId(123) << "ns" - << "db.coll") << "ok" << 1)); + << "db.coll") + << "ok" + << 1)); ASSERT_NOT_OK(result.getStatus()); } TEST(CursorResponseTest, parseFromBSONFirstBatchFieldWrongType) { - StatusWith<CursorResponse> result = CursorResponse::parseFromBSON( - BSON("cursor" << BSON("id" << CursorId(123) << "ns" - << "db.coll" - << "firstBatch" << BSON("_id" << 1)) << "ok" << 1)); + StatusWith<CursorResponse> result = + CursorResponse::parseFromBSON(BSON("cursor" << BSON("id" << CursorId(123) << "ns" + << "db.coll" + << "firstBatch" + << BSON("_id" << 1)) + << "ok" + << 1)); ASSERT_NOT_OK(result.getStatus()); } TEST(CursorResponseTest, parseFromBSONNextBatchFieldWrongType) { - StatusWith<CursorResponse> result = CursorResponse::parseFromBSON( - BSON("cursor" << BSON("id" << CursorId(123) << "ns" - << "db.coll" - << "nextBatch" << BSON("_id" << 1)) << "ok" << 1)); + StatusWith<CursorResponse> result = + CursorResponse::parseFromBSON(BSON("cursor" << BSON("id" << CursorId(123) << "ns" + << "db.coll" + << "nextBatch" + << BSON("_id" << 1)) + << "ok" + << 1)); ASSERT_NOT_OK(result.getStatus()); } TEST(CursorResponseTest, parseFromBSONOkFieldMissing) { - StatusWith<CursorResponse> result = CursorResponse::parseFromBSON(BSON( - "cursor" << BSON("id" << CursorId(123) << "ns" - << "db.coll" - << "nextBatch" << BSON_ARRAY(BSON("_id" << 1) << BSON("_id" << 2))))); + StatusWith<CursorResponse> result = CursorResponse::parseFromBSON( + BSON("cursor" << BSON("id" << CursorId(123) << "ns" + << "db.coll" + << "nextBatch" + << BSON_ARRAY(BSON("_id" << 1) << BSON("_id" << 2))))); ASSERT_NOT_OK(result.getStatus()); } @@ -186,11 +212,13 @@ TEST(CursorResponseTest, toBSONInitialResponse) { std::vector<BSONObj> batch = {BSON("_id" << 1), BSON("_id" << 2)}; CursorResponse response(NamespaceString("testdb.testcoll"), CursorId(123), batch); BSONObj responseObj = response.toBSON(CursorResponse::ResponseType::InitialResponse); - BSONObj expectedResponse = BSON( - "cursor" << BSON("id" << CursorId(123) << "ns" - << "testdb.testcoll" - << "firstBatch" << BSON_ARRAY(BSON("_id" << 1) << BSON("_id" << 2))) - << "ok" << 1.0); + BSONObj expectedResponse = + BSON("cursor" << BSON("id" << CursorId(123) << "ns" + << "testdb.testcoll" + << "firstBatch" + << BSON_ARRAY(BSON("_id" << 1) << BSON("_id" << 2))) + << "ok" + << 1.0); ASSERT_EQ(responseObj, expectedResponse); } @@ -198,11 +226,13 @@ TEST(CursorResponseTest, toBSONSubsequentResponse) { std::vector<BSONObj> batch = {BSON("_id" << 1), BSON("_id" << 2)}; CursorResponse response(NamespaceString("testdb.testcoll"), CursorId(123), batch); BSONObj responseObj = response.toBSON(CursorResponse::ResponseType::SubsequentResponse); - BSONObj expectedResponse = BSON( - "cursor" << BSON("id" << CursorId(123) << "ns" - << "testdb.testcoll" - << "nextBatch" << BSON_ARRAY(BSON("_id" << 1) << BSON("_id" << 2))) - << "ok" << 1.0); + BSONObj expectedResponse = + BSON("cursor" << BSON("id" << CursorId(123) << "ns" + << "testdb.testcoll" + << "nextBatch" + << BSON_ARRAY(BSON("_id" << 1) << BSON("_id" << 2))) + << "ok" + << 1.0); ASSERT_EQ(responseObj, expectedResponse); } @@ -214,11 +244,13 @@ TEST(CursorResponseTest, addToBSONInitialResponse) { response.addToBSON(CursorResponse::ResponseType::InitialResponse, &builder); BSONObj responseObj = builder.obj(); - BSONObj expectedResponse = BSON( - "cursor" << BSON("id" << CursorId(123) << "ns" - << "testdb.testcoll" - << "firstBatch" << BSON_ARRAY(BSON("_id" << 1) << BSON("_id" << 2))) - << "ok" << 1.0); + BSONObj expectedResponse = + BSON("cursor" << BSON("id" << CursorId(123) << "ns" + << "testdb.testcoll" + << "firstBatch" + << BSON_ARRAY(BSON("_id" << 1) << BSON("_id" << 2))) + << "ok" + << 1.0); ASSERT_EQ(responseObj, expectedResponse); } @@ -230,11 +262,13 @@ TEST(CursorResponseTest, addToBSONSubsequentResponse) { response.addToBSON(CursorResponse::ResponseType::SubsequentResponse, &builder); BSONObj responseObj = builder.obj(); - BSONObj expectedResponse = BSON( - "cursor" << BSON("id" << CursorId(123) << "ns" - << "testdb.testcoll" - << "nextBatch" << BSON_ARRAY(BSON("_id" << 1) << BSON("_id" << 2))) - << "ok" << 1.0); + BSONObj expectedResponse = + BSON("cursor" << BSON("id" << CursorId(123) << "ns" + << "testdb.testcoll" + << "nextBatch" + << BSON_ARRAY(BSON("_id" << 1) << BSON("_id" << 2))) + << "ok" + << 1.0); ASSERT_EQ(responseObj, expectedResponse); } diff --git a/src/mongo/db/query/explain.cpp b/src/mongo/db/query/explain.cpp index 4e0c82aaa81..6475b5aaa5f 100644 --- a/src/mongo/db/query/explain.cpp +++ b/src/mongo/db/query/explain.cpp @@ -39,13 +39,13 @@ #include "mongo/db/exec/multi_plan.h" #include "mongo/db/exec/near.h" #include "mongo/db/exec/text.h" +#include "mongo/db/exec/working_set_common.h" #include "mongo/db/query/get_executor.h" #include "mongo/db/query/plan_executor.h" #include "mongo/db/query/plan_summary_stats.h" #include "mongo/db/query/query_planner.h" #include "mongo/db/query/query_settings.h" #include "mongo/db/query/stage_builder.h" -#include "mongo/db/exec/working_set_common.h" #include "mongo/db/server_options.h" #include "mongo/db/server_parameters.h" #include "mongo/util/mongoutils/str.h" diff --git a/src/mongo/db/query/expression_index.cpp b/src/mongo/db/query/expression_index.cpp index 6212c28016c..ff24396baeb 100644 --- a/src/mongo/db/query/expression_index.cpp +++ b/src/mongo/db/query/expression_index.cpp @@ -34,8 +34,8 @@ #include "mongo/db/geo/r2_region_coverer.h" #include "mongo/db/hasher.h" #include "mongo/db/index/expression_params.h" -#include "mongo/db/server_parameters.h" #include "mongo/db/query/expression_index_knobs.h" +#include "mongo/db/server_parameters.h" #include "third_party/s2/s2cellid.h" #include "third_party/s2/s2region.h" #include "third_party/s2/s2regioncoverer.h" diff --git a/src/mongo/db/query/find.cpp b/src/mongo/db/query/find.cpp index 0888b5e7085..88f09fcfa19 100644 --- a/src/mongo/db/query/find.cpp +++ b/src/mongo/db/query/find.cpp @@ -42,7 +42,6 @@ #include "mongo/db/db_raii.h" #include "mongo/db/exec/filter.h" #include "mongo/db/exec/working_set_common.h" -#include "mongo/db/service_context.h" #include "mongo/db/keypattern.h" #include "mongo/db/matcher/extensions_callback_real.h" #include "mongo/db/query/explain.h" @@ -55,6 +54,7 @@ #include "mongo/db/s/collection_sharding_state.h" #include "mongo/db/server_options.h" #include "mongo/db/server_parameters.h" +#include "mongo/db/service_context.h" #include "mongo/db/storage/storage_options.h" #include "mongo/s/chunk_version.h" #include "mongo/s/stale_exception.h" @@ -311,7 +311,9 @@ QueryResult::View getMore(OperationContext* txn, // there for the cursor. uassert(ErrorCodes::Unauthorized, str::stream() << "Requested getMore on namespace " << ns << ", but cursor " - << cursorid << " belongs to namespace " << cc->ns(), + << cursorid + << " belongs to namespace " + << cc->ns(), ns == cc->ns()); *isCursorAuthorized = true; @@ -504,9 +506,9 @@ std::string runQuery(OperationContext* txn, auto statusWithCQ = CanonicalQuery::canonicalize(txn, q, ExtensionsCallbackReal(txn, &nss)); if (!statusWithCQ.isOK()) { - uasserted( - 17287, - str::stream() << "Can't canonicalize query: " << statusWithCQ.getStatus().toString()); + uasserted(17287, + str::stream() << "Can't canonicalize query: " + << statusWithCQ.getStatus().toString()); } unique_ptr<CanonicalQuery> cq = std::move(statusWithCQ.getValue()); invariant(cq.get()); diff --git a/src/mongo/db/query/get_executor.cpp b/src/mongo/db/query/get_executor.cpp index f97810a90e0..c2330958e76 100644 --- a/src/mongo/db/query/get_executor.cpp +++ b/src/mongo/db/query/get_executor.cpp @@ -51,8 +51,8 @@ #include "mongo/db/exec/sort_key_generator.h" #include "mongo/db/exec/subplan.h" #include "mongo/db/exec/update.h" -#include "mongo/db/index_names.h" #include "mongo/db/index/index_descriptor.h" +#include "mongo/db/index_names.h" #include "mongo/db/matcher/extensions_callback_disallow_extensions.h" #include "mongo/db/matcher/extensions_callback_noop.h" #include "mongo/db/matcher/extensions_callback_real.h" @@ -71,14 +71,14 @@ #include "mongo/db/query/query_settings.h" #include "mongo/db/query/stage_builder.h" #include "mongo/db/repl/replication_coordinator_global.h" -#include "mongo/db/server_options.h" -#include "mongo/db/server_parameters.h" -#include "mongo/db/service_context.h" #include "mongo/db/s/collection_metadata.h" #include "mongo/db/s/collection_sharding_state.h" #include "mongo/db/s/sharding_state.h" -#include "mongo/db/storage/storage_options.h" +#include "mongo/db/server_options.h" +#include "mongo/db/server_parameters.h" +#include "mongo/db/service_context.h" #include "mongo/db/storage/oplog_hack.h" +#include "mongo/db/storage/storage_options.h" #include "mongo/scripting/engine.h" #include "mongo/stdx/memory.h" #include "mongo/util/log.h" @@ -774,7 +774,8 @@ inline void validateUpdate(const char* ns, const BSONObj& updateobj, const BSONO has pointers into it */ uassert(10156, str::stream() << "cannot update system collection: " << ns << " q: " << patternOrig - << " u: " << updateobj, + << " u: " + << updateobj, legalClientSystemNS(ns, true)); } } diff --git a/src/mongo/db/query/get_executor.h b/src/mongo/db/query/get_executor.h index 0488aeccf7d..c15c7144370 100644 --- a/src/mongo/db/query/get_executor.h +++ b/src/mongo/db/query/get_executor.h @@ -26,16 +26,16 @@ * it in the license file. */ -#include "mongo/db/query/canonical_query.h" -#include "mongo/db/query/plan_executor.h" -#include "mongo/db/query/query_planner_params.h" -#include "mongo/db/query/query_settings.h" -#include "mongo/db/query/query_solution.h" #include "mongo/db/ops/delete_request.h" #include "mongo/db/ops/parsed_delete.h" #include "mongo/db/ops/parsed_update.h" #include "mongo/db/ops/update_driver.h" #include "mongo/db/ops/update_request.h" +#include "mongo/db/query/canonical_query.h" +#include "mongo/db/query/plan_executor.h" +#include "mongo/db/query/query_planner_params.h" +#include "mongo/db/query/query_settings.h" +#include "mongo/db/query/query_solution.h" namespace mongo { diff --git a/src/mongo/db/query/getmore_request.cpp b/src/mongo/db/query/getmore_request.cpp index 4662942294c..b1a97f32c5e 100644 --- a/src/mongo/db/query/getmore_request.cpp +++ b/src/mongo/db/query/getmore_request.cpp @@ -81,7 +81,8 @@ Status GetMoreRequest::isValid() const { if (batchSize && *batchSize <= 0) { return Status(ErrorCodes::BadValue, str::stream() << "Batch size for getMore must be positive, " - << "but received: " << *batchSize); + << "but received: " + << *batchSize); } return Status::OK(); @@ -122,8 +123,8 @@ StatusWith<GetMoreRequest> GetMoreRequest::parseFromBSON(const std::string& dbna } else if (str::equals(fieldName, kCollectionField)) { if (el.type() != BSONType::String) { return {ErrorCodes::TypeMismatch, - str::stream() - << "Field 'collection' must be of type string in: " << cmdObj}; + str::stream() << "Field 'collection' must be of type string in: " + << cmdObj}; } fullns = parseNs(dbname, cmdObj); @@ -159,7 +160,9 @@ StatusWith<GetMoreRequest> GetMoreRequest::parseFromBSON(const std::string& dbna } else if (!str::startsWith(fieldName, "$")) { return {ErrorCodes::FailedToParse, str::stream() << "Failed to parse: " << cmdObj << ". " - << "Unrecognized field '" << fieldName << "'."}; + << "Unrecognized field '" + << fieldName + << "'."}; } } diff --git a/src/mongo/db/query/getmore_request_test.cpp b/src/mongo/db/query/getmore_request_test.cpp index 997310c9645..94dfb9ba366 100644 --- a/src/mongo/db/query/getmore_request_test.cpp +++ b/src/mongo/db/query/getmore_request_test.cpp @@ -30,9 +30,9 @@ #include <string> -#include "mongo/db/repl/optime.h" -#include "mongo/db/query/getmore_request.h" #include "mongo/db/jsobj.h" +#include "mongo/db/query/getmore_request.h" +#include "mongo/db/repl/optime.h" #include "mongo/unittest/unittest.h" @@ -60,7 +60,8 @@ TEST(GetMoreRequestTest, parseFromBSONCursorIdNotLongLong) { StatusWith<GetMoreRequest> result = GetMoreRequest::parseFromBSON("db", BSON("getMore" << "not a number" - << "collection" << 123)); + << "collection" + << 123)); ASSERT_NOT_OK(result.getStatus()); ASSERT_EQUALS(ErrorCodes::TypeMismatch, result.getStatus().code()); } @@ -115,7 +116,8 @@ TEST(GetMoreRequestTest, parseFromBSONUnrecognizedFieldName) { GetMoreRequest::parseFromBSON("db", BSON("getMore" << CursorId(123) << "collection" << "coll" - << "unknown_field" << 1)); + << "unknown_field" + << 1)); ASSERT_NOT_OK(result.getStatus()); ASSERT_EQUALS(ErrorCodes::FailedToParse, result.getStatus().code()); } @@ -125,7 +127,8 @@ TEST(GetMoreRequestTest, parseFromBSONInvalidBatchSize) { GetMoreRequest::parseFromBSON("db", BSON("getMore" << CursorId(123) << "collection" << "coll" - << "batchSize" << -1)); + << "batchSize" + << -1)); ASSERT_NOT_OK(result.getStatus()); ASSERT_EQUALS(ErrorCodes::BadValue, result.getStatus().code()); } @@ -135,7 +138,8 @@ TEST(GetMoreRequestTest, parseFromBSONInvalidBatchSizeOfZero) { GetMoreRequest::parseFromBSON("db", BSON("getMore" << CursorId(123) << "collection" << "coll" - << "batchSize" << 0)); + << "batchSize" + << 0)); ASSERT_NOT_OK(result.getStatus()); ASSERT_EQUALS(ErrorCodes::BadValue, result.getStatus().code()); } @@ -156,7 +160,8 @@ TEST(GetMoreRequestTest, parseFromBSONBatchSizeProvided) { GetMoreRequest::parseFromBSON("db", BSON("getMore" << CursorId(123) << "collection" << "coll" - << "batchSize" << 200)); + << "batchSize" + << 200)); ASSERT_EQUALS("db.coll", result.getValue().nss.toString()); ASSERT_EQUALS(CursorId(123), result.getValue().cursorid); ASSERT(result.getValue().batchSize); @@ -180,7 +185,8 @@ TEST(GetMoreRequestTest, parseFromBSONHasMaxTimeMS) { GetMoreRequest::parseFromBSON("db", BSON("getMore" << CursorId(123) << "collection" << "coll" - << "maxTimeMS" << 100)); + << "maxTimeMS" + << 100)); ASSERT_OK(result.getStatus()); ASSERT_EQUALS("db.coll", result.getValue().nss.toString()); ASSERT(result.getValue().awaitDataTimeout); @@ -193,7 +199,8 @@ TEST(GetMoreRequestTest, parseFromBSONHasMaxTimeMSOfZero) { GetMoreRequest::parseFromBSON("db", BSON("getMore" << CursorId(123) << "collection" << "coll" - << "maxTimeMS" << 0)); + << "maxTimeMS" + << 0)); ASSERT_OK(result.getStatus()); ASSERT_EQUALS("db.coll", result.getValue().nss.toString()); ASSERT_EQUALS(CursorId(123), result.getValue().cursorid); @@ -208,7 +215,8 @@ TEST(GetMoreRequestTest, toBSONHasBatchSize) { BSONObj requestObj = request.toBSON(); BSONObj expectedRequest = BSON("getMore" << CursorId(123) << "collection" << "testcoll" - << "batchSize" << 99); + << "batchSize" + << 99); ASSERT_EQ(requestObj, expectedRequest); } @@ -231,7 +239,10 @@ TEST(GetMoreRequestTest, toBSONHasTerm) { BSONObj requestObj = request.toBSON(); BSONObj expectedRequest = BSON("getMore" << CursorId(123) << "collection" << "testcoll" - << "batchSize" << 99 << "term" << 1); + << "batchSize" + << 99 + << "term" + << 1); ASSERT_EQ(requestObj, expectedRequest); } @@ -243,11 +254,14 @@ TEST(GetMoreRequestTest, toBSONHasCommitLevel) { 1, repl::OpTime(Timestamp(0, 10), 2)); BSONObj requestObj = request.toBSON(); - BSONObj expectedRequest = - BSON("getMore" << CursorId(123) << "collection" - << "testcoll" - << "batchSize" << 99 << "term" << 1 << "lastKnownCommittedOpTime" - << BSON("ts" << Timestamp(0, 10) << "t" << 2LL)); + BSONObj expectedRequest = BSON("getMore" << CursorId(123) << "collection" + << "testcoll" + << "batchSize" + << 99 + << "term" + << 1 + << "lastKnownCommittedOpTime" + << BSON("ts" << Timestamp(0, 10) << "t" << 2LL)); ASSERT_EQ(requestObj, expectedRequest); } @@ -261,7 +275,8 @@ TEST(GetMoreRequestTest, toBSONHasMaxTimeMS) { BSONObj requestObj = request.toBSON(); BSONObj expectedRequest = BSON("getMore" << CursorId(123) << "collection" << "testcoll" - << "maxTimeMS" << 789); + << "maxTimeMS" + << 789); ASSERT_EQ(requestObj, expectedRequest); } diff --git a/src/mongo/db/query/index_bounds_builder.h b/src/mongo/db/query/index_bounds_builder.h index b37901f6d2d..5d3c02e029f 100644 --- a/src/mongo/db/query/index_bounds_builder.h +++ b/src/mongo/db/query/index_bounds_builder.h @@ -28,8 +28,8 @@ #pragma once -#include "mongo/db/jsobj.h" #include "mongo/db/hasher.h" +#include "mongo/db/jsobj.h" #include "mongo/db/matcher/expression_parser.h" #include "mongo/db/query/index_bounds.h" #include "mongo/db/query/index_entry.h" diff --git a/src/mongo/db/query/index_bounds_builder_test.cpp b/src/mongo/db/query/index_bounds_builder_test.cpp index 4d93b8b63c9..af346b5f908 100644 --- a/src/mongo/db/query/index_bounds_builder_test.cpp +++ b/src/mongo/db/query/index_bounds_builder_test.cpp @@ -571,9 +571,8 @@ TEST(IndexBoundsBuilderTest, TranslateLteBinData) { ASSERT_EQ(oil.intervals.size(), 1U); ASSERT_EQ(Interval::INTERVAL_EQUALS, oil.intervals[0].compare( - Interval(fromjson( - "{'': {$binary: '', $type: '00'}," - "'': {$binary: 'AAAAAAAAAAAAAAAAAAAAAAAAAAAA', $type: '00'}}"), + Interval(fromjson("{'': {$binary: '', $type: '00'}," + "'': {$binary: 'AAAAAAAAAAAAAAAAAAAAAAAAAAAA', $type: '00'}}"), true, true))); ASSERT_EQ(tightness, IndexBoundsBuilder::EXACT); @@ -593,9 +592,8 @@ TEST(IndexBoundsBuilderTest, TranslateLtBinData) { ASSERT_EQ(oil.intervals.size(), 1U); ASSERT_EQ(Interval::INTERVAL_EQUALS, oil.intervals[0].compare( - Interval(fromjson( - "{'': {$binary: '', $type: '00'}," - "'': {$binary: 'AAAAAAAAAAAAAAAAAAAAAAAAAAAA', $type: '00'}}"), + Interval(fromjson("{'': {$binary: '', $type: '00'}," + "'': {$binary: 'AAAAAAAAAAAAAAAAAAAAAAAAAAAA', $type: '00'}}"), true, false))); ASSERT_EQ(tightness, IndexBoundsBuilder::EXACT); @@ -615,9 +613,8 @@ TEST(IndexBoundsBuilderTest, TranslateGtBinData) { ASSERT_EQ(oil.intervals.size(), 1U); ASSERT_EQ(Interval::INTERVAL_EQUALS, oil.intervals[0].compare( - Interval(fromjson( - "{'': {$binary: '////////////////////////////', $type: '00'}," - "'': ObjectId('000000000000000000000000')}"), + Interval(fromjson("{'': {$binary: '////////////////////////////', $type: '00'}," + "'': ObjectId('000000000000000000000000')}"), false, false))); ASSERT_EQ(tightness, IndexBoundsBuilder::EXACT); @@ -637,9 +634,8 @@ TEST(IndexBoundsBuilderTest, TranslateGteBinData) { ASSERT_EQ(oil.intervals.size(), 1U); ASSERT_EQ(Interval::INTERVAL_EQUALS, oil.intervals[0].compare( - Interval(fromjson( - "{'': {$binary: '////////////////////////////', $type: '00'}," - "'': ObjectId('000000000000000000000000')}"), + Interval(fromjson("{'': {$binary: '////////////////////////////', $type: '00'}," + "'': ObjectId('000000000000000000000000')}"), true, false))); ASSERT_EQ(tightness, IndexBoundsBuilder::EXACT); diff --git a/src/mongo/db/query/index_bounds_test.cpp b/src/mongo/db/query/index_bounds_test.cpp index 75b49f6429e..250563b54ce 100644 --- a/src/mongo/db/query/index_bounds_test.cpp +++ b/src/mongo/db/query/index_bounds_test.cpp @@ -32,13 +32,13 @@ #include "mongo/platform/basic.h" -#include "mongo/db/query/index_bounds.h" -#include "mongo/db/json.h" #include "mongo/db/jsobj.h" +#include "mongo/db/json.h" +#include "mongo/db/query/index_bounds.h" #include "mongo/unittest/unittest.h" #include "mongo/util/assert_util.h" -#include "mongo/util/text.h" #include "mongo/util/mongoutils/str.h" +#include "mongo/util/text.h" using namespace mongo; diff --git a/src/mongo/db/query/killcursors_request.cpp b/src/mongo/db/query/killcursors_request.cpp index 6d95311accd..c446998eaa1 100644 --- a/src/mongo/db/query/killcursors_request.cpp +++ b/src/mongo/db/query/killcursors_request.cpp @@ -66,8 +66,8 @@ StatusWith<KillCursorsRequest> KillCursorsRequest::parseFromBSON(const std::stri if (cmdObj[kCursorsField].type() != BSONType::Array) { return {ErrorCodes::FailedToParse, - str::stream() << "Field '" << kCursorsField - << "' must be of type array in: " << cmdObj}; + str::stream() << "Field '" << kCursorsField << "' must be of type array in: " + << cmdObj}; } std::vector<CursorId> cursorIds; diff --git a/src/mongo/db/query/killcursors_request_test.cpp b/src/mongo/db/query/killcursors_request_test.cpp index 74ce8bfa31e..19c220a7408 100644 --- a/src/mongo/db/query/killcursors_request_test.cpp +++ b/src/mongo/db/query/killcursors_request_test.cpp @@ -94,7 +94,8 @@ TEST(KillCursorsRequestTest, parseFromBSONCursorFieldNotArray) { KillCursorsRequest::parseFromBSON("db", BSON("killCursors" << "coll" - << "cursors" << CursorId(123))); + << "cursors" + << CursorId(123))); ASSERT_NOT_OK(result.getStatus()); ASSERT_EQ(result.getStatus().code(), ErrorCodes::FailedToParse); } @@ -104,7 +105,8 @@ TEST(KillCursorsRequestTest, parseFromBSONCursorFieldEmptyArray) { KillCursorsRequest::parseFromBSON("db", BSON("killCursors" << "coll" - << "cursors" << BSONArrayBuilder().arr())); + << "cursors" + << BSONArrayBuilder().arr())); ASSERT_NOT_OK(result.getStatus()); ASSERT_EQ(result.getStatus().code(), ErrorCodes::BadValue); } @@ -129,7 +131,8 @@ TEST(KillCursorsRequestTest, toBSON) { BSONObj requestObj = request.toBSON(); BSONObj expectedObj = BSON("killCursors" << "coll" - << "cursors" << BSON_ARRAY(CursorId(123) << CursorId(456))); + << "cursors" + << BSON_ARRAY(CursorId(123) << CursorId(456))); ASSERT_EQ(requestObj, expectedObj); } diff --git a/src/mongo/db/query/killcursors_response.cpp b/src/mongo/db/query/killcursors_response.cpp index 0484a1100fa..2cf7d998d8f 100644 --- a/src/mongo/db/query/killcursors_response.cpp +++ b/src/mongo/db/query/killcursors_response.cpp @@ -50,8 +50,8 @@ Status fillOutCursorArray(const BSONObj& cmdResponse, if (elt.type() != BSONType::Array) { return {ErrorCodes::FailedToParse, - str::stream() << "Field '" << fieldName - << "' must be of type array in: " << cmdResponse}; + str::stream() << "Field '" << fieldName << "' must be of type array in: " + << cmdResponse}; } for (BSONElement cursorElt : elt.Obj()) { diff --git a/src/mongo/db/query/killcursors_response_test.cpp b/src/mongo/db/query/killcursors_response_test.cpp index e2a56af98c4..0fe3d996edf 100644 --- a/src/mongo/db/query/killcursors_response_test.cpp +++ b/src/mongo/db/query/killcursors_response_test.cpp @@ -40,9 +40,13 @@ namespace { TEST(KillCursorsResponseTest, parseFromBSONSuccess) { StatusWith<KillCursorsResponse> result = KillCursorsResponse::parseFromBSON( BSON("cursorsKilled" << BSON_ARRAY(CursorId(123)) << "cursorsNotFound" - << BSON_ARRAY(CursorId(456) << CursorId(6)) << "cursorsAlive" + << BSON_ARRAY(CursorId(456) << CursorId(6)) + << "cursorsAlive" << BSON_ARRAY(CursorId(7) << CursorId(8) << CursorId(9)) - << "cursorsUnknown" << BSONArray() << "ok" << 1.0)); + << "cursorsUnknown" + << BSONArray() + << "ok" + << 1.0)); ASSERT_OK(result.getStatus()); KillCursorsResponse response = result.getValue(); ASSERT_EQ(response.cursorsKilled.size(), 1U); @@ -60,8 +64,11 @@ TEST(KillCursorsResponseTest, parseFromBSONSuccess) { TEST(KillCursorsResponseTest, parseFromBSONSuccessOmitCursorsAlive) { StatusWith<KillCursorsResponse> result = KillCursorsResponse::parseFromBSON( BSON("cursorsKilled" << BSON_ARRAY(CursorId(123)) << "cursorsNotFound" - << BSON_ARRAY(CursorId(456) << CursorId(6)) << "cursorsUnknown" - << BSON_ARRAY(CursorId(789)) << "ok" << 1.0)); + << BSON_ARRAY(CursorId(456) << CursorId(6)) + << "cursorsUnknown" + << BSON_ARRAY(CursorId(789)) + << "ok" + << 1.0)); ASSERT_NOT_OK(result.getStatus()); ASSERT_EQ(result.getStatus().code(), ErrorCodes::FailedToParse); } @@ -76,11 +83,13 @@ TEST(KillCursorsResponseTest, parseFromBSONCommandNotOk) { } TEST(KillCursorsResponseTest, parseFromBSONFieldNotArray) { - StatusWith<KillCursorsResponse> result = KillCursorsResponse::parseFromBSON(BSON( - "cursorsKilled" << BSON_ARRAY(CursorId(123)) << "cursorsNotFound" - << "foobar" - << "cursorsAlive" << BSON_ARRAY(CursorId(7) << CursorId(8) << CursorId(9)) - << "ok" << 1.0)); + StatusWith<KillCursorsResponse> result = KillCursorsResponse::parseFromBSON( + BSON("cursorsKilled" << BSON_ARRAY(CursorId(123)) << "cursorsNotFound" + << "foobar" + << "cursorsAlive" + << BSON_ARRAY(CursorId(7) << CursorId(8) << CursorId(9)) + << "ok" + << 1.0)); ASSERT_NOT_OK(result.getStatus()); ASSERT_EQ(result.getStatus().code(), ErrorCodes::FailedToParse); } @@ -88,8 +97,11 @@ TEST(KillCursorsResponseTest, parseFromBSONFieldNotArray) { TEST(KillCursorsResponseTest, parseFromBSONArrayContainsInvalidElement) { StatusWith<KillCursorsResponse> result = KillCursorsResponse::parseFromBSON( BSON("cursorsKilled" << BSON_ARRAY(CursorId(123)) << "cursorsNotFound" - << BSON_ARRAY(CursorId(456) << CursorId(6)) << "cursorsAlive" - << BSON_ARRAY(CursorId(7) << "foobar" << CursorId(9)) << "ok" << 1.0)); + << BSON_ARRAY(CursorId(456) << CursorId(6)) + << "cursorsAlive" + << BSON_ARRAY(CursorId(7) << "foobar" << CursorId(9)) + << "ok" + << 1.0)); ASSERT_NOT_OK(result.getStatus()); ASSERT_EQ(result.getStatus().code(), ErrorCodes::FailedToParse); } @@ -103,9 +115,13 @@ TEST(KillCursorsResponseTest, toBSON) { BSONObj responseObj = response.toBSON(); BSONObj expectedResponse = BSON("cursorsKilled" << BSON_ARRAY(CursorId(123)) << "cursorsNotFound" - << BSON_ARRAY(CursorId(456) << CursorId(6)) << "cursorsAlive" + << BSON_ARRAY(CursorId(456) << CursorId(6)) + << "cursorsAlive" << BSON_ARRAY(CursorId(7) << CursorId(8) << CursorId(9)) - << "cursorsUnknown" << BSONArray() << "ok" << 1.0); + << "cursorsUnknown" + << BSONArray() + << "ok" + << 1.0); ASSERT_EQ(responseObj, expectedResponse); } diff --git a/src/mongo/db/query/lite_parsed_query.cpp b/src/mongo/db/query/lite_parsed_query.cpp index 00ad7091397..4e7e036a4cc 100644 --- a/src/mongo/db/query/lite_parsed_query.cpp +++ b/src/mongo/db/query/lite_parsed_query.cpp @@ -351,7 +351,9 @@ StatusWith<unique_ptr<LiteParsedQuery>> LiteParsedQuery::makeFromFindCommand(Nam } else if (!str::startsWith(fieldName, '$')) { return Status(ErrorCodes::FailedToParse, str::stream() << "Failed to parse: " << cmdObj.toString() << ". " - << "Unrecognized field '" << fieldName << "'."); + << "Unrecognized field '" + << fieldName + << "'."); } } @@ -553,32 +555,32 @@ Status LiteParsedQuery::validate() const { if (_limit && *_limit < 0) { return Status(ErrorCodes::BadValue, - str::stream() - << "Limit value must be non-negative, but received: " << *_limit); + str::stream() << "Limit value must be non-negative, but received: " + << *_limit); } if (_batchSize && *_batchSize < 0) { return Status(ErrorCodes::BadValue, - str::stream() - << "BatchSize value must be non-negative, but received: " << *_batchSize); + str::stream() << "BatchSize value must be non-negative, but received: " + << *_batchSize); } if (_ntoreturn && *_ntoreturn < 0) { return Status(ErrorCodes::BadValue, - str::stream() - << "NToReturn value must be non-negative, but received: " << *_ntoreturn); + str::stream() << "NToReturn value must be non-negative, but received: " + << *_ntoreturn); } if (_maxScan < 0) { return Status(ErrorCodes::BadValue, - str::stream() - << "MaxScan value must be non-negative, but received: " << _maxScan); + str::stream() << "MaxScan value must be non-negative, but received: " + << _maxScan); } if (_maxTimeMS < 0) { return Status(ErrorCodes::BadValue, - str::stream() - << "MaxTimeMS value must be non-negative, but received: " << _maxTimeMS); + str::stream() << "MaxTimeMS value must be non-negative, but received: " + << _maxTimeMS); } if (_tailable) { @@ -618,9 +620,10 @@ StatusWith<int> LiteParsedQuery::parseMaxTimeMS(BSONElement maxTimeMSElt) { } double maxTimeMSDouble = maxTimeMSElt.numberDouble(); if (maxTimeMSElt.type() == mongo::NumberDouble && floor(maxTimeMSDouble) != maxTimeMSDouble) { - return StatusWith<int>(ErrorCodes::BadValue, - (StringBuilder() << maxTimeMSElt.fieldNameStringData() - << " has non-integral value").str()); + return StatusWith<int>( + ErrorCodes::BadValue, + (StringBuilder() << maxTimeMSElt.fieldNameStringData() << " has non-integral value") + .str()); } return StatusWith<int>(static_cast<int>(maxTimeMSLongLong)); } diff --git a/src/mongo/db/query/lite_parsed_query_test.cpp b/src/mongo/db/query/lite_parsed_query_test.cpp index d94ec230cb6..17affe6f9c3 100644 --- a/src/mongo/db/query/lite_parsed_query_test.cpp +++ b/src/mongo/db/query/lite_parsed_query_test.cpp @@ -346,9 +346,9 @@ TEST(LiteParsedQueryTest, ValidateSortOrder) { ASSERT_FALSE(LiteParsedQuery::isValidSortOrder(fromjson("{a: {$meta: 1}}"))); ASSERT_FALSE(LiteParsedQuery::isValidSortOrder(fromjson("{a: {$meta: \"image\"}}"))); ASSERT_FALSE(LiteParsedQuery::isValidSortOrder(fromjson("{a: {$world: \"textScore\"}}"))); - ASSERT_FALSE(LiteParsedQuery::isValidSortOrder(fromjson( - "{a: {$meta: \"textScore\"," - " b: 1}}"))); + ASSERT_FALSE( + LiteParsedQuery::isValidSortOrder(fromjson("{a: {$meta: \"textScore\"," + " b: 1}}"))); ASSERT_FALSE(LiteParsedQuery::isValidSortOrder(fromjson("{'': 1}"))); ASSERT_FALSE(LiteParsedQuery::isValidSortOrder(fromjson("{'': -1}"))); } diff --git a/src/mongo/db/query/parsed_projection_test.cpp b/src/mongo/db/query/parsed_projection_test.cpp index 90f1b9bfb5c..b1b1b59324f 100644 --- a/src/mongo/db/query/parsed_projection_test.cpp +++ b/src/mongo/db/query/parsed_projection_test.cpp @@ -28,11 +28,11 @@ #include "mongo/db/query/parsed_projection.h" -#include <memory> #include "mongo/db/json.h" #include "mongo/db/matcher/expression_parser.h" #include "mongo/db/matcher/extensions_callback_disallow_extensions.h" #include "mongo/unittest/unittest.h" +#include <memory> namespace { @@ -56,8 +56,10 @@ unique_ptr<ParsedProjection> createParsedProjection(const BSONObj& query, const Status status = ParsedProjection::make( projObj, queryMatchExpr.get(), &out, ExtensionsCallbackDisallowExtensions()); if (!status.isOK()) { - FAIL(mongoutils::str::stream() << "failed to parse projection " << projObj - << " (query: " << query << "): " << status.toString()); + FAIL(mongoutils::str::stream() << "failed to parse projection " << projObj << " (query: " + << query + << "): " + << status.toString()); } ASSERT(out); return unique_ptr<ParsedProjection>(out); diff --git a/src/mongo/db/query/plan_cache.cpp b/src/mongo/db/query/plan_cache.cpp index ab64b8f1d26..ca1f93d9d6f 100644 --- a/src/mongo/db/query/plan_cache.cpp +++ b/src/mongo/db/query/plan_cache.cpp @@ -32,19 +32,19 @@ #include "mongo/db/query/plan_cache.h" -#include <algorithm> -#include <math.h> -#include <memory> #include "mongo/base/owned_pointer_vector.h" #include "mongo/client/dbclientinterface.h" // For QueryOption_foobar #include "mongo/db/matcher/expression_array.h" #include "mongo/db/matcher/expression_geo.h" #include "mongo/db/query/plan_ranker.h" -#include "mongo/db/query/query_solution.h" #include "mongo/db/query/query_knobs.h" +#include "mongo/db/query/query_solution.h" #include "mongo/util/assert_util.h" #include "mongo/util/log.h" #include "mongo/util/mongoutils/str.h" +#include <algorithm> +#include <math.h> +#include <memory> namespace mongo { namespace { diff --git a/src/mongo/db/query/plan_cache.h b/src/mongo/db/query/plan_cache.h index 02ab8ef64cb..332e7b79cea 100644 --- a/src/mongo/db/query/plan_cache.h +++ b/src/mongo/db/query/plan_cache.h @@ -28,8 +28,8 @@ #pragma once -#include <set> #include <boost/optional/optional.hpp> +#include <set> #include "mongo/db/exec/plan_stats.h" #include "mongo/db/query/canonical_query.h" diff --git a/src/mongo/db/query/plan_cache_indexability.cpp b/src/mongo/db/query/plan_cache_indexability.cpp index 4e61e9ba595..066d7a2782b 100644 --- a/src/mongo/db/query/plan_cache_indexability.cpp +++ b/src/mongo/db/query/plan_cache_indexability.cpp @@ -30,14 +30,14 @@ #include "mongo/db/query/plan_cache_indexability.h" -#include <memory> #include "mongo/base/init.h" #include "mongo/base/owned_pointer_vector.h" -#include "mongo/db/query/index_entry.h" #include "mongo/db/matcher/expression.h" #include "mongo/db/matcher/expression_algo.h" #include "mongo/db/matcher/expression_leaf.h" +#include "mongo/db/query/index_entry.h" #include "mongo/stdx/memory.h" +#include <memory> namespace mongo { diff --git a/src/mongo/db/query/plan_cache_indexability_test.cpp b/src/mongo/db/query/plan_cache_indexability_test.cpp index bfc1d786878..e5db935d3a3 100644 --- a/src/mongo/db/query/plan_cache_indexability_test.cpp +++ b/src/mongo/db/query/plan_cache_indexability_test.cpp @@ -42,8 +42,8 @@ std::unique_ptr<MatchExpression> parseMatchExpression(const BSONObj& obj) { StatusWithMatchExpression status = MatchExpressionParser::parse(obj, ExtensionsCallbackDisallowExtensions(), collator); if (!status.isOK()) { - FAIL(str::stream() << "failed to parse query: " << obj.toString() - << ". Reason: " << status.getStatus().toString()); + FAIL(str::stream() << "failed to parse query: " << obj.toString() << ". Reason: " + << status.getStatus().toString()); } return std::move(status.getValue()); } diff --git a/src/mongo/db/query/plan_cache_test.cpp b/src/mongo/db/query/plan_cache_test.cpp index 4192f748362..708ff2b69e6 100644 --- a/src/mongo/db/query/plan_cache_test.cpp +++ b/src/mongo/db/query/plan_cache_test.cpp @@ -33,8 +33,8 @@ #include "mongo/db/query/plan_cache.h" #include <algorithm> -#include <ostream> #include <memory> +#include <ostream> #include "mongo/db/jsobj.h" #include "mongo/db/json.h" @@ -318,9 +318,9 @@ TEST(PlanCacheTest, ShouldNotCacheQueryWithMax) { * the planner is able to come up with a cacheable solution. */ TEST(PlanCacheTest, ShouldCacheQueryWithGeoWithinLegacyCoordinates) { - unique_ptr<CanonicalQuery> cq(canonicalize( - "{a: {$geoWithin: " - "{$box: [[-180, -90], [180, 90]]}}}")); + unique_ptr<CanonicalQuery> cq( + canonicalize("{a: {$geoWithin: " + "{$box: [[-180, -90], [180, 90]]}}}")); assertShouldCacheQuery(*cq); } @@ -328,10 +328,10 @@ TEST(PlanCacheTest, ShouldCacheQueryWithGeoWithinLegacyCoordinates) { * $geoWithin queries with GeoJSON coordinates are supported by the index bounds builder. */ TEST(PlanCacheTest, ShouldCacheQueryWithGeoWithinJSONCoordinates) { - unique_ptr<CanonicalQuery> cq(canonicalize( - "{a: {$geoWithin: " - "{$geometry: {type: 'Polygon', coordinates: " - "[[[0, 0], [0, 90], [90, 0], [0, 0]]]}}}}")); + unique_ptr<CanonicalQuery> cq( + canonicalize("{a: {$geoWithin: " + "{$geometry: {type: 'Polygon', coordinates: " + "[[[0, 0], [0, 90], [90, 0], [0, 0]]]}}}}")); assertShouldCacheQuery(*cq); } @@ -339,11 +339,11 @@ TEST(PlanCacheTest, ShouldCacheQueryWithGeoWithinJSONCoordinates) { * $geoWithin queries with both legacy and GeoJSON coordinates are cacheable. */ TEST(PlanCacheTest, ShouldCacheQueryWithGeoWithinLegacyAndJSONCoordinates) { - unique_ptr<CanonicalQuery> cq(canonicalize( - "{$or: [{a: {$geoWithin: {$geometry: {type: 'Polygon', " - "coordinates: [[[0, 0], [0, 90], " - "[90, 0], [0, 0]]]}}}}," - "{a: {$geoWithin: {$box: [[-180, -90], [180, 90]]}}}]}")); + unique_ptr<CanonicalQuery> cq( + canonicalize("{$or: [{a: {$geoWithin: {$geometry: {type: 'Polygon', " + "coordinates: [[[0, 0], [0, 90], " + "[90, 0], [0, 0]]]}}}}," + "{a: {$geoWithin: {$box: [[-180, -90], [180, 90]]}}}]}")); assertShouldCacheQuery(*cq); } @@ -351,10 +351,10 @@ TEST(PlanCacheTest, ShouldCacheQueryWithGeoWithinLegacyAndJSONCoordinates) { * $geoIntersects queries are always cacheable because they support GeoJSON coordinates only. */ TEST(PlanCacheTest, ShouldCacheQueryWithGeoIntersects) { - unique_ptr<CanonicalQuery> cq(canonicalize( - "{a: {$geoIntersects: " - "{$geometry: {type: 'Point', coordinates: " - "[10.0, 10.0]}}}}")); + unique_ptr<CanonicalQuery> cq( + canonicalize("{a: {$geoIntersects: " + "{$geometry: {type: 'Point', coordinates: " + "[10.0, 10.0]}}}}")); assertShouldCacheQuery(*cq); } @@ -363,9 +363,9 @@ TEST(PlanCacheTest, ShouldCacheQueryWithGeoIntersects) { * between flat and spherical queries. */ TEST(PlanCacheTest, ShouldNotCacheQueryWithGeoNear) { - unique_ptr<CanonicalQuery> cq(canonicalize( - "{a: {$geoNear: {$geometry: {type: 'Point'," - "coordinates: [0,0]}, $maxDistance:100}}}")); + unique_ptr<CanonicalQuery> cq( + canonicalize("{a: {$geoNear: {$geometry: {type: 'Point'," + "coordinates: [0,0]}, $maxDistance:100}}}")); assertShouldCacheQuery(*cq); } @@ -1279,14 +1279,14 @@ TEST(PlanCacheTest, ComputeKeyGeoWithin) { PlanCache planCache; // Legacy coordinates. - unique_ptr<CanonicalQuery> cqLegacy(canonicalize( - "{a: {$geoWithin: " - "{$box: [[-180, -90], [180, 90]]}}}")); + unique_ptr<CanonicalQuery> cqLegacy( + canonicalize("{a: {$geoWithin: " + "{$box: [[-180, -90], [180, 90]]}}}")); // GeoJSON coordinates. - unique_ptr<CanonicalQuery> cqNew(canonicalize( - "{a: {$geoWithin: " - "{$geometry: {type: 'Polygon', coordinates: " - "[[[0, 0], [0, 90], [90, 0], [0, 0]]]}}}}")); + unique_ptr<CanonicalQuery> cqNew( + canonicalize("{a: {$geoWithin: " + "{$geometry: {type: 'Polygon', coordinates: " + "[[[0, 0], [0, 90], [90, 0], [0, 0]]]}}}}")); ASSERT_NOT_EQUALS(planCache.computeKey(*cqLegacy), planCache.computeKey(*cqNew)); } diff --git a/src/mongo/db/query/plan_enumerator.cpp b/src/mongo/db/query/plan_enumerator.cpp index c6fe53a1c37..4b843baabe4 100644 --- a/src/mongo/db/query/plan_enumerator.cpp +++ b/src/mongo/db/query/plan_enumerator.cpp @@ -32,8 +32,8 @@ #include <set> -#include "mongo/db/query/indexability.h" #include "mongo/db/query/index_tag.h" +#include "mongo/db/query/indexability.h" #include "mongo/util/log.h" #include "mongo/util/string_map.h" @@ -332,8 +332,7 @@ bool PlanEnumerator::getNext(MatchExpression** tree) { sortUsingTags(*tree); _root->resetTag(); - LOG(5) << "Enumerator: memo just before moving:" << endl - << dumpMemo(); + LOG(5) << "Enumerator: memo just before moving:" << endl << dumpMemo(); _done = nextMemo(memoIDForNode(_root)); return true; } diff --git a/src/mongo/db/query/plan_executor.cpp b/src/mongo/db/query/plan_executor.cpp index 84602dc3c29..4a121926b9e 100644 --- a/src/mongo/db/query/plan_executor.cpp +++ b/src/mongo/db/query/plan_executor.cpp @@ -40,8 +40,8 @@ #include "mongo/db/exec/subplan.h" #include "mongo/db/exec/working_set.h" #include "mongo/db/exec/working_set_common.h" -#include "mongo/db/service_context.h" #include "mongo/db/query/plan_yield_policy.h" +#include "mongo/db/service_context.h" #include "mongo/db/storage/record_fetcher.h" #include "mongo/stdx/memory.h" #include "mongo/util/fail_point_service.h" @@ -556,7 +556,8 @@ Status PlanExecutor::executePlan() { if (PlanExecutor::DEAD == state || PlanExecutor::FAILURE == state) { return Status(ErrorCodes::OperationFailed, str::stream() << "Exec error: " << WorkingSetCommon::toStatusString(obj) - << ", state: " << PlanExecutor::statestr(state)); + << ", state: " + << PlanExecutor::statestr(state)); } invariant(PlanExecutor::IS_EOF == state); diff --git a/src/mongo/db/query/plan_ranker.cpp b/src/mongo/db/query/plan_ranker.cpp index d4f68eb0602..9836e980fbb 100644 --- a/src/mongo/db/query/plan_ranker.cpp +++ b/src/mongo/db/query/plan_ranker.cpp @@ -32,8 +32,8 @@ #include <algorithm> #include <cmath> -#include <vector> #include <utility> +#include <vector> #include "mongo/db/query/plan_ranker.h" diff --git a/src/mongo/db/query/planner_access.cpp b/src/mongo/db/query/planner_access.cpp index 9b28a933131..c3172d5387d 100644 --- a/src/mongo/db/query/planner_access.cpp +++ b/src/mongo/db/query/planner_access.cpp @@ -39,9 +39,9 @@ #include "mongo/db/matcher/expression_array.h" #include "mongo/db/matcher/expression_geo.h" #include "mongo/db/matcher/expression_text.h" -#include "mongo/db/query/indexability.h" #include "mongo/db/query/index_bounds_builder.h" #include "mongo/db/query/index_tag.h" +#include "mongo/db/query/indexability.h" #include "mongo/db/query/query_knobs.h" #include "mongo/db/query/query_planner.h" #include "mongo/db/query/query_planner_common.h" diff --git a/src/mongo/db/query/planner_analysis.cpp b/src/mongo/db/query/planner_analysis.cpp index b789395cb44..1a507d16ef2 100644 --- a/src/mongo/db/query/planner_analysis.cpp +++ b/src/mongo/db/query/planner_analysis.cpp @@ -33,12 +33,12 @@ #include <set> #include <vector> -#include "mongo/db/jsobj.h" #include "mongo/db/index/expression_params.h" #include "mongo/db/index/s2_common.h" +#include "mongo/db/jsobj.h" #include "mongo/db/matcher/expression_geo.h" -#include "mongo/db/query/query_planner_common.h" #include "mongo/db/query/query_planner.h" +#include "mongo/db/query/query_planner_common.h" #include "mongo/util/log.h" namespace mongo { diff --git a/src/mongo/db/query/planner_analysis_test.cpp b/src/mongo/db/query/planner_analysis_test.cpp index 78b82845afa..c02c9c25cfb 100644 --- a/src/mongo/db/query/planner_analysis_test.cpp +++ b/src/mongo/db/query/planner_analysis_test.cpp @@ -90,16 +90,14 @@ TEST(QueryPlannerAnalysis, GetSortPatternSpecialIndexTypes) { ASSERT_EQUALS(fromjson("{a: 1}"), QueryPlannerAnalysis::getSortPattern(fromjson("{a: 1, b: 'text', c: 1}"))); ASSERT_EQUALS(fromjson("{a: 1}"), - QueryPlannerAnalysis::getSortPattern(fromjson( - "{a: 1, b: '2dsphere'," - " c: 1}"))); + QueryPlannerAnalysis::getSortPattern(fromjson("{a: 1, b: '2dsphere'," + " c: 1}"))); ASSERT_EQUALS(fromjson("{a: 1, b: 1}"), QueryPlannerAnalysis::getSortPattern(fromjson("{a: 1, b: 1, c: 'text'}"))); ASSERT_EQUALS(fromjson("{a: 1, b: 1}"), - QueryPlannerAnalysis::getSortPattern(fromjson( - "{a: 1, b: 1, c: 'text'," - " d: 1}"))); + QueryPlannerAnalysis::getSortPattern(fromjson("{a: 1, b: 1, c: 'text'," + " d: 1}"))); } // Test the generation of sort orders provided by an index scan done by diff --git a/src/mongo/db/query/planner_ixselect.cpp b/src/mongo/db/query/planner_ixselect.cpp index 8af46a211af..7c32d516260 100644 --- a/src/mongo/db/query/planner_ixselect.cpp +++ b/src/mongo/db/query/planner_ixselect.cpp @@ -40,8 +40,8 @@ #include "mongo/db/matcher/expression_geo.h" #include "mongo/db/matcher/expression_text.h" #include "mongo/db/query/collation/collator_interface.h" -#include "mongo/db/query/indexability.h" #include "mongo/db/query/index_tag.h" +#include "mongo/db/query/indexability.h" #include "mongo/db/query/query_planner_common.h" #include "mongo/util/log.h" diff --git a/src/mongo/db/query/planner_ixselect_test.cpp b/src/mongo/db/query/planner_ixselect_test.cpp index 14c46e47970..098c921e5bd 100644 --- a/src/mongo/db/query/planner_ixselect_test.cpp +++ b/src/mongo/db/query/planner_ixselect_test.cpp @@ -32,7 +32,6 @@ #include "mongo/db/query/planner_ixselect.h" -#include <memory> #include "mongo/db/json.h" #include "mongo/db/matcher/expression_parser.h" #include "mongo/db/matcher/extensions_callback_disallow_extensions.h" @@ -40,6 +39,7 @@ #include "mongo/db/query/index_tag.h" #include "mongo/unittest/unittest.h" #include "mongo/util/text.h" +#include <memory> using namespace mongo; diff --git a/src/mongo/db/query/query_planner.cpp b/src/mongo/db/query/query_planner.cpp index 6560e54a125..faad7ca6aae 100644 --- a/src/mongo/db/query/query_planner.cpp +++ b/src/mongo/db/query/query_planner.cpp @@ -40,10 +40,10 @@ #include "mongo/db/matcher/expression_text.h" #include "mongo/db/query/canonical_query.h" #include "mongo/db/query/plan_cache.h" +#include "mongo/db/query/plan_enumerator.h" #include "mongo/db/query/planner_access.h" #include "mongo/db/query/planner_analysis.h" #include "mongo/db/query/planner_ixselect.h" -#include "mongo/db/query/plan_enumerator.h" #include "mongo/db/query/query_planner_common.h" #include "mongo/db/query/query_solution.h" #include "mongo/util/log.h" @@ -398,8 +398,7 @@ Status QueryPlanner::planFromCache(const CanonicalQuery& query, // The planner requires a defined sort order. sortUsingTags(clone.get()); - LOG(5) << "Tagged tree:" << endl - << clone->toString(); + LOG(5) << "Tagged tree:" << endl << clone->toString(); // Use the cached index assignments to build solnRoot. QuerySolutionNode* solnRoot = QueryPlannerAccess::buildIndexedDataAccess( @@ -415,8 +414,8 @@ Status QueryPlanner::planFromCache(const CanonicalQuery& query, QuerySolution* soln = QueryPlannerAnalysis::analyzeDataAccess(query, params, solnRoot); if (!soln) { return Status(ErrorCodes::BadValue, - str::stream() - << "Failed to analyze plan from cache. Query: " << query.toStringShort()); + str::stream() << "Failed to analyze plan from cache. Query: " + << query.toStringShort()); } LOG(5) << "Planner: solution constructed from the cache:\n" << soln->toString(); @@ -677,8 +676,7 @@ Status QueryPlanner::plan(const CanonicalQuery& query, } // query.root() is now annotated with RelevantTag(s). - LOG(5) << "Rated tree:" << endl - << query.root()->toString(); + LOG(5) << "Rated tree:" << endl << query.root()->toString(); // If there is a GEO_NEAR it must have an index it can use directly. const MatchExpression* gnNode = NULL; @@ -744,8 +742,7 @@ Status QueryPlanner::plan(const CanonicalQuery& query, MatchExpression* rawTree; while (isp.getNext(&rawTree) && (out->size() < params.maxIndexedSolutions)) { - LOG(5) << "About to build solntree from tagged tree:" << endl - << rawTree->toString(); + LOG(5) << "About to build solntree from tagged tree:" << endl << rawTree->toString(); // The tagged tree produced by the plan enumerator is not guaranteed // to be canonically sorted. In order to be compatible with the cached @@ -771,8 +768,7 @@ Status QueryPlanner::plan(const CanonicalQuery& query, QuerySolution* soln = QueryPlannerAnalysis::analyzeDataAccess(query, params, solnRoot); if (NULL != soln) { - LOG(5) << "Planner: adding solution:" << endl - << soln->toString(); + LOG(5) << "Planner: adding solution:" << endl << soln->toString(); if (indexTreeStatus.isOK()) { SolutionCacheData* scd = new SolutionCacheData(); scd->tree.reset(autoData.release()); @@ -918,8 +914,7 @@ Status QueryPlanner::plan(const CanonicalQuery& query, scd->solnType = SolutionCacheData::COLLSCAN_SOLN; collscan->cacheData.reset(scd); out->push_back(collscan); - LOG(5) << "Planner: outputting a collscan:" << endl - << collscan->toString(); + LOG(5) << "Planner: outputting a collscan:" << endl << collscan->toString(); } } diff --git a/src/mongo/db/query/query_planner_array_test.cpp b/src/mongo/db/query/query_planner_array_test.cpp index d5f7fa741a3..3bc52263b13 100644 --- a/src/mongo/db/query/query_planner_array_test.cpp +++ b/src/mongo/db/query/query_planner_array_test.cpp @@ -92,9 +92,9 @@ TEST_F(QueryPlannerTest, AllElemMatchCompound) { // true means multikey addIndex(BSON("d" << 1 << "a.b" << 1 << "a.c" << 1), true); - runQuery(fromjson( - "{d: 1, a: {$all: [{$elemMatch: {b: 2, c: 2}}," - "{$elemMatch: {b: 3, c: 3}}]}}")); + runQuery( + fromjson("{d: 1, a: {$all: [{$elemMatch: {b: 2, c: 2}}," + "{$elemMatch: {b: 3, c: 3}}]}}")); assertNumSolutions(2U); assertSolutionExists("{cscan: {dir: 1}}"); @@ -121,9 +121,9 @@ TEST_F(QueryPlannerTest, ElemMatchWithAllElemMatchChild) { TEST_F(QueryPlannerTest, ElemMatchWithAllElemMatchChild2) { // true means multikey addIndex(BSON("a.b.c.d" << 1), true); - runQuery(fromjson( - "{'a.b': {$elemMatch: {c: {$all: " - "[{$elemMatch: {d: {$gt: 1, $lt: 3}}}]}}}}")); + runQuery( + fromjson("{'a.b': {$elemMatch: {c: {$all: " + "[{$elemMatch: {d: {$gt: 1, $lt: 3}}}]}}}}")); assertNumSolutions(3U); assertSolutionExists("{cscan: {dir: 1}}"); @@ -202,9 +202,9 @@ TEST_F(QueryPlannerTest, ElemMatchNested) { TEST_F(QueryPlannerTest, TwoElemMatchNested) { addIndex(BSON("a.d.e" << 1)); addIndex(BSON("a.b.c" << 1)); - runQuery(fromjson( - "{ a:{ $elemMatch:{ d:{ $elemMatch:{ e:{ $lte:1 } } }," - "b:{ $elemMatch:{ c:{ $gte:1 } } } } } }")); + runQuery( + fromjson("{ a:{ $elemMatch:{ d:{ $elemMatch:{ e:{ $lte:1 } } }," + "b:{ $elemMatch:{ c:{ $gte:1 } } } } } }")); ASSERT_EQUALS(getNumSolutions(), 3U); assertSolutionExists("{cscan: {dir: 1}}"); @@ -486,9 +486,9 @@ TEST_F(QueryPlannerTest, MultikeyNestedElemMatchIn) { // The bounds can be compounded because the index is not multikey. TEST_F(QueryPlannerTest, TwoNestedElemMatchBounds) { addIndex(BSON("a.d.e" << 1 << "a.b.c" << 1)); - runQuery(fromjson( - "{a: {$elemMatch: {d: {$elemMatch: {e: {$lte: 1}}}," - "b: {$elemMatch: {c: {$gte: 1}}}}}}")); + runQuery( + fromjson("{a: {$elemMatch: {d: {$elemMatch: {e: {$lte: 1}}}," + "b: {$elemMatch: {c: {$gte: 1}}}}}}")); assertNumSolutions(2U); assertSolutionExists("{cscan: {dir: 1}}"); @@ -505,9 +505,9 @@ TEST_F(QueryPlannerTest, TwoNestedElemMatchBounds) { TEST_F(QueryPlannerTest, MultikeyTwoNestedElemMatchBounds) { // true means multikey addIndex(BSON("a.d.e" << 1 << "a.b.c" << 1), true); - runQuery(fromjson( - "{a: {$elemMatch: {d: {$elemMatch: {e: {$lte: 1}}}," - "b: {$elemMatch: {c: {$gte: 1}}}}}}")); + runQuery( + fromjson("{a: {$elemMatch: {d: {$elemMatch: {e: {$lte: 1}}}," + "b: {$elemMatch: {c: {$gte: 1}}}}}}")); assertNumSolutions(2U); assertSolutionExists("{cscan: {dir: 1}}"); @@ -535,9 +535,9 @@ TEST_F(QueryPlannerTest, MultikeyElemMatchValue) { // the index is not multikey. TEST_F(QueryPlannerTest, ElemMatchIntersectBoundsNotMultikey) { addIndex(BSON("a.b" << 1)); - runQuery(fromjson( - "{a: {$elemMatch: {b: {$elemMatch: {$gte: 1, $lte: 4}}}}," - "'a.b': {$in: [2,5]}}")); + runQuery( + fromjson("{a: {$elemMatch: {b: {$elemMatch: {$gte: 1, $lte: 4}}}}," + "'a.b': {$in: [2,5]}}")); assertNumSolutions(2U); assertSolutionExists("{cscan: {dir: 1}}"); @@ -554,9 +554,9 @@ TEST_F(QueryPlannerTest, ElemMatchIntersectBoundsNotMultikey) { TEST_F(QueryPlannerTest, ElemMatchIntersectBoundsMultikey) { // true means multikey addIndex(BSON("a.b" << 1), true); - runQuery(fromjson( - "{a: {$elemMatch: {b: {$elemMatch: {$gte: 1, $lte: 4}}}}," - "'a.b': {$in: [2,5]}}")); + runQuery( + fromjson("{a: {$elemMatch: {b: {$elemMatch: {$gte: 1, $lte: 4}}}}," + "'a.b': {$in: [2,5]}}")); assertNumSolutions(3U); assertSolutionExists("{cscan: {dir: 1}}"); @@ -848,9 +848,9 @@ TEST_F(QueryPlannerTest, MultikeyDoubleDottedElemMatchOnDotted) { TEST_F(QueryPlannerTest, MultikeyComplexDoubleDotted) { // true means multikey addIndex(BSON("a.b.c" << 1 << "a.e.f" << 1 << "a.b.d" << 1 << "a.e.g" << 1), true); - runQuery(fromjson( - "{'a.b': {$elemMatch: {c: 1, d: 1}}, " - "'a.e': {$elemMatch: {f: 1, g: 1}}}")); + runQuery( + fromjson("{'a.b': {$elemMatch: {c: 1, d: 1}}, " + "'a.e': {$elemMatch: {f: 1, g: 1}}}")); assertNumSolutions(2U); assertSolutionExists("{cscan: {dir: 1}}"); @@ -866,9 +866,9 @@ TEST_F(QueryPlannerTest, MultikeyComplexDoubleDotted) { TEST_F(QueryPlannerTest, MultikeyComplexDoubleDotted2) { // true means multikey addIndex(BSON("a.b.c" << 1 << "a.e.c" << 1 << "a.b.d" << 1 << "a.e.d" << 1), true); - runQuery(fromjson( - "{'a.b': {$elemMatch: {c: 1, d: 1}}, " - "'a.e': {$elemMatch: {f: 1, g: 1}}}")); + runQuery( + fromjson("{'a.b': {$elemMatch: {c: 1, d: 1}}, " + "'a.e': {$elemMatch: {f: 1, g: 1}}}")); assertNumSolutions(2U); assertSolutionExists("{cscan: {dir: 1}}"); @@ -889,9 +889,9 @@ TEST_F(QueryPlannerTest, ElemMatchIndexIntersection) { addIndex(BSON("a.b.startDate" << 1), true); addIndex(BSON("a.b.endDate" << 1), true); - runQuery(fromjson( - "{shortId: 3, 'a.b': {$elemMatch: {startDate: {$lte: 3}," - "endDate: {$gt: 6}}}}")); + runQuery( + fromjson("{shortId: 3, 'a.b': {$elemMatch: {startDate: {$lte: 3}," + "endDate: {$gt: 6}}}}")); assertNumSolutions(6U); @@ -1071,9 +1071,9 @@ TEST_F(QueryPlannerTest, MultikeyElemMatchAll) { // SERVER-16042 TEST_F(QueryPlannerTest, MultikeyElemMatchAllCompound) { addIndex(BSON("a.b" << 1 << "c" << 1), true); - runQuery(fromjson( - "{a: {$all: [{$elemMatch: {b: {$gt: 1}}}, " - "{$elemMatch: {b: {$lt: 0}}}]}, c: 3}")); + runQuery( + fromjson("{a: {$all: [{$elemMatch: {b: {$gt: 1}}}, " + "{$elemMatch: {b: {$lt: 0}}}]}, c: 3}")); assertNumSolutions(3U); assertSolutionExists("{cscan: {dir: 1}}"); @@ -1090,9 +1090,9 @@ TEST_F(QueryPlannerTest, MultikeyElemMatchAllCompound) { // SERVER-16042 TEST_F(QueryPlannerTest, MultikeyElemMatchAllCompound2) { addIndex(BSON("a.b" << 1 << "c" << 1), true); - runQuery(fromjson( - "{a: {$all: [{$elemMatch: {b: {$gt: 1}}}, " - "{$elemMatch: {b: {$lt: 0}}}]}, c: {$gte: 3, $lte: 4}}")); + runQuery( + fromjson("{a: {$all: [{$elemMatch: {b: {$gt: 1}}}, " + "{$elemMatch: {b: {$lt: 0}}}]}, c: {$gte: 3, $lte: 4}}")); assertNumSolutions(3U); assertSolutionExists("{cscan: {dir: 1}}"); @@ -1348,9 +1348,9 @@ TEST_F(QueryPlannerTest, CannotIntersectBoundsOfTwoSeparateElemMatches) { MultikeyPaths multikeyPaths{{0U}, {0U}}; addIndex(BSON("a.b" << 1 << "a.c" << 1), multikeyPaths); - runQuery(fromjson( - "{$and: [{a: {$elemMatch: {b: {$gte: 0}, c: {$lt: 20}}}}, " - "{a: {$elemMatch: {b: {$lt: 10}, c: {$gte: 5}}}}]}")); + runQuery( + fromjson("{$and: [{a: {$elemMatch: {b: {$gte: 0}, c: {$lt: 20}}}}, " + "{a: {$elemMatch: {b: {$lt: 10}, c: {$gte: 5}}}}]}")); assertNumSolutions(3U); assertSolutionExists( diff --git a/src/mongo/db/query/query_planner_collation_test.cpp b/src/mongo/db/query/query_planner_collation_test.cpp index 7f9d784e6c5..996c644e609 100644 --- a/src/mongo/db/query/query_planner_collation_test.cpp +++ b/src/mongo/db/query/query_planner_collation_test.cpp @@ -90,9 +90,9 @@ TEST_F(QueryPlannerTest, StringComparisonAndNonStringComparisonCanUseSeparateInd // The string predicate can use index {a: 1}, since the collators match. The non-string // comparison can use index {b: 1}, even though the collators don't match. - runQueryAsCommand(fromjson( - "{find: 'testns', filter: {a: {$lt: 'foo'}, b: {$lte: 4}}, collation: {locale: " - "'reverse'}}")); + runQueryAsCommand( + fromjson("{find: 'testns', filter: {a: {$lt: 'foo'}, b: {$lte: 4}}, collation: {locale: " + "'reverse'}}")); assertNumSolutions(3U); assertSolutionExists("{cscan: {dir: 1}}"); @@ -189,9 +189,9 @@ TEST_F(QueryPlannerTest, OrQueryResultsInCollscanWhenOnlyOneBranchHasIndexWithMa addIndex(fromjson("{a: 1}"), &reverseStringCollator); addIndex(fromjson("{b: 1}"), &alwaysEqualCollator); - runQueryAsCommand(fromjson( - "{find: 'testns', filter: {$or: [{a: 'foo'}, {b: 'bar'}]}, collation: {locale: " - "'reverse'}}")); + runQueryAsCommand( + fromjson("{find: 'testns', filter: {$or: [{a: 'foo'}, {b: 'bar'}]}, collation: {locale: " + "'reverse'}}")); assertNumSolutions(1U); assertSolutionExists("{cscan: {dir: 1}}"); @@ -202,9 +202,9 @@ TEST_F(QueryPlannerTest, OrQueryCanBeIndexedWhenBothBranchesHaveIndexWithMatchin addIndex(fromjson("{a: 1}"), &collator); addIndex(fromjson("{b: 1}"), &collator); - runQueryAsCommand(fromjson( - "{find: 'testns', filter: {$or: [{a: 'foo'}, {b: 'bar'}]}, collation: {locale: " - "'reverse'}}")); + runQueryAsCommand( + fromjson("{find: 'testns', filter: {$or: [{a: 'foo'}, {b: 'bar'}]}, collation: {locale: " + "'reverse'}}")); assertNumSolutions(2U); assertSolutionExists("{cscan: {dir: 1}}"); diff --git a/src/mongo/db/query/query_planner_geo_test.cpp b/src/mongo/db/query/query_planner_geo_test.cpp index f4218f20fb9..9e087444079 100644 --- a/src/mongo/db/query/query_planner_geo_test.cpp +++ b/src/mongo/db/query/query_planner_geo_test.cpp @@ -75,10 +75,10 @@ TEST_F(QueryPlannerTest, Basic2DSphereCompound) { addIndex(BSON("loc" << "2dsphere")); - runQuery(fromjson( - "{loc:{$near:{$geometry:{type:'Point'," - "coordinates : [-81.513743,28.369947] }," - " $maxDistance :100}},a: 'mouse'}")); + runQuery( + fromjson("{loc:{$near:{$geometry:{type:'Point'," + "coordinates : [-81.513743,28.369947] }," + " $maxDistance :100}},a: 'mouse'}")); assertNumSolutions(1U); assertSolutionExists( "{fetch: {node: {geoNear2dsphere: {pattern: {loc: '2dsphere'}, " @@ -88,11 +88,12 @@ TEST_F(QueryPlannerTest, Basic2DSphereCompound) { TEST_F(QueryPlannerTest, Basic2DCompound) { addIndex(BSON("loc" << "2d" - << "a" << 1)); + << "a" + << 1)); - runQuery(fromjson( - "{ loc: { $geoWithin: { $box : [[0, 0],[10, 10]] } }," - "a: 'mouse' }")); + runQuery( + fromjson("{ loc: { $geoWithin: { $box : [[0, 0],[10, 10]] } }," + "a: 'mouse' }")); assertNumSolutions(2U); assertSolutionExists("{cscan: {dir: 1}}"); assertSolutionExists( @@ -110,10 +111,10 @@ TEST_F(QueryPlannerTest, Multikey2DSphereCompound) { << "2dsphere"), true); - runQuery(fromjson( - "{loc:{$near:{$geometry:{type:'Point'," - "coordinates : [-81.513743,28.369947] }," - " $maxDistance :100}},a: 'mouse'}")); + runQuery( + fromjson("{loc:{$near:{$geometry:{type:'Point'," + "coordinates : [-81.513743,28.369947] }," + " $maxDistance :100}},a: 'mouse'}")); assertNumSolutions(1U); assertSolutionExists( "{fetch: {node: {geoNear2dsphere: {pattern: {loc: '2dsphere'}, " @@ -125,9 +126,9 @@ TEST_F(QueryPlannerTest, Basic2DSphereNonNear) { addIndex(BSON("a" << "2dsphere")); - runQuery(fromjson( - "{a: {$geoIntersects: {$geometry: {type: 'Point'," - "coordinates: [10.0, 10.0]}}}}")); + runQuery( + fromjson("{a: {$geoIntersects: {$geometry: {type: 'Point'," + "coordinates: [10.0, 10.0]}}}}")); assertNumSolutions(2U); assertSolutionExists("{cscan: {dir: 1}}"); assertSolutionExists("{fetch: {node: {ixscan: {pattern: {a: '2dsphere'}}}}}"); @@ -147,9 +148,9 @@ TEST_F(QueryPlannerTest, Multikey2DSphereNonNear) { << "2dsphere"), true); - runQuery(fromjson( - "{a: {$geoIntersects: {$geometry: {type: 'Point'," - "coordinates: [10.0, 10.0]}}}}")); + runQuery( + fromjson("{a: {$geoIntersects: {$geometry: {type: 'Point'," + "coordinates: [10.0, 10.0]}}}}")); assertNumSolutions(2U); assertSolutionExists("{cscan: {dir: 1}}"); assertSolutionExists("{fetch: {node: {ixscan: {pattern: {a: '2dsphere'}}}}}"); @@ -182,9 +183,9 @@ TEST_F(QueryPlannerTest, Basic2DSphereGeoNear) { "{geoNear2dsphere: {pattern: {a: '2dsphere'}, " "bounds: {a: [['MinKey', 'MaxKey', true, true]]}}}"); - runQuery(fromjson( - "{a: {$geoNear: {$geometry: {type: 'Point', coordinates: [0,0]}," - "$maxDistance:100}}}")); + runQuery( + fromjson("{a: {$geoNear: {$geometry: {type: 'Point', coordinates: [0,0]}," + "$maxDistance:100}}}")); assertNumSolutions(1U); assertSolutionExists( "{geoNear2dsphere: {pattern: {a: '2dsphere'}, " @@ -204,9 +205,9 @@ TEST_F(QueryPlannerTest, Multikey2DSphereGeoNear) { "{geoNear2dsphere: {pattern: {a: '2dsphere'}, " "bounds: {a: [['MinKey', 'MaxKey', true, true]]}}}"); - runQuery(fromjson( - "{a: {$geoNear: {$geometry: {type: 'Point', coordinates: [0,0]}," - "$maxDistance:100}}}")); + runQuery( + fromjson("{a: {$geoNear: {$geometry: {type: 'Point', coordinates: [0,0]}," + "$maxDistance:100}}}")); assertNumSolutions(1U); assertSolutionExists( "{geoNear2dsphere: {pattern: {a: '2dsphere'}, " @@ -277,9 +278,9 @@ TEST_F(QueryPlannerTest, GeoNearMultipleRelevantIndicesButOnlyOneCompatible) { addIndex(BSON("b" << 1 << "a" << "2dsphere")); - runQuery(fromjson( - "{a: {$nearSphere: {$geometry: {type: 'Point', coordinates: [0,0]}}}," - " b: {$exists: false}}")); + runQuery( + fromjson("{a: {$nearSphere: {$geometry: {type: 'Point', coordinates: [0,0]}}}," + " b: {$exists: false}}")); assertNumSolutions(1U); assertSolutionExists( @@ -294,9 +295,9 @@ TEST_F(QueryPlannerTest, Or2DNonNear) { << "2d")); addIndex(BSON("b" << "2d")); - runQuery(fromjson( - "{$or: [ {a : { $within : { $polygon : [[0,0], [2,0], [4,0]] } }}," - " {b : { $within : { $center : [[ 5, 5 ], 7 ] } }} ]}")); + runQuery( + fromjson("{$or: [ {a : { $within : { $polygon : [[0,0], [2,0], [4,0]] } }}," + " {b : { $within : { $center : [[ 5, 5 ], 7 ] } }} ]}")); assertNumSolutions(2U); assertSolutionExists("{cscan: {dir: 1}}"); @@ -309,9 +310,9 @@ TEST_F(QueryPlannerTest, Or2DNonNear) { TEST_F(QueryPlannerTest, Or2DSameFieldNonNear) { addIndex(BSON("a" << "2d")); - runQuery(fromjson( - "{$or: [ {a : { $within : { $polygon : [[0,0], [2,0], [4,0]] } }}," - " {a : { $within : { $center : [[ 5, 5 ], 7 ] } }} ]}")); + runQuery( + fromjson("{$or: [ {a : { $within : { $polygon : [[0,0], [2,0], [4,0]] } }}," + " {a : { $within : { $center : [[ 5, 5 ], 7 ] } }} ]}")); assertNumSolutions(2U); assertSolutionExists("{cscan: {dir: 1}}"); @@ -344,10 +345,10 @@ TEST_F(QueryPlannerTest, Or2DSphereNonNearMultikey) { addIndex(BSON("b" << "2dsphere"), true); - runQuery(fromjson( - "{$or: [ {a: {$geoIntersects: {$geometry: " - "{type: 'Point', coordinates: [10.0, 10.0]}}}}," - " {b: {$geoWithin: { $centerSphere: [[ 10, 20 ], 0.01 ] } }} ]}")); + runQuery( + fromjson("{$or: [ {a: {$geoIntersects: {$geometry: " + "{type: 'Point', coordinates: [10.0, 10.0]}}}}," + " {b: {$geoWithin: { $centerSphere: [[ 10, 20 ], 0.01 ] } }} ]}")); assertNumSolutions(2U); assertSolutionExists("{cscan: {dir: 1}}"); @@ -360,9 +361,9 @@ TEST_F(QueryPlannerTest, Or2DSphereNonNearMultikey) { TEST_F(QueryPlannerTest, And2DSameFieldNonNear) { addIndex(BSON("a" << "2d")); - runQuery(fromjson( - "{$and: [ {a : { $within : { $polygon : [[0,0], [2,0], [4,0]] } }}," - " {a : { $within : { $center : [[ 5, 5 ], 7 ] } }} ]}")); + runQuery( + fromjson("{$and: [ {a : { $within : { $polygon : [[0,0], [2,0], [4,0]] } }}," + " {a : { $within : { $center : [[ 5, 5 ], 7 ] } }} ]}")); assertNumSolutions(2U); assertSolutionExists("{cscan: {dir: 1}}"); @@ -374,9 +375,9 @@ TEST_F(QueryPlannerTest, And2DSameFieldNonNear) { TEST_F(QueryPlannerTest, And2DWith2DNearSameField) { addIndex(BSON("a" << "2d")); - runQuery(fromjson( - "{$and: [ {a : { $within : { $polygon : [[0,0], [2,0], [4,0]] } }}," - " {a : { $near : [ 5, 5 ] } } ]}")); + runQuery( + fromjson("{$and: [ {a : { $within : { $polygon : [[0,0], [2,0], [4,0]] } }}," + " {a : { $near : [ 5, 5 ] } } ]}")); // GEO_NEAR must use the index, and GEO predicate becomes a filter. assertNumSolutions(1U); @@ -388,9 +389,9 @@ TEST_F(QueryPlannerTest, And2DWith2DNearSameFieldMultikey) { addIndex(BSON("geo" << "2d"), multikey); - runQuery(fromjson( - "{$and: [{geo: {$near: [0, 0]}}, " - "{geo: {$within: {$polygon: [[0, 0], [1, 0], [1, 1]]}}}]}")); + runQuery( + fromjson("{$and: [{geo: {$near: [0, 0]}}, " + "{geo: {$within: {$polygon: [[0, 0], [1, 0], [1, 1]]}}}]}")); // GEO_NEAR must use the index, and GEO predicate becomes a filter. assertNumSolutions(1U); @@ -402,11 +403,11 @@ TEST_F(QueryPlannerTest, And2DWith2DNearSameFieldMultikey) { TEST_F(QueryPlannerTest, And2DSphereSameFieldNonNear) { addIndex(BSON("a" << "2dsphere")); - runQuery(fromjson( - "{$and: [ {a: {$geoIntersects: {$geometry: " - "{type: 'Point', coordinates: [3.0, 1.0]}}}}," - " {a: {$geoIntersects: {$geometry: " - "{type: 'Point', coordinates: [4.0, 1.0]}}}}]}")); + runQuery( + fromjson("{$and: [ {a: {$geoIntersects: {$geometry: " + "{type: 'Point', coordinates: [3.0, 1.0]}}}}," + " {a: {$geoIntersects: {$geometry: " + "{type: 'Point', coordinates: [4.0, 1.0]}}}}]}")); assertNumSolutions(2U); assertSolutionExists("{cscan: {dir: 1}}"); @@ -420,11 +421,11 @@ TEST_F(QueryPlannerTest, And2DSphereSameFieldNonNearMultikey) { addIndex(BSON("a" << "2dsphere"), true); - runQuery(fromjson( - "{$and: [ {a: {$geoIntersects: {$geometry: " - "{type: 'Point', coordinates: [3.0, 1.0]}}}}," - " {a: {$geoIntersects: {$geometry: " - "{type: 'Point', coordinates: [4.0, 1.0]}}}}]}")); + runQuery( + fromjson("{$and: [ {a: {$geoIntersects: {$geometry: " + "{type: 'Point', coordinates: [3.0, 1.0]}}}}," + " {a: {$geoIntersects: {$geometry: " + "{type: 'Point', coordinates: [4.0, 1.0]}}}}]}")); assertNumSolutions(3U); assertSolutionExists("{cscan: {dir: 1}}"); @@ -434,11 +435,11 @@ TEST_F(QueryPlannerTest, And2DSphereSameFieldNonNearMultikey) { TEST_F(QueryPlannerTest, And2DSphereWithNearSameField) { addIndex(BSON("a" << "2dsphere")); - runQuery(fromjson( - "{$and: [{a: {$geoIntersects: {$geometry: " - "{type: 'Point', coordinates: [3.0, 1.0]}}}}," - "{a: {$near: {$geometry: " - "{type: 'Point', coordinates: [10.0, 10.0]}}}}]}")); + runQuery( + fromjson("{$and: [{a: {$geoIntersects: {$geometry: " + "{type: 'Point', coordinates: [3.0, 1.0]}}}}," + "{a: {$near: {$geometry: " + "{type: 'Point', coordinates: [10.0, 10.0]}}}}]}")); // GEO_NEAR must use the index, and GEO predicate becomes a filter. assertNumSolutions(1U); @@ -450,11 +451,11 @@ TEST_F(QueryPlannerTest, And2DSphereWithNearSameFieldMultikey) { addIndex(BSON("a" << "2dsphere"), true); - runQuery(fromjson( - "{$and: [{a: {$geoIntersects: {$geometry: " - "{type: 'Point', coordinates: [3.0, 1.0]}}}}," - "{a: {$near: {$geometry: " - "{type: 'Point', coordinates: [10.0, 10.0]}}}}]}")); + runQuery( + fromjson("{$and: [{a: {$geoIntersects: {$geometry: " + "{type: 'Point', coordinates: [3.0, 1.0]}}}}," + "{a: {$near: {$geometry: " + "{type: 'Point', coordinates: [10.0, 10.0]}}}}]}")); // GEO_NEAR must use the index, and GEO predicate becomes a filter. assertNumSolutions(1U); @@ -466,11 +467,11 @@ TEST_F(QueryPlannerTest, And2DSphereWithNearSameFieldMultikey) { TEST_F(QueryPlannerTest, Or2DSphereSameFieldNonNear) { addIndex(BSON("a" << "2dsphere")); - runQuery(fromjson( - "{$or: [ {a: {$geoIntersects: {$geometry: " - "{type: 'Point', coordinates: [3.0, 1.0]}}}}," - " {a: {$geoIntersects: {$geometry: " - "{type: 'Point', coordinates: [4.0, 1.0]}}}}]}")); + runQuery( + fromjson("{$or: [ {a: {$geoIntersects: {$geometry: " + "{type: 'Point', coordinates: [3.0, 1.0]}}}}," + " {a: {$geoIntersects: {$geometry: " + "{type: 'Point', coordinates: [4.0, 1.0]}}}}]}")); assertNumSolutions(2U); assertSolutionExists("{cscan: {dir: 1}}"); @@ -482,11 +483,11 @@ TEST_F(QueryPlannerTest, Or2DSphereSameFieldNonNearMultikey) { addIndex(BSON("a" << "2dsphere"), true); - runQuery(fromjson( - "{$or: [ {a: {$geoIntersects: {$geometry: " - "{type: 'Point', coordinates: [3.0, 1.0]}}}}," - " {a: {$geoIntersects: {$geometry: " - "{type: 'Point', coordinates: [4.0, 1.0]}}}}]}")); + runQuery( + fromjson("{$or: [ {a: {$geoIntersects: {$geometry: " + "{type: 'Point', coordinates: [3.0, 1.0]}}}}," + " {a: {$geoIntersects: {$geometry: " + "{type: 'Point', coordinates: [4.0, 1.0]}}}}]}")); assertNumSolutions(2U); assertSolutionExists("{cscan: {dir: 1}}"); @@ -498,9 +499,9 @@ TEST_F(QueryPlannerTest, CompoundMultikey2DSphereNear) { addIndex(BSON("a" << 1 << "b" << "2dsphere"), true); - runQuery(fromjson( - "{a: {$gte: 0}, b: {$near: {$geometry: " - "{type: 'Point', coordinates: [2, 2]}}}}")); + runQuery( + fromjson("{a: {$gte: 0}, b: {$near: {$geometry: " + "{type: 'Point', coordinates: [2, 2]}}}}")); assertNumSolutions(1U); assertSolutionExists( @@ -513,9 +514,9 @@ TEST_F(QueryPlannerTest, CompoundMultikey2DSphereNearFetchRequired) { addIndex(BSON("a" << 1 << "b" << "2dsphere"), true); - runQuery(fromjson( - "{a: {$gte: 0, $lt: 5}, b: {$near: {$geometry: " - "{type: 'Point', coordinates: [2, 2]}}}}")); + runQuery( + fromjson("{a: {$gte: 0, $lt: 5}, b: {$near: {$geometry: " + "{type: 'Point', coordinates: [2, 2]}}}}")); assertNumSolutions(1U); assertSolutionExists( @@ -532,9 +533,9 @@ TEST_F(QueryPlannerTest, CompoundMultikey2DSphereNearMultipleIndices) { addIndex(BSON("c" << 1 << "b" << "2dsphere"), true); - runQuery(fromjson( - "{a: {$gte: 0}, c: 3, b: {$near: {$geometry: " - "{type: 'Point', coordinates: [2, 2]}}}}")); + runQuery( + fromjson("{a: {$gte: 0}, c: 3, b: {$near: {$geometry: " + "{type: 'Point', coordinates: [2, 2]}}}}")); assertNumSolutions(2U); assertSolutionExists( @@ -552,9 +553,9 @@ TEST_F(QueryPlannerTest, CompoundMultikey2DSphereNearMultipleLeadingFields) { addIndex(BSON("a" << 1 << "b" << 1 << "c" << "2dsphere"), true); - runQuery(fromjson( - "{a: {$lt: 5, $gt: 1}, b: 6, c: {$near: {$geometry: " - "{type: 'Point', coordinates: [2, 2]}}}}")); + runQuery( + fromjson("{a: {$lt: 5, $gt: 1}, b: 6, c: {$near: {$geometry: " + "{type: 'Point', coordinates: [2, 2]}}}}")); assertNumSolutions(1U); assertSolutionExists( @@ -569,10 +570,10 @@ TEST_F(QueryPlannerTest, CompoundMultikey2DSphereNearMultipleGeoPreds) { addIndex(BSON("a" << 1 << "b" << 1 << "c" << "2dsphere"), true); - runQuery(fromjson( - "{a: 1, b: 6, $and: [" - "{c: {$near: {$geometry: {type: 'Point', coordinates: [2, 2]}}}}," - "{c: {$geoWithin: {$box: [ [1, 1], [3, 3] ] } } } ] }")); + runQuery( + fromjson("{a: 1, b: 6, $and: [" + "{c: {$near: {$geometry: {type: 'Point', coordinates: [2, 2]}}}}," + "{c: {$geoWithin: {$box: [ [1, 1], [3, 3] ] } } } ] }")); assertNumSolutions(1U); assertSolutionExists( @@ -585,12 +586,15 @@ TEST_F(QueryPlannerTest, CompoundMultikey2DSphereNearCompoundTest) { // true means multikey addIndex(BSON("a" << 1 << "b" << "2dsphere" - << "c" << 1 << "d" << 1), + << "c" + << 1 + << "d" + << 1), true); - runQuery(fromjson( - "{a: {$gte: 0}, c: {$gte: 0, $lt: 4}, d: {$gt: 1, $lt: 5}," - "b: {$near: {$geometry: " - "{type: 'Point', coordinates: [2, 2]}}}}")); + runQuery( + fromjson("{a: {$gte: 0}, c: {$gte: 0, $lt: 4}, d: {$gt: 1, $lt: 5}," + "b: {$near: {$geometry: " + "{type: 'Point', coordinates: [2, 2]}}}}")); assertNumSolutions(1U); assertSolutionExists( @@ -604,7 +608,8 @@ TEST_F(QueryPlannerTest, CompoundMultikey2DNear) { // true means multikey addIndex(BSON("a" << "2d" - << "b" << 1), + << "b" + << 1), true); runQuery(fromjson("{a: {$near: [0, 0]}, b: {$gte: 0}}")); @@ -698,9 +703,8 @@ TEST_F(QueryPlannerTest, CantUseNonCompoundGeoIndexToProvideSort) { TEST_F(QueryPlannerTest, CantUseNonCompoundGeoIndexToProvideSortWithIndexablePred) { addIndex(BSON("x" << "2dsphere")); - runQuerySortProj(fromjson( - "{x: {$geoIntersects: {$geometry: {type: 'Point'," - " coordinates: [0, 0]}}}}"), + runQuerySortProj(fromjson("{x: {$geoIntersects: {$geometry: {type: 'Point'," + " coordinates: [0, 0]}}}}"), BSON("x" << 1), BSONObj()); @@ -727,9 +731,8 @@ TEST_F(QueryPlannerTest, CantUseCompoundGeoIndexToProvideSortIfNoGeoPred) { TEST_F(QueryPlannerTest, CanUseCompoundGeoIndexToProvideSortWithGeoPred) { addIndex(BSON("x" << 1 << "y" << "2dsphere")); - runQuerySortProj(fromjson( - "{x: 1, y: {$geoIntersects: {$geometry: {type: 'Point'," - " coordinates: [0, 0]}}}}"), + runQuerySortProj(fromjson("{x: 1, y: {$geoIntersects: {$geometry: {type: 'Point'," + " coordinates: [0, 0]}}}}"), BSON("x" << 1), BSONObj()); @@ -768,19 +771,19 @@ TEST_F(QueryPlannerTest, Negation2DSphereGeoNear) { addIndex(BSON("a" << "2dsphere")); - runQuery(fromjson( - "{$and: [{a: {$nearSphere: [0,0], $maxDistance: 0.31}}, " - "{b: {$ne: 1}}]}")); + runQuery( + fromjson("{$and: [{a: {$nearSphere: [0,0], $maxDistance: 0.31}}, " + "{b: {$ne: 1}}]}")); assertNumSolutions(1U); assertSolutionExists( "{fetch: {node: {geoNear2dsphere: {pattern: {a: '2dsphere'}, " "bounds: {a: [['MinKey', 'MaxKey', true, true]]}}}}}"); - runQuery(fromjson( - "{$and: [{a: {$geoNear: {$geometry: {type: 'Point', " - "coordinates: [0, 0]}," - "$maxDistance: 100}}}," - "{b: {$ne: 1}}]}")); + runQuery( + fromjson("{$and: [{a: {$geoNear: {$geometry: {type: 'Point', " + "coordinates: [0, 0]}," + "$maxDistance: 100}}}," + "{b: {$ne: 1}}]}")); assertNumSolutions(1U); assertSolutionExists( "{fetch: {node: {geoNear2dsphere: {pattern: {a: '2dsphere'}, " @@ -798,19 +801,19 @@ TEST_F(QueryPlannerTest, Negation2DSphereGeoNearMultikey) { << "2dsphere"), true); - runQuery(fromjson( - "{$and: [{a: {$nearSphere: [0,0], $maxDistance: 0.31}}, " - "{b: {$ne: 1}}]}")); + runQuery( + fromjson("{$and: [{a: {$nearSphere: [0,0], $maxDistance: 0.31}}, " + "{b: {$ne: 1}}]}")); assertNumSolutions(1U); assertSolutionExists( "{fetch: {node: {geoNear2dsphere: {pattern: {a: '2dsphere'}, " "bounds: {a: [['MinKey', 'MaxKey', true, true]]}}}}}"); - runQuery(fromjson( - "{$and: [{a: {$geoNear: {$geometry: {type: 'Point', " - "coordinates: [0, 0]}," - "$maxDistance: 100}}}," - "{b: {$ne: 1}}]}")); + runQuery( + fromjson("{$and: [{a: {$geoNear: {$geometry: {type: 'Point', " + "coordinates: [0, 0]}," + "$maxDistance: 100}}}," + "{b: {$ne: 1}}]}")); assertNumSolutions(1U); assertSolutionExists( "{fetch: {node: {geoNear2dsphere: {pattern: {a: '2dsphere'}, " @@ -1065,10 +1068,10 @@ TEST_F(QueryPlannerGeo2dsphereTest, CannotIntersectBoundsOfTwoSeparateElemMatche << "2dsphere"), multikeyPaths); - runQuery(fromjson( - "{$and: [{a: {$elemMatch: {b: {$gte: 0}, c: {$lt: 20}}}}, " - "{a: {$elemMatch: {b: {$lt: 10}, c: {$gte: 5}}}}, " - "{'a.geo': {$nearSphere: [0, 0]}}]}")); + runQuery( + fromjson("{$and: [{a: {$elemMatch: {b: {$gte: 0}, c: {$lt: 20}}}}, " + "{a: {$elemMatch: {b: {$lt: 10}, c: {$gte: 5}}}}, " + "{'a.geo': {$nearSphere: [0, 0]}}]}")); assertNumSolutions(1U); assertSolutionExists( @@ -1096,7 +1099,10 @@ TEST_F(QueryPlannerGeo2dsphereTest, MultikeyPaths multikeyPaths{{1U}, {1U}, {1U}}; addIndex(BSON("a.geo" << "2dsphere" - << "a.b" << 1 << "a.c" << 1), + << "a.b" + << 1 + << "a.c" + << 1), multikeyPaths); runQuery(fromjson("{'a.geo': {$nearSphere: [0, 0]}, 'a.b': 2, 'a.c': 3}")); @@ -1126,7 +1132,10 @@ TEST_F(QueryPlannerGeo2dsphereTest, MultikeyPaths multikeyPaths{{0U}, {0U}, {0U}}; addIndex(BSON("a.geo" << "2dsphere" - << "a.b" << 1 << "a.c" << 1), + << "a.b" + << 1 + << "a.c" + << 1), multikeyPaths); runQuery(fromjson("{'a.geo': {$nearSphere: [0, 0]}, 'a.b': 2, 'a.c': 3}")); @@ -1157,7 +1166,10 @@ TEST_F(QueryPlannerGeo2dsphereTest, MultikeyPaths multikeyPaths{{0U}, {0U}, {0U}}; addIndex(BSON("a.geo" << "2dsphere" - << "a.b" << 1 << "a.c" << 1), + << "a.b" + << 1 + << "a.c" + << 1), multikeyPaths); runQuery(fromjson("{'a.geo': {$nearSphere: [0, 0]}, a: {$elemMatch: {b: 2, c: 3}}}")); @@ -1189,7 +1201,10 @@ TEST_F(QueryPlannerGeo2dsphereTest, MultikeyPaths multikeyPaths{{0U, 1U}, {0U, 1U}, {0U, 1U}}; addIndex(BSON("a.b.geo" << "2dsphere" - << "a.b.c" << 1 << "a.b.d" << 1), + << "a.b.c" + << 1 + << "a.b.d" + << 1), multikeyPaths); runQuery(fromjson("{'a.b.geo': {$nearSphere: [0, 0]}, a: {$elemMatch: {'b.c': 2, 'b.d': 3}}}")); @@ -1207,9 +1222,9 @@ TEST_F(QueryPlannerGeo2dsphereTest, CanIntersectBoundsOn2dsphereFieldWhenItIsNot addIndex(BSON("geo" << "2dsphere"), multikeyPaths); - runQuery(fromjson( - "{$and: [{geo: {$nearSphere: [0, 0]}}, " - "{geo: {$geoIntersects: {$geometry: {type: 'Point', coordinates: [0, 0]}}}}]}")); + runQuery( + fromjson("{$and: [{geo: {$nearSphere: [0, 0]}}, " + "{geo: {$geoIntersects: {$geometry: {type: 'Point', coordinates: [0, 0]}}}}]}")); assertNumSolutions(1U); assertSolutionExists( @@ -1223,9 +1238,9 @@ TEST_F(QueryPlannerGeo2dsphereTest, CannotIntersectBoundsOn2dsphereFieldWhenItIs addIndex(BSON("geo" << "2dsphere"), multikeyPaths); - runQuery(fromjson( - "{$and: [{geo: {$nearSphere: [0, 0]}}, " - "{geo: {$geoIntersects: {$geometry: {type: 'Point', coordinates: [0, 0]}}}}]}")); + runQuery( + fromjson("{$and: [{geo: {$nearSphere: [0, 0]}}, " + "{geo: {$geoIntersects: {$geometry: {type: 'Point', coordinates: [0, 0]}}}}]}")); assertNumSolutions(1U); assertSolutionExists( @@ -1353,7 +1368,8 @@ TEST_F(QueryPlanner2dsphereVersionTest, TwoDNearCompound) { std::vector<int> versions{2, 3}; std::vector<BSONObj> keyPatterns = {BSON("geo" << "2dsphere" - << "nongeo" << 1)}; + << "nongeo" + << 1)}; BSONObj predicate = fromjson("{geo: {$nearSphere: [-71.34895, 42.46037]}}"); testMultiple2dsphereIndexVersions(versions, keyPatterns, predicate, 1U); } @@ -1364,10 +1380,16 @@ TEST_F(QueryPlanner2dsphereVersionTest, TwoDSphereSparseBelowOr) { std::vector<int> versions{2, 3}; std::vector<BSONObj> keyPatterns = {BSON("geo1" << "2dsphere" - << "a" << 1 << "b" << 1), + << "a" + << 1 + << "b" + << 1), BSON("geo2" << "2dsphere" - << "a" << 1 << "b" << 1)}; + << "a" + << 1 + << "b" + << 1)}; BSONObj predicate = fromjson( "{a: 4, b: 5, $or: [" @@ -1389,7 +1411,8 @@ TEST_F(QueryPlanner2dsphereVersionTest, TwoDSphereSparseBelowElemMatch) { std::vector<int> versions{2, 3}; std::vector<BSONObj> keyPatterns = {BSON("a.b" << "2dsphere" - << "a.c" << 1)}; + << "a.c" + << 1)}; BSONObj predicate = fromjson( "{a: {$elemMatch: {b: {$geoWithin: {$centerSphere: [[10,20], 0.01]}}," diff --git a/src/mongo/db/query/query_planner_test.cpp b/src/mongo/db/query/query_planner_test.cpp index 108d4002195..de70d351035 100644 --- a/src/mongo/db/query/query_planner_test.cpp +++ b/src/mongo/db/query/query_planner_test.cpp @@ -666,9 +666,9 @@ TEST_F(QueryPlannerTest, OrOfAnd3) { // SERVER-12594: we don't yet collapse an OR of ANDs into a single ixscan. TEST_F(QueryPlannerTest, OrOfAnd4) { addIndex(BSON("a" << 1 << "b" << 1)); - runQuery(fromjson( - "{$or: [{a:{$gt:1,$lt:5}, b:{$gt:0,$lt:3}, c:6}, " - "{a:3, b:{$gt:1,$lt:2}, c:{$gt:0,$lt:10}}]}")); + runQuery( + fromjson("{$or: [{a:{$gt:1,$lt:5}, b:{$gt:0,$lt:3}, c:6}, " + "{a:3, b:{$gt:1,$lt:2}, c:{$gt:0,$lt:10}}]}")); assertNumSolutions(2U); assertSolutionExists("{cscan: {dir: 1}}"); @@ -684,9 +684,9 @@ TEST_F(QueryPlannerTest, OrOfAnd4) { // SERVER-12594: we don't yet collapse an OR of ANDs into a single ixscan. TEST_F(QueryPlannerTest, OrOfAnd5) { addIndex(BSON("a" << 1 << "b" << 1)); - runQuery(fromjson( - "{$or: [{a:{$gt:1,$lt:5}, c:6}, " - "{a:3, b:{$gt:1,$lt:2}, c:{$gt:0,$lt:10}}]}")); + runQuery( + fromjson("{$or: [{a:{$gt:1,$lt:5}, c:6}, " + "{a:3, b:{$gt:1,$lt:2}, c:{$gt:0,$lt:10}}]}")); assertNumSolutions(2U); assertSolutionExists("{cscan: {dir: 1}}"); @@ -870,9 +870,9 @@ TEST_F(QueryPlannerTest, OrInexactWithExact2) { // SERVER-13960: an exact, inexact covered, and inexact fetch predicate. TEST_F(QueryPlannerTest, OrAllThreeTightnesses) { addIndex(BSON("names" << 1)); - runQuery(fromjson( - "{$or: [{names: 'frank'}, {names: /^al(ice)|(ex)/}," - "{names: {$elemMatch: {$eq: 'thomas'}}}]}")); + runQuery( + fromjson("{$or: [{names: 'frank'}, {names: /^al(ice)|(ex)/}," + "{names: {$elemMatch: {$eq: 'thomas'}}}]}")); assertNumSolutions(2U); assertSolutionExists("{cscan: {dir: 1}}"); @@ -887,9 +887,9 @@ TEST_F(QueryPlannerTest, OrAllThreeTightnesses) { TEST_F(QueryPlannerTest, OrTwoInexactFetch) { // true means multikey addIndex(BSON("names" << 1), true); - runQuery(fromjson( - "{$or: [{names: {$elemMatch: {$eq: 'alexandra'}}}," - "{names: {$elemMatch: {$eq: 'thomas'}}}]}")); + runQuery( + fromjson("{$or: [{names: {$elemMatch: {$eq: 'alexandra'}}}," + "{names: {$elemMatch: {$eq: 'thomas'}}}]}")); assertNumSolutions(2U); assertSolutionExists("{cscan: {dir: 1}}"); @@ -917,9 +917,9 @@ TEST_F(QueryPlannerTest, OrInexactCoveredMultikey) { TEST_F(QueryPlannerTest, OrElemMatchObject) { // true means multikey addIndex(BSON("a.b" << 1), true); - runQuery(fromjson( - "{$or: [{a: {$elemMatch: {b: {$lte: 1}}}}," - "{a: {$elemMatch: {b: {$gte: 4}}}}]}")); + runQuery( + fromjson("{$or: [{a: {$elemMatch: {b: {$lte: 1}}}}," + "{a: {$elemMatch: {b: {$gte: 4}}}}]}")); assertNumSolutions(2U); assertSolutionExists("{cscan: {dir: 1}}"); @@ -935,9 +935,9 @@ TEST_F(QueryPlannerTest, OrElemMatchObject) { TEST_F(QueryPlannerTest, OrElemMatchObjectBeneathAnd) { // true means multikey addIndex(BSON("a.b" << 1), true); - runQuery(fromjson( - "{$or: [{'a.b': 0, a: {$elemMatch: {b: {$lte: 1}}}}," - "{a: {$elemMatch: {b: {$gte: 4}}}}]}")); + runQuery( + fromjson("{$or: [{'a.b': 0, a: {$elemMatch: {b: {$lte: 1}}}}," + "{a: {$elemMatch: {b: {$gte: 4}}}}]}")); assertNumSolutions(3U); assertSolutionExists("{cscan: {dir: 1}}"); @@ -988,9 +988,9 @@ TEST_F(QueryPlannerTest, OrWithExactAndInexact) { // SERVER-13960: $in with exact, inexact covered, and inexact fetch predicates. TEST_F(QueryPlannerTest, OrWithExactAndInexact2) { addIndex(BSON("name" << 1)); - runQuery(fromjson( - "{$or: [{name: {$in: ['thomas', /^alexand(er|ra)/]}}," - "{name: {$exists: false}}]}")); + runQuery( + fromjson("{$or: [{name: {$in: ['thomas', /^alexand(er|ra)/]}}," + "{name: {$exists: false}}]}")); assertNumSolutions(2U); assertSolutionExists("{cscan: {dir: 1}}"); @@ -1005,9 +1005,9 @@ TEST_F(QueryPlannerTest, OrWithExactAndInexact2) { TEST_F(QueryPlannerTest, OrWithExactAndInexact3) { addIndex(BSON("a" << 1)); addIndex(BSON("b" << 1)); - runQuery(fromjson( - "{$or: [{a: {$in: [/z/, /x/]}}, {a: 'w'}," - "{b: {$exists: false}}, {b: {$in: ['p']}}]}")); + runQuery( + fromjson("{$or: [{a: {$in: [/z/, /x/]}}, {a: 'w'}," + "{b: {$exists: false}}, {b: {$in: ['p']}}]}")); assertNumSolutions(2U); assertSolutionExists("{cscan: {dir: 1}}"); @@ -1420,7 +1420,8 @@ TEST_F(QueryPlannerTest, CantUseHashedIndexToProvideSortWithIndexablePred) { TEST_F(QueryPlannerTest, CantUseTextIndexToProvideSort) { addIndex(BSON("x" << 1 << "_fts" << "text" - << "_ftsx" << 1)); + << "_ftsx" + << 1)); runQuerySortProj(BSONObj(), BSON("x" << 1), BSONObj()); ASSERT_EQUALS(getNumSolutions(), 1U); @@ -1766,10 +1767,9 @@ TEST_F(QueryPlannerTest, ManyInWithSort) { // SERVER-1205 TEST_F(QueryPlannerTest, TooManyToExplode) { addIndex(BSON("a" << 1 << "b" << 1 << "c" << 1 << "d" << 1)); - runQuerySortProjSkipNToReturn(fromjson( - "{a: {$in: [1,2,3,4,5,6]}," - "b:{$in:[1,2,3,4,5,6,7,8]}," - "c:{$in:[1,2,3,4,5,6,7,8]}}"), + runQuerySortProjSkipNToReturn(fromjson("{a: {$in: [1,2,3,4,5,6]}," + "b:{$in:[1,2,3,4,5,6,7,8]}," + "c:{$in:[1,2,3,4,5,6,7,8]}}"), BSON("d" << 1), BSONObj(), 0, @@ -1962,11 +1962,10 @@ TEST_F(QueryPlannerTest, TooManyToExplodeOr) { addIndex(BSON("b" << 1 << "e" << 1)); addIndex(BSON("c" << 1 << "e" << 1)); addIndex(BSON("d" << 1 << "e" << 1)); - runQuerySortProj(fromjson( - "{$or: [{a: {$in: [1,2,3,4,5,6]}," - "b: {$in: [1,2,3,4,5,6]}}," - "{c: {$in: [1,2,3,4,5,6]}," - "d: {$in: [1,2,3,4,5,6]}}]}"), + runQuerySortProj(fromjson("{$or: [{a: {$in: [1,2,3,4,5,6]}," + "b: {$in: [1,2,3,4,5,6]}}," + "{c: {$in: [1,2,3,4,5,6]}," + "d: {$in: [1,2,3,4,5,6]}}]}"), BSON("e" << 1), BSONObj()); @@ -2004,9 +2003,8 @@ TEST_F(QueryPlannerTest, TooManyToExplodeOr) { TEST_F(QueryPlannerTest, ExplodeIxscanWithFilter) { addIndex(BSON("a" << 1 << "b" << 1)); - runQuerySortProj(fromjson( - "{$and: [{b: {$regex: 'foo', $options: 'i'}}," - "{a: {$in: [1, 2]}}]}"), + runQuerySortProj(fromjson("{$and: [{b: {$regex: 'foo', $options: 'i'}}," + "{a: {$in: [1, 2]}}]}"), BSON("b" << 1), BSONObj()); @@ -2106,9 +2104,9 @@ TEST_F(QueryPlannerTest, TwoPlansElemMatch) { addIndex(BSON("a" << 1 << "b" << 1)); addIndex(BSON("arr.x" << 1 << "a" << 1)); - runQuery(fromjson( - "{arr: { $elemMatch : { x : 5 , y : 5 } }," - " a : 55 , b : { $in : [ 1 , 5 , 8 ] } }")); + runQuery( + fromjson("{arr: { $elemMatch : { x : 5 , y : 5 } }," + " a : 55 , b : { $in : [ 1 , 5 , 8 ] } }")); // 2 indexed solns and one non-indexed ASSERT_EQUALS(getNumSolutions(), 3U); @@ -2763,9 +2761,9 @@ TEST_F(QueryPlannerTest, NegatedRangeIntGTE) { TEST_F(QueryPlannerTest, TwoNegatedRanges) { addIndex(BSON("i" << 1)); - runQuery(fromjson( - "{$and: [{i: {$not: {$lte: 'b'}}}, " - "{i: {$not: {$gte: 'f'}}}]}")); + runQuery( + fromjson("{$and: [{i: {$not: {$lte: 'b'}}}, " + "{i: {$not: {$gte: 'f'}}}]}")); assertNumSolutions(2U); assertSolutionExists("{cscan: {dir: 1}}"); @@ -3273,14 +3271,14 @@ TEST_F(QueryPlannerTest, IntersectCanBeVeryBig) { addIndex(BSON("b" << 1)); addIndex(BSON("c" << 1)); addIndex(BSON("d" << 1)); - runQuery(fromjson( - "{$or: [{ 'a' : null, 'b' : 94, 'c' : null, 'd' : null }," - "{ 'a' : null, 'b' : 98, 'c' : null, 'd' : null }," - "{ 'a' : null, 'b' : 1, 'c' : null, 'd' : null }," - "{ 'a' : null, 'b' : 2, 'c' : null, 'd' : null }," - "{ 'a' : null, 'b' : 7, 'c' : null, 'd' : null }," - "{ 'a' : null, 'b' : 9, 'c' : null, 'd' : null }," - "{ 'a' : null, 'b' : 16, 'c' : null, 'd' : null }]}")); + runQuery( + fromjson("{$or: [{ 'a' : null, 'b' : 94, 'c' : null, 'd' : null }," + "{ 'a' : null, 'b' : 98, 'c' : null, 'd' : null }," + "{ 'a' : null, 'b' : 1, 'c' : null, 'd' : null }," + "{ 'a' : null, 'b' : 2, 'c' : null, 'd' : null }," + "{ 'a' : null, 'b' : 7, 'c' : null, 'd' : null }," + "{ 'a' : null, 'b' : 9, 'c' : null, 'd' : null }," + "{ 'a' : null, 'b' : 16, 'c' : null, 'd' : null }]}")); assertNumSolutions(internalQueryEnumerationMaxOrSolutions); } @@ -3549,13 +3547,13 @@ TEST_F(QueryPlannerTest, OrEnumerationLimit) { // 6 $or clauses, each with 2 indexed predicates // means 2^6 = 64 possibilities. We should hit the limit. - runQuery(fromjson( - "{$or: [{a: 1, b: 1}," - "{a: 2, b: 2}," - "{a: 3, b: 3}," - "{a: 4, b: 4}," - "{a: 5, b: 5}," - "{a: 6, b: 6}]}")); + runQuery( + fromjson("{$or: [{a: 1, b: 1}," + "{a: 2, b: 2}," + "{a: 3, b: 3}," + "{a: 4, b: 4}," + "{a: 5, b: 5}," + "{a: 6, b: 6}]}")); assertNumSolutions(internalQueryEnumerationMaxOrSolutions); } @@ -3569,10 +3567,10 @@ TEST_F(QueryPlannerTest, OrEnumerationLimit2) { // 3 $or clauses, and a few other preds. Each $or clause can // generate up to the max number of allowed $or enumerations. - runQuery(fromjson( - "{$or: [{a: 1, b: 1, c: 1, d: 1}," - "{a: 2, b: 2, c: 2, d: 2}," - "{a: 3, b: 3, c: 3, d: 3}]}")); + runQuery( + fromjson("{$or: [{a: 1, b: 1, c: 1, d: 1}," + "{a: 2, b: 2, c: 2, d: 2}," + "{a: 3, b: 3, c: 3, d: 3}]}")); assertNumSolutions(internalQueryEnumerationMaxOrSolutions); } diff --git a/src/mongo/db/query/query_planner_test_fixture.cpp b/src/mongo/db/query/query_planner_test_fixture.cpp index 2258a818547..aae4d95372f 100644 --- a/src/mongo/db/query/query_planner_test_fixture.cpp +++ b/src/mongo/db/query/query_planner_test_fixture.cpp @@ -34,10 +34,10 @@ #include <algorithm> -#include "mongo/db/namespace_string.h" #include "mongo/db/matcher/expression_parser.h" -#include "mongo/db/matcher/extensions_callback_noop.h" #include "mongo/db/matcher/extensions_callback_disallow_extensions.h" +#include "mongo/db/matcher/extensions_callback_noop.h" +#include "mongo/db/namespace_string.h" #include "mongo/db/query/query_knobs.h" #include "mongo/db/query/query_planner.h" #include "mongo/db/query/query_planner_test_lib.h" @@ -404,8 +404,8 @@ std::unique_ptr<MatchExpression> QueryPlannerTest::parseMatchExpression(const BS StatusWithMatchExpression status = MatchExpressionParser::parse(obj, ExtensionsCallbackDisallowExtensions(), collator); if (!status.isOK()) { - FAIL(str::stream() << "failed to parse query: " << obj.toString() - << ". Reason: " << status.getStatus().toString()); + FAIL(str::stream() << "failed to parse query: " << obj.toString() << ". Reason: " + << status.getStatus().toString()); } return std::move(status.getValue()); } diff --git a/src/mongo/db/query/query_planner_test_lib.cpp b/src/mongo/db/query/query_planner_test_lib.cpp index 2e6d9c000d2..a52505acc23 100644 --- a/src/mongo/db/query/query_planner_test_lib.cpp +++ b/src/mongo/db/query/query_planner_test_lib.cpp @@ -32,7 +32,6 @@ #include "mongo/db/query/query_planner_test_lib.h" -#include <ostream> #include "mongo/db/jsobj.h" #include "mongo/db/json.h" #include "mongo/db/matcher/expression_parser.h" @@ -42,6 +41,7 @@ #include "mongo/db/query/query_solution.h" #include "mongo/unittest/unittest.h" #include "mongo/util/assert_util.h" +#include <ostream> namespace { diff --git a/src/mongo/db/query/query_planner_test_lib.h b/src/mongo/db/query/query_planner_test_lib.h index 0a1931d1828..e8ca0e5c360 100644 --- a/src/mongo/db/query/query_planner_test_lib.h +++ b/src/mongo/db/query/query_planner_test_lib.h @@ -30,7 +30,6 @@ * This file contains tests for mongo/db/query/query_planner.cpp */ -#include <ostream> #include "mongo/db/jsobj.h" #include "mongo/db/json.h" #include "mongo/db/matcher/expression_parser.h" @@ -38,6 +37,7 @@ #include "mongo/db/query/query_solution.h" #include "mongo/unittest/unittest.h" #include "mongo/util/assert_util.h" +#include <ostream> namespace mongo { diff --git a/src/mongo/db/query/query_planner_text_test.cpp b/src/mongo/db/query/query_planner_text_test.cpp index 884b8d1dac9..5050653292a 100644 --- a/src/mongo/db/query/query_planner_text_test.cpp +++ b/src/mongo/db/query/query_planner_text_test.cpp @@ -51,7 +51,8 @@ using namespace mongo; TEST_F(QueryPlannerTest, SimpleText) { addIndex(BSON("_fts" << "text" - << "_ftsx" << 1)); + << "_ftsx" + << 1)); runQuery(fromjson("{$text: {$search: 'blah'}}")); assertNumSolutions(1); @@ -63,7 +64,8 @@ TEST_F(QueryPlannerTest, CantUseTextUnlessHaveTextPred) { params.options = QueryPlannerParams::NO_TABLE_SCAN; addIndex(BSON("a" << 1 << "_fts" << "text" - << "_ftsx" << 1)); + << "_ftsx" + << 1)); runQuery(fromjson("{a:1}")); // No table scans allowed so there is no solution. @@ -76,7 +78,8 @@ TEST_F(QueryPlannerTest, HaveOKPrefixOnTextIndex) { params.options = QueryPlannerParams::NO_TABLE_SCAN; addIndex(BSON("a" << 1 << "_fts" << "text" - << "_ftsx" << 1)); + << "_ftsx" + << 1)); runQuery(fromjson("{a:1, $text:{$search: 'blah'}}")); assertNumSolutions(1); @@ -95,7 +98,8 @@ TEST_F(QueryPlannerTest, HaveBadPrefixOnTextIndex) { params.options = QueryPlannerParams::NO_TABLE_SCAN; addIndex(BSON("a" << 1 << "_fts" << "text" - << "_ftsx" << 1)); + << "_ftsx" + << 1)); runInvalidQuery(fromjson("{a:{$gt: 1}, $text:{$search: 'blah'}}")); runInvalidQuery(fromjson("{$text: {$search: 'blah'}}")); @@ -108,7 +112,8 @@ TEST_F(QueryPlannerTest, ManyPrefixTextIndex) { params.options = QueryPlannerParams::NO_TABLE_SCAN; addIndex(BSON("a" << 1 << "b" << 1 << "_fts" << "text" - << "_ftsx" << 1)); + << "_ftsx" + << 1)); // Both points. runQuery(fromjson("{a:1, b:1, $text:{$search: 'blah'}}")); @@ -133,7 +138,10 @@ TEST_F(QueryPlannerTest, SuffixOptional) { params.options = QueryPlannerParams::NO_TABLE_SCAN; addIndex(BSON("a" << 1 << "_fts" << "text" - << "_ftsx" << 1 << "b" << 1)); + << "_ftsx" + << 1 + << "b" + << 1)); runQuery(fromjson("{a:1, $text:{$search: 'blah'}}")); assertNumSolutions(1); @@ -148,7 +156,10 @@ TEST_F(QueryPlannerTest, RemoveFromSubtree) { params.options = QueryPlannerParams::NO_TABLE_SCAN; addIndex(BSON("a" << 1 << "_fts" << "text" - << "_ftsx" << 1 << "b" << 1)); + << "_ftsx" + << 1 + << "b" + << 1)); runQuery(fromjson("{a:1, $or: [{a:1}, {b:7}], $text:{$search: 'blah'}}")); assertNumSolutions(1); @@ -164,7 +175,8 @@ TEST_F(QueryPlannerTest, CompoundPrefixEvenIfMultikey) { params.options = QueryPlannerParams::NO_TABLE_SCAN; addIndex(BSON("a" << 1 << "b" << 1 << "_fts" << "text" - << "_ftsx" << 1), + << "_ftsx" + << 1), true); // Both points. @@ -177,7 +189,10 @@ TEST_F(QueryPlannerTest, IndexOnOwnFieldButNotLeafPrefix) { params.options = QueryPlannerParams::NO_TABLE_SCAN; addIndex(BSON("a" << 1 << "_fts" << "text" - << "_ftsx" << 1 << "b" << 1)); + << "_ftsx" + << 1 + << "b" + << 1)); // 'a' is not an EQ so it doesn't compound w/the text pred. We also shouldn't use the text // index to satisfy it w/o the text query. @@ -188,7 +203,10 @@ TEST_F(QueryPlannerTest, IndexOnOwnFieldButNotLeafSuffixNoPrefix) { params.options = QueryPlannerParams::NO_TABLE_SCAN; addIndex(BSON("_fts" << "text" - << "_ftsx" << 1 << "b" << 1)); + << "_ftsx" + << 1 + << "b" + << 1)); runQuery(fromjson("{b:{$elemMatch:{$gt: 0, $lt: 2}}, $text:{$search: 'blah'}}")); assertNumSolutions(1); @@ -198,7 +216,8 @@ TEST_F(QueryPlannerTest, TextInsideAndWithCompoundIndex) { params.options = QueryPlannerParams::NO_TABLE_SCAN; addIndex(BSON("a" << 1 << "_fts" << "text" - << "_ftsx" << 1)); + << "_ftsx" + << 1)); runQuery(fromjson("{$and: [{a: 3}, {$text: {$search: 'foo'}}], a: 3}")); assertNumSolutions(1U); @@ -211,7 +230,8 @@ TEST_F(QueryPlannerTest, TextInsideAndWithCompoundIndexAndMultiplePredsOnIndexPr params.options = QueryPlannerParams::NO_TABLE_SCAN; addIndex(BSON("a" << 1 << "_fts" << "text" - << "_ftsx" << 1)); + << "_ftsx" + << 1)); runQuery(fromjson("{$and: [{a: 1}, {a: 2}, {$text: {$search: 'foo'}}]}")); assertNumSolutions(1U); @@ -225,7 +245,8 @@ TEST_F(QueryPlannerTest, TextInsideOrBasic) { addIndex(BSON("a" << 1)); addIndex(BSON("_fts" << "text" - << "_ftsx" << 1)); + << "_ftsx" + << 1)); runQuery(fromjson("{a: 0, $or: [{_id: 1}, {$text: {$search: 'foo'}}]}")); assertNumSolutions(1U); @@ -241,10 +262,11 @@ TEST_F(QueryPlannerTest, TextInsideOrWithAnotherOr) { addIndex(BSON("a" << 1)); addIndex(BSON("_fts" << "text" - << "_ftsx" << 1)); - runQuery(fromjson( - "{$and: [{$or: [{a: 3}, {a: 4}]}, " - "{$or: [{$text: {$search: 'foo'}}, {a: 5}]}]}")); + << "_ftsx" + << 1)); + runQuery( + fromjson("{$and: [{$or: [{a: 3}, {a: 4}]}, " + "{$or: [{$text: {$search: 'foo'}}, {a: 5}]}]}")); assertNumSolutions(1U); assertSolutionExists( @@ -260,10 +282,11 @@ TEST_F(QueryPlannerTest, TextInsideOrOfAnd) { addIndex(BSON("a" << 1)); addIndex(BSON("_fts" << "text" - << "_ftsx" << 1)); - runQuery(fromjson( - "{$or: [{a: {$gt: 1, $gt: 2}}, " - "{a: {$gt: 3}, $text: {$search: 'foo'}}]}")); + << "_ftsx" + << 1)); + runQuery( + fromjson("{$or: [{a: {$gt: 1, $gt: 2}}, " + "{a: {$gt: 3}, $text: {$search: 'foo'}}]}")); assertNumSolutions(1U); assertSolutionExists( @@ -281,10 +304,11 @@ TEST_F(QueryPlannerTest, TextInsideAndOrAnd) { addIndex(BSON("b" << 1)); addIndex(BSON("_fts" << "text" - << "_ftsx" << 1)); - runQuery(fromjson( - "{a: 1, $or: [{a:2}, {b:2}, " - "{a: 1, $text: {$search: 'foo'}}]}")); + << "_ftsx" + << 1)); + runQuery( + fromjson("{a: 1, $or: [{a:2}, {b:2}, " + "{a: 1, $text: {$search: 'foo'}}]}")); assertNumSolutions(1U); assertSolutionExists( @@ -300,12 +324,13 @@ TEST_F(QueryPlannerTest, TextInsideAndOrAndOr) { addIndex(BSON("a" << 1)); addIndex(BSON("_fts" << "text" - << "_ftsx" << 1)); - runQuery(fromjson( - "{$or: [{a: {$gt: 1, $gt: 2}}, " - "{a: {$gt: 3}, $or: [{$text: {$search: 'foo'}}, " - "{a: 6}]}], " - "a: 5}")); + << "_ftsx" + << 1)); + runQuery( + fromjson("{$or: [{a: {$gt: 1, $gt: 2}}, " + "{a: {$gt: 3}, $or: [{$text: {$search: 'foo'}}, " + "{a: 6}]}], " + "a: 5}")); assertNumSolutions(1U); assertSolutionExists( @@ -323,7 +348,8 @@ TEST_F(QueryPlannerTest, TextInsideOrOneBranchNotIndexed) { addIndex(BSON("a" << 1)); addIndex(BSON("_fts" << "text" - << "_ftsx" << 1)); + << "_ftsx" + << 1)); runQuery(fromjson("{a: 1, $or: [{b: 2}, {$text: {$search: 'foo'}}]}")); assertNumSolutions(0); @@ -336,10 +362,11 @@ TEST_F(QueryPlannerTest, TextInsideOrWithAnotherUnindexableOr) { addIndex(BSON("a" << 1)); addIndex(BSON("_fts" << "text" - << "_ftsx" << 1)); - runQuery(fromjson( - "{$and: [{$or: [{a: 1}, {b: 1}]}, " - "{$or: [{a: 2}, {$text: {$search: 'foo'}}]}]}")); + << "_ftsx" + << 1)); + runQuery( + fromjson("{$and: [{$or: [{a: 1}, {b: 1}]}, " + "{$or: [{a: 2}, {$text: {$search: 'foo'}}]}]}")); assertNumSolutions(1U); assertSolutionExists( @@ -351,10 +378,11 @@ TEST_F(QueryPlannerTest, TextInsideOrWithAnotherUnindexableOr) { TEST_F(QueryPlannerTest, AndTextWithGeoNonNear) { addIndex(BSON("_fts" << "text" - << "_ftsx" << 1)); - runQuery(fromjson( - "{$text: {$search: 'foo'}, a: {$geoIntersects: {$geometry: " - "{type: 'Point', coordinates: [3.0, 1.0]}}}}")); + << "_ftsx" + << 1)); + runQuery( + fromjson("{$text: {$search: 'foo'}, a: {$geoIntersects: {$geometry: " + "{type: 'Point', coordinates: [3.0, 1.0]}}}}")); // Mandatory text index is used, and geo predicate becomes a filter. assertNumSolutions(1U); @@ -365,7 +393,8 @@ TEST_F(QueryPlannerTest, AndTextWithGeoNonNear) { TEST_F(QueryPlannerTest, OrTextExact) { addIndex(BSON("pre" << 1 << "_fts" << "text" - << "_ftsx" << 1)); + << "_ftsx" + << 1)); addIndex(BSON("other" << 1)); runQuery(fromjson("{$or: [{$text: {$search: 'dave'}, pre: 3}, {other: 2}]}")); @@ -380,7 +409,8 @@ TEST_F(QueryPlannerTest, OrTextExact) { TEST_F(QueryPlannerTest, OrTextInexactCovered) { addIndex(BSON("pre" << 1 << "_fts" << "text" - << "_ftsx" << 1)); + << "_ftsx" + << 1)); addIndex(BSON("other" << 1)); runQuery(fromjson("{$or: [{$text: {$search: 'dave'}, pre: 3}, {other: /bar/}]}")); @@ -395,7 +425,8 @@ TEST_F(QueryPlannerTest, OrTextInexactCovered) { TEST_F(QueryPlannerTest, TextCaseSensitive) { addIndex(BSON("_fts" << "text" - << "_ftsx" << 1)); + << "_ftsx" + << 1)); runQuery(fromjson("{$text: {$search: 'blah', $caseSensitive: true}}")); assertNumSolutions(1); @@ -405,7 +436,8 @@ TEST_F(QueryPlannerTest, TextCaseSensitive) { TEST_F(QueryPlannerTest, TextDiacriticSensitive) { addIndex(BSON("_fts" << "text" - << "_ftsx" << 1)); + << "_ftsx" + << 1)); runQuery(fromjson("{$text: {$search: 'blah', $diacriticSensitive: true}}")); assertNumSolutions(1); @@ -415,7 +447,8 @@ TEST_F(QueryPlannerTest, TextDiacriticSensitive) { TEST_F(QueryPlannerTest, SortKeyMetaProjectionWithTextScoreMetaSort) { addIndex(BSON("_fts" << "text" - << "_ftsx" << 1)); + << "_ftsx" + << 1)); runQuerySortProj(fromjson("{$text: {$search: 'foo'}}"), fromjson("{a: {$meta: 'textScore'}}"), diff --git a/src/mongo/db/query/query_solution.h b/src/mongo/db/query/query_solution.h index f64e5d263dc..0a63f8a10e0 100644 --- a/src/mongo/db/query/query_solution.h +++ b/src/mongo/db/query/query_solution.h @@ -30,9 +30,9 @@ #include <memory> +#include "mongo/db/fts/fts_query.h" #include "mongo/db/jsobj.h" #include "mongo/db/matcher/expression.h" -#include "mongo/db/fts/fts_query.h" #include "mongo/db/query/index_bounds.h" #include "mongo/db/query/plan_cache.h" #include "mongo/db/query/stage_types.h" diff --git a/src/mongo/db/query/query_solution_test.cpp b/src/mongo/db/query/query_solution_test.cpp index ac1b6abbac1..e5d01e4a091 100644 --- a/src/mongo/db/query/query_solution_test.cpp +++ b/src/mongo/db/query/query_solution_test.cpp @@ -259,8 +259,10 @@ std::unique_ptr<ParsedProjection> createParsedProjection(const BSONObj& query, Status status = ParsedProjection::make( projObj, queryMatchExpr.getValue().get(), &out, ExtensionsCallbackDisallowExtensions()); if (!status.isOK()) { - FAIL(mongoutils::str::stream() << "failed to parse projection " << projObj - << " (query: " << query << "): " << status.toString()); + FAIL(mongoutils::str::stream() << "failed to parse projection " << projObj << " (query: " + << query + << "): " + << status.toString()); } ASSERT(out); return std::unique_ptr<ParsedProjection>(out); diff --git a/src/mongo/db/query/stage_builder.cpp b/src/mongo/db/query/stage_builder.cpp index 74e5c58d4e7..2701dc420ec 100644 --- a/src/mongo/db/query/stage_builder.cpp +++ b/src/mongo/db/query/stage_builder.cpp @@ -32,6 +32,8 @@ #include "mongo/db/query/stage_builder.h" +#include "mongo/db/catalog/collection.h" +#include "mongo/db/catalog/database.h" #include "mongo/db/client.h" #include "mongo/db/exec/and_hash.h" #include "mongo/db/exec/and_sorted.h" @@ -48,14 +50,12 @@ #include "mongo/db/exec/or.h" #include "mongo/db/exec/projection.h" #include "mongo/db/exec/shard_filter.h" +#include "mongo/db/exec/skip.h" #include "mongo/db/exec/sort.h" #include "mongo/db/exec/sort_key_generator.h" -#include "mongo/db/exec/skip.h" #include "mongo/db/exec/text.h" #include "mongo/db/index/fts_access_method.h" #include "mongo/db/matcher/extensions_callback_real.h" -#include "mongo/db/catalog/collection.h" -#include "mongo/db/catalog/database.h" #include "mongo/db/s/sharding_state.h" #include "mongo/stdx/memory.h" #include "mongo/util/log.h" |