diff options
| author | J. Rassi <rassi@10gen.com> | 2016-06-06 11:49:23 -0400 |
|---|---|---|
| committer | J. Rassi <rassi@10gen.com> | 2016-06-06 16:50:55 -0400 |
| commit | c78f95141142e4d13c820a64aa26fe28d07ebb0c (patch) | |
| tree | b63ee4fceeaa689bb917467f4b647fe57f371e27 /src | |
| parent | 38ab06d09b2295d404c7e8d012a8491ed0a0ec1f (diff) | |
| download | mongo-c78f95141142e4d13c820a64aa26fe28d07ebb0c.tar.gz | |
SERVER-23611 Add ComparisonMatchExpression::setCollator() method
Also removes collator parameter from ComparisonMatchExpression
constructor.
Diffstat (limited to 'src')
| -rw-r--r-- | src/mongo/db/matcher/expression_algo.cpp | 3 | ||||
| -rw-r--r-- | src/mongo/db/matcher/expression_array_test.cpp | 63 | ||||
| -rw-r--r-- | src/mongo/db/matcher/expression_leaf.h | 52 | ||||
| -rw-r--r-- | src/mongo/db/matcher/expression_leaf_test.cpp | 187 | ||||
| -rw-r--r-- | src/mongo/db/matcher/expression_parser.cpp | 35 | ||||
| -rw-r--r-- | src/mongo/db/matcher/expression_parser.h | 4 | ||||
| -rw-r--r-- | src/mongo/db/matcher/expression_test.cpp | 15 | ||||
| -rw-r--r-- | src/mongo/db/matcher/expression_tree_test.cpp | 64 | ||||
| -rw-r--r-- | src/mongo/db/query/canonical_query.cpp | 3 |
9 files changed, 174 insertions, 252 deletions
diff --git a/src/mongo/db/matcher/expression_algo.cpp b/src/mongo/db/matcher/expression_algo.cpp index 1b130592597..ce7cfa70924 100644 --- a/src/mongo/db/matcher/expression_algo.cpp +++ b/src/mongo/db/matcher/expression_algo.cpp @@ -166,8 +166,9 @@ bool _isSubsetOf(const MatchExpression* lhs, const ComparisonMatchExpression* rh } for (BSONElement elem : ime->getEqualities()) { // Each element in the $in-array represents an equality predicate. - EqualityMatchExpression equality(ime->getCollator()); + EqualityMatchExpression equality; equality.init(lhs->path(), elem); + equality.setCollator(ime->getCollator()); if (!_isSubsetOf(&equality, rhs)) { return false; } diff --git a/src/mongo/db/matcher/expression_array_test.cpp b/src/mongo/db/matcher/expression_array_test.cpp index 8fbc971221b..201d11fbed4 100644 --- a/src/mongo/db/matcher/expression_array_test.cpp +++ b/src/mongo/db/matcher/expression_array_test.cpp @@ -44,8 +44,7 @@ TEST(ElemMatchObjectMatchExpression, MatchesElementSingle) { BSONObj baseOperand = BSON("b" << 5); BSONObj match = BSON("a" << BSON_ARRAY(BSON("b" << 5.0))); BSONObj notMatch = BSON("a" << BSON_ARRAY(BSON("b" << 6))); - const CollatorInterface* collator = nullptr; - unique_ptr<ComparisonMatchExpression> eq(new EqualityMatchExpression(collator)); + unique_ptr<ComparisonMatchExpression> eq(new EqualityMatchExpression()); ASSERT(eq->init("b", baseOperand["b"]).isOK()); ElemMatchObjectMatchExpression op; ASSERT(op.init("a", eq.release()).isOK()); @@ -57,8 +56,7 @@ TEST(ElemMatchObjectMatchExpression, MatchesElementArray) { BSONObj baseOperand = BSON("1" << 5); BSONObj match = BSON("a" << BSON_ARRAY(BSON_ARRAY('s' << 5.0))); BSONObj notMatch = BSON("a" << BSON_ARRAY(BSON_ARRAY(5 << 6))); - const CollatorInterface* collator = nullptr; - unique_ptr<ComparisonMatchExpression> eq(new EqualityMatchExpression(collator)); + unique_ptr<ComparisonMatchExpression> eq(new EqualityMatchExpression()); ASSERT(eq->init("1", baseOperand["1"]).isOK()); ElemMatchObjectMatchExpression op; ASSERT(op.init("a", eq.release()).isOK()); @@ -74,12 +72,11 @@ TEST(ElemMatchObjectMatchExpression, MatchesElementMultiple) { BSONObj notMatch2 = BSON("a" << BSON_ARRAY(BSON("b" << 6 << "c" << 7))); BSONObj notMatch3 = BSON("a" << BSON_ARRAY(BSON("b" << BSON_ARRAY(5 << 6)))); BSONObj match = BSON("a" << BSON_ARRAY(BSON("b" << BSON_ARRAY(5 << 6) << "c" << 7))); - const CollatorInterface* collator = nullptr; - unique_ptr<ComparisonMatchExpression> eq1(new EqualityMatchExpression(collator)); + unique_ptr<ComparisonMatchExpression> eq1(new EqualityMatchExpression()); ASSERT(eq1->init("b", baseOperand1["b"]).isOK()); - unique_ptr<ComparisonMatchExpression> eq2(new EqualityMatchExpression(collator)); + unique_ptr<ComparisonMatchExpression> eq2(new EqualityMatchExpression()); ASSERT(eq2->init("b", baseOperand2["b"]).isOK()); - unique_ptr<ComparisonMatchExpression> eq3(new EqualityMatchExpression(collator)); + unique_ptr<ComparisonMatchExpression> eq3(new EqualityMatchExpression()); ASSERT(eq3->init("c", baseOperand3["c"]).isOK()); unique_ptr<AndMatchExpression> andOp(new AndMatchExpression()); @@ -97,8 +94,7 @@ TEST(ElemMatchObjectMatchExpression, MatchesElementMultiple) { TEST(ElemMatchObjectMatchExpression, MatchesNonArray) { BSONObj baseOperand = BSON("b" << 5); - const CollatorInterface* collator = nullptr; - unique_ptr<ComparisonMatchExpression> eq(new EqualityMatchExpression(collator)); + unique_ptr<ComparisonMatchExpression> eq(new EqualityMatchExpression()); ASSERT(eq->init("b", baseOperand["b"]).isOK()); ElemMatchObjectMatchExpression op; ASSERT(op.init("a", eq.release()).isOK()); @@ -111,8 +107,7 @@ TEST(ElemMatchObjectMatchExpression, MatchesNonArray) { TEST(ElemMatchObjectMatchExpression, MatchesArrayObject) { BSONObj baseOperand = BSON("b" << 5); - const CollatorInterface* collator = nullptr; - unique_ptr<ComparisonMatchExpression> eq(new EqualityMatchExpression(collator)); + unique_ptr<ComparisonMatchExpression> eq(new EqualityMatchExpression()); ASSERT(eq->init("b", baseOperand["b"]).isOK()); ElemMatchObjectMatchExpression op; ASSERT(op.init("a", eq.release()).isOK()); @@ -124,8 +119,7 @@ TEST(ElemMatchObjectMatchExpression, MatchesArrayObject) { TEST(ElemMatchObjectMatchExpression, MatchesMultipleNamedValues) { BSONObj baseOperand = BSON("c" << 5); - const CollatorInterface* collator = nullptr; - unique_ptr<ComparisonMatchExpression> eq(new EqualityMatchExpression(collator)); + unique_ptr<ComparisonMatchExpression> eq(new EqualityMatchExpression()); ASSERT(eq->init("c", baseOperand["c"]).isOK()); ElemMatchObjectMatchExpression op; ASSERT(op.init("a.b", eq.release()).isOK()); @@ -137,8 +131,7 @@ TEST(ElemMatchObjectMatchExpression, MatchesMultipleNamedValues) { TEST(ElemMatchObjectMatchExpression, ElemMatchKey) { BSONObj baseOperand = BSON("c" << 6); - const CollatorInterface* collator = nullptr; - unique_ptr<ComparisonMatchExpression> eq(new EqualityMatchExpression(collator)); + unique_ptr<ComparisonMatchExpression> eq(new EqualityMatchExpression()); ASSERT(eq->init("c", baseOperand["c"]).isOK()); ElemMatchObjectMatchExpression op; ASSERT(op.init("a.b", eq.release()).isOK()); @@ -178,8 +171,7 @@ TEST(ElemMatchValueMatchExpression, MatchesElementSingle) { BSONObj baseOperand = BSON("$gt" << 5); BSONObj match = BSON("a" << BSON_ARRAY(6)); BSONObj notMatch = BSON("a" << BSON_ARRAY(4)); - const CollatorInterface* collator = nullptr; - unique_ptr<ComparisonMatchExpression> gt(new GTMatchExpression(collator)); + unique_ptr<ComparisonMatchExpression> gt(new GTMatchExpression()); ASSERT(gt->init("", baseOperand["$gt"]).isOK()); ElemMatchValueMatchExpression op; ASSERT(op.init("a", gt.release()).isOK()); @@ -193,10 +185,9 @@ TEST(ElemMatchValueMatchExpression, MatchesElementMultiple) { BSONObj notMatch1 = BSON("a" << BSON_ARRAY(0 << 1)); BSONObj notMatch2 = BSON("a" << BSON_ARRAY(10 << 11)); BSONObj match = BSON("a" << BSON_ARRAY(0 << 5 << 11)); - const CollatorInterface* collator = nullptr; - unique_ptr<ComparisonMatchExpression> gt(new GTMatchExpression(collator)); + unique_ptr<ComparisonMatchExpression> gt(new GTMatchExpression()); ASSERT(gt->init("", baseOperand1["$gt"]).isOK()); - unique_ptr<ComparisonMatchExpression> lt(new LTMatchExpression(collator)); + unique_ptr<ComparisonMatchExpression> lt(new LTMatchExpression()); ASSERT(lt->init("", baseOperand2["$lt"]).isOK()); ElemMatchValueMatchExpression op; @@ -211,8 +202,7 @@ TEST(ElemMatchValueMatchExpression, MatchesElementMultiple) { TEST(ElemMatchValueMatchExpression, MatchesNonArray) { BSONObj baseOperand = BSON("$gt" << 5); - const CollatorInterface* collator = nullptr; - unique_ptr<ComparisonMatchExpression> gt(new GTMatchExpression(collator)); + unique_ptr<ComparisonMatchExpression> gt(new GTMatchExpression()); ASSERT(gt->init("", baseOperand["$gt"]).isOK()); ElemMatchObjectMatchExpression op; ASSERT(op.init("a", gt.release()).isOK()); @@ -224,8 +214,7 @@ TEST(ElemMatchValueMatchExpression, MatchesNonArray) { TEST(ElemMatchValueMatchExpression, MatchesArrayScalar) { BSONObj baseOperand = BSON("$gt" << 5); - const CollatorInterface* collator = nullptr; - unique_ptr<ComparisonMatchExpression> gt(new GTMatchExpression(collator)); + unique_ptr<ComparisonMatchExpression> gt(new GTMatchExpression()); ASSERT(gt->init("", baseOperand["$gt"]).isOK()); ElemMatchValueMatchExpression op; ASSERT(op.init("a", gt.release()).isOK()); @@ -236,8 +225,7 @@ TEST(ElemMatchValueMatchExpression, MatchesArrayScalar) { TEST(ElemMatchValueMatchExpression, MatchesMultipleNamedValues) { BSONObj baseOperand = BSON("$gt" << 5); - const CollatorInterface* collator = nullptr; - unique_ptr<ComparisonMatchExpression> gt(new GTMatchExpression(collator)); + unique_ptr<ComparisonMatchExpression> gt(new GTMatchExpression()); ASSERT(gt->init("", baseOperand["$gt"]).isOK()); ElemMatchValueMatchExpression op; ASSERT(op.init("a.b", gt.release()).isOK()); @@ -249,8 +237,7 @@ TEST(ElemMatchValueMatchExpression, MatchesMultipleNamedValues) { TEST(ElemMatchValueMatchExpression, ElemMatchKey) { BSONObj baseOperand = BSON("$gt" << 6); - const CollatorInterface* collator = nullptr; - unique_ptr<ComparisonMatchExpression> gt(new GTMatchExpression(collator)); + unique_ptr<ComparisonMatchExpression> gt(new GTMatchExpression()); ASSERT(gt->init("", baseOperand["$gt"]).isOK()); ElemMatchValueMatchExpression op; ASSERT(op.init("a.b", gt.release()).isOK()); @@ -287,12 +274,11 @@ TEST( ElemMatchValueMatchExpression, MatchesIndexKey ) { TEST(AndOfElemMatch, MatchesElement) { BSONObj baseOperanda1 = BSON("a" << 1); - const CollatorInterface* collator = nullptr; - unique_ptr<ComparisonMatchExpression> eqa1(new EqualityMatchExpression(collator)); + unique_ptr<ComparisonMatchExpression> eqa1(new EqualityMatchExpression()); ASSERT(eqa1->init("a", baseOperanda1["a"]).isOK()); BSONObj baseOperandb1 = BSON("b" << 1); - unique_ptr<ComparisonMatchExpression> eqb1(new EqualityMatchExpression(collator)); + unique_ptr<ComparisonMatchExpression> eqb1(new EqualityMatchExpression()); ASSERT(eqb1->init("b", baseOperandb1["b"]).isOK()); unique_ptr<AndMatchExpression> and1(new AndMatchExpression()); @@ -305,11 +291,11 @@ TEST(AndOfElemMatch, MatchesElement) { // elemMatch1 = { x : { $elemMatch : { a : 1, b : 1 } } } BSONObj baseOperanda2 = BSON("a" << 2); - unique_ptr<ComparisonMatchExpression> eqa2(new EqualityMatchExpression(collator)); + unique_ptr<ComparisonMatchExpression> eqa2(new EqualityMatchExpression()); ASSERT(eqa2->init("a", baseOperanda2["a"]).isOK()); BSONObj baseOperandb2 = BSON("b" << 2); - unique_ptr<ComparisonMatchExpression> eqb2(new EqualityMatchExpression(collator)); + unique_ptr<ComparisonMatchExpression> eqb2(new EqualityMatchExpression()); ASSERT(eqb2->init("b", baseOperandb2["b"]).isOK()); unique_ptr<AndMatchExpression> and2(new AndMatchExpression()); @@ -345,12 +331,11 @@ TEST(AndOfElemMatch, MatchesElement) { TEST(AndOfElemMatch, Matches) { BSONObj baseOperandgt1 = BSON("$gt" << 1); - const CollatorInterface* collator = nullptr; - unique_ptr<ComparisonMatchExpression> gt1(new GTMatchExpression(collator)); + unique_ptr<ComparisonMatchExpression> gt1(new GTMatchExpression()); ASSERT(gt1->init("", baseOperandgt1["$gt"]).isOK()); BSONObj baseOperandlt1 = BSON("$lt" << 10); - unique_ptr<ComparisonMatchExpression> lt1(new LTMatchExpression(collator)); + unique_ptr<ComparisonMatchExpression> lt1(new LTMatchExpression()); ASSERT(lt1->init("", baseOperandlt1["$lt"]).isOK()); unique_ptr<ElemMatchValueMatchExpression> elemMatch1(new ElemMatchValueMatchExpression()); @@ -360,11 +345,11 @@ TEST(AndOfElemMatch, Matches) { // elemMatch1 = { x : { $elemMatch : { $gt : 1 , $lt : 10 } } } BSONObj baseOperandgt2 = BSON("$gt" << 101); - unique_ptr<ComparisonMatchExpression> gt2(new GTMatchExpression(collator)); + unique_ptr<ComparisonMatchExpression> gt2(new GTMatchExpression()); ASSERT(gt2->init("", baseOperandgt2["$gt"]).isOK()); BSONObj baseOperandlt2 = BSON("$lt" << 110); - unique_ptr<ComparisonMatchExpression> lt2(new LTMatchExpression(collator)); + unique_ptr<ComparisonMatchExpression> lt2(new LTMatchExpression()); ASSERT(lt2->init("", baseOperandlt2["$lt"]).isOK()); unique_ptr<ElemMatchValueMatchExpression> elemMatch2(new ElemMatchValueMatchExpression()); diff --git a/src/mongo/db/matcher/expression_leaf.h b/src/mongo/db/matcher/expression_leaf.h index bb7b1f54c2f..c3569930252 100644 --- a/src/mongo/db/matcher/expression_leaf.h +++ b/src/mongo/db/matcher/expression_leaf.h @@ -84,11 +84,7 @@ private: */ class ComparisonMatchExpression : public LeafMatchExpression { public: - /** - * 'collator' must outlive the ComparisonMatchExpression and any clones made of it. - */ - ComparisonMatchExpression(MatchType type, const CollatorInterface* collator) - : LeafMatchExpression(type), _collator(collator) {} + ComparisonMatchExpression(MatchType type) : LeafMatchExpression(type) {} Status init(StringData path, const BSONElement& rhs); @@ -102,6 +98,13 @@ public: virtual void debugString(StringBuilder& debug, int level = 0) const; + /** + * 'collator' must outlive the ComparisonMatchExpression and any clones made of it. + */ + void setCollator(const CollatorInterface* collator) { + _collator = collator; + } + virtual void serialize(BSONObjBuilder* out) const; virtual bool equivalent(const MatchExpression* other) const; @@ -116,7 +119,9 @@ public: protected: BSONElement _rhs; - const CollatorInterface* _collator; + + // Collator used to compare elements. By default, simple binary comparison will be used. + const CollatorInterface* _collator = nullptr; }; // @@ -125,75 +130,70 @@ protected: class EqualityMatchExpression : public ComparisonMatchExpression { public: - EqualityMatchExpression(const CollatorInterface* collator) - : ComparisonMatchExpression(EQ, collator) {} + EqualityMatchExpression() : ComparisonMatchExpression(EQ) {} virtual std::unique_ptr<MatchExpression> shallowClone() const { - std::unique_ptr<ComparisonMatchExpression> e = - stdx::make_unique<EqualityMatchExpression>(_collator); + std::unique_ptr<ComparisonMatchExpression> e = stdx::make_unique<EqualityMatchExpression>(); e->init(path(), _rhs); if (getTag()) { e->setTag(getTag()->clone()); } + e->setCollator(_collator); return std::move(e); } }; class LTEMatchExpression : public ComparisonMatchExpression { public: - LTEMatchExpression(const CollatorInterface* collator) - : ComparisonMatchExpression(LTE, collator) {} + LTEMatchExpression() : ComparisonMatchExpression(LTE) {} virtual std::unique_ptr<MatchExpression> shallowClone() const { - std::unique_ptr<ComparisonMatchExpression> e = - stdx::make_unique<LTEMatchExpression>(_collator); + std::unique_ptr<ComparisonMatchExpression> e = stdx::make_unique<LTEMatchExpression>(); e->init(path(), _rhs); if (getTag()) { e->setTag(getTag()->clone()); } + e->setCollator(_collator); return std::move(e); } }; class LTMatchExpression : public ComparisonMatchExpression { public: - LTMatchExpression(const CollatorInterface* collator) - : ComparisonMatchExpression(LT, collator) {} + LTMatchExpression() : ComparisonMatchExpression(LT) {} virtual std::unique_ptr<MatchExpression> shallowClone() const { - std::unique_ptr<ComparisonMatchExpression> e = - stdx::make_unique<LTMatchExpression>(_collator); + std::unique_ptr<ComparisonMatchExpression> e = stdx::make_unique<LTMatchExpression>(); e->init(path(), _rhs); if (getTag()) { e->setTag(getTag()->clone()); } + e->setCollator(_collator); return std::move(e); } }; class GTMatchExpression : public ComparisonMatchExpression { public: - GTMatchExpression(const CollatorInterface* collator) - : ComparisonMatchExpression(GT, collator) {} + GTMatchExpression() : ComparisonMatchExpression(GT) {} virtual std::unique_ptr<MatchExpression> shallowClone() const { - std::unique_ptr<ComparisonMatchExpression> e = - stdx::make_unique<GTMatchExpression>(_collator); + std::unique_ptr<ComparisonMatchExpression> e = stdx::make_unique<GTMatchExpression>(); e->init(path(), _rhs); if (getTag()) { e->setTag(getTag()->clone()); } + e->setCollator(_collator); return std::move(e); } }; class GTEMatchExpression : public ComparisonMatchExpression { public: - GTEMatchExpression(const CollatorInterface* collator) - : ComparisonMatchExpression(GTE, collator) {} + GTEMatchExpression() : ComparisonMatchExpression(GTE) {} virtual std::unique_ptr<MatchExpression> shallowClone() const { - std::unique_ptr<ComparisonMatchExpression> e = - stdx::make_unique<GTEMatchExpression>(_collator); + std::unique_ptr<ComparisonMatchExpression> e = stdx::make_unique<GTEMatchExpression>(); e->init(path(), _rhs); if (getTag()) { e->setTag(getTag()->clone()); } + e->setCollator(_collator); return std::move(e); } }; diff --git a/src/mongo/db/matcher/expression_leaf_test.cpp b/src/mongo/db/matcher/expression_leaf_test.cpp index 5abec471bcb..fb90768e238 100644 --- a/src/mongo/db/matcher/expression_leaf_test.cpp +++ b/src/mongo/db/matcher/expression_leaf_test.cpp @@ -43,25 +43,28 @@ using std::string; TEST(ComparisonMatchExpression, ComparisonMatchExpressionsWithUnequalCollatorsAreUnequal) { CollatorInterfaceMock collator1(CollatorInterfaceMock::MockType::kReverseString); - EqualityMatchExpression eq1(&collator1); + EqualityMatchExpression eq1; + eq1.setCollator(&collator1); CollatorInterfaceMock collator2(CollatorInterfaceMock::MockType::kAlwaysEqual); - EqualityMatchExpression eq2(&collator2); + EqualityMatchExpression eq2; + eq2.setCollator(&collator2); ASSERT(!eq1.equivalent(&eq2)); } TEST(ComparisonMatchExpression, ComparisonMatchExpressionsWithEqualCollatorsAreEqual) { CollatorInterfaceMock collator1(CollatorInterfaceMock::MockType::kAlwaysEqual); - EqualityMatchExpression eq1(&collator1); + EqualityMatchExpression eq1; + eq1.setCollator(&collator1); CollatorInterfaceMock collator2(CollatorInterfaceMock::MockType::kAlwaysEqual); - EqualityMatchExpression eq2(&collator2); + EqualityMatchExpression eq2; + eq2.setCollator(&collator2); ASSERT(eq1.equivalent(&eq2)); } TEST(ComparisonMatchExpression, StringMatchingWithNullCollatorUsesBinaryComparison) { BSONObj operand = BSON("a" << "string"); - const CollatorInterface* collator = nullptr; - EqualityMatchExpression eq(collator); + EqualityMatchExpression eq; ASSERT(eq.init("a", operand["a"]).isOK()); ASSERT(!eq.matchesBSON(BSON("a" << "string2"), @@ -72,7 +75,8 @@ TEST(ComparisonMatchExpression, StringMatchingRespectsCollation) { BSONObj operand = BSON("a" << "string"); CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual); - EqualityMatchExpression eq(&collator); + EqualityMatchExpression eq; + eq.setCollator(&collator); ASSERT(eq.init("a", operand["a"]).isOK()); ASSERT(eq.matchesBSON(BSON("a" << "string2"), @@ -84,8 +88,7 @@ TEST(EqOp, MatchesElement) { BSONObj match = BSON("a" << 5.0); BSONObj notMatch = BSON("a" << 6); - const CollatorInterface* collator = nullptr; - EqualityMatchExpression eq(collator); + EqualityMatchExpression eq; eq.init("", operand["a"]); ASSERT(eq.matchesSingleElement(match.firstElement())); ASSERT(!eq.matchesSingleElement(notMatch.firstElement())); @@ -95,15 +98,13 @@ TEST(EqOp, MatchesElement) { TEST(EqOp, InvalidEooOperand) { BSONObj operand; - const CollatorInterface* collator = nullptr; - EqualityMatchExpression eq(collator); + EqualityMatchExpression eq; ASSERT(!eq.init("", operand.firstElement()).isOK()); } TEST(EqOp, MatchesScalar) { BSONObj operand = BSON("a" << 5); - const CollatorInterface* collator = nullptr; - EqualityMatchExpression eq(collator); + EqualityMatchExpression eq; eq.init("a", operand["a"]); ASSERT(eq.matchesBSON(BSON("a" << 5.0), NULL)); ASSERT(!eq.matchesBSON(BSON("a" << 4), NULL)); @@ -111,8 +112,7 @@ TEST(EqOp, MatchesScalar) { TEST(EqOp, MatchesArrayValue) { BSONObj operand = BSON("a" << 5); - const CollatorInterface* collator = nullptr; - EqualityMatchExpression eq(collator); + EqualityMatchExpression eq; eq.init("a", operand["a"]); ASSERT(eq.matchesBSON(BSON("a" << BSON_ARRAY(5.0 << 6)), NULL)); ASSERT(!eq.matchesBSON(BSON("a" << BSON_ARRAY(6 << 7)), NULL)); @@ -120,8 +120,7 @@ TEST(EqOp, MatchesArrayValue) { TEST(EqOp, MatchesReferencedObjectValue) { BSONObj operand = BSON("a.b" << 5); - const CollatorInterface* collator = nullptr; - EqualityMatchExpression eq(collator); + EqualityMatchExpression eq; eq.init("a.b", operand["a.b"]); ASSERT(eq.matchesBSON(BSON("a" << BSON("b" << 5)), NULL)); ASSERT(eq.matchesBSON(BSON("a" << BSON("b" << BSON_ARRAY(5))), NULL)); @@ -130,8 +129,7 @@ TEST(EqOp, MatchesReferencedObjectValue) { TEST(EqOp, MatchesReferencedArrayValue) { BSONObj operand = BSON("a.0" << 5); - const CollatorInterface* collator = nullptr; - EqualityMatchExpression eq(collator); + EqualityMatchExpression eq; eq.init("a.0", operand["a.0"]); ASSERT(eq.matchesBSON(BSON("a" << BSON_ARRAY(5)), NULL)); ASSERT(!eq.matchesBSON(BSON("a" << BSON_ARRAY(BSON_ARRAY(5))), NULL)); @@ -139,8 +137,7 @@ TEST(EqOp, MatchesReferencedArrayValue) { TEST(EqOp, MatchesNull) { BSONObj operand = BSON("a" << BSONNULL); - const CollatorInterface* collator = nullptr; - EqualityMatchExpression eq(collator); + EqualityMatchExpression eq; eq.init("a", operand["a"]); ASSERT(eq.matchesBSON(BSONObj(), NULL)); ASSERT(eq.matchesBSON(BSON("a" << BSONNULL), NULL)); @@ -153,8 +150,7 @@ TEST(EqOp, MatchesNull) { // not necessarily how it should work ideally. TEST(EqOp, MatchesNestedNull) { BSONObj operand = BSON("a.b" << BSONNULL); - const CollatorInterface* collator = nullptr; - EqualityMatchExpression eq(collator); + EqualityMatchExpression eq; eq.init("a.b", operand["a.b"]); // null matches any empty object that is on a subpath of a.b ASSERT(eq.matchesBSON(BSONObj(), NULL)); @@ -174,8 +170,7 @@ TEST(EqOp, MatchesNestedNull) { TEST(EqOp, MatchesMinKey) { BSONObj operand = BSON("a" << MinKey); - const CollatorInterface* collator = nullptr; - EqualityMatchExpression eq(collator); + EqualityMatchExpression eq; eq.init("a", operand["a"]); ASSERT(eq.matchesBSON(BSON("a" << MinKey), NULL)); ASSERT(!eq.matchesBSON(BSON("a" << MaxKey), NULL)); @@ -185,8 +180,7 @@ TEST(EqOp, MatchesMinKey) { TEST(EqOp, MatchesMaxKey) { BSONObj operand = BSON("a" << MaxKey); - const CollatorInterface* collator = nullptr; - EqualityMatchExpression eq(collator); + EqualityMatchExpression eq; ASSERT(eq.init("a", operand["a"]).isOK()); ASSERT(eq.matchesBSON(BSON("a" << MaxKey), NULL)); ASSERT(!eq.matchesBSON(BSON("a" << MinKey), NULL)); @@ -195,8 +189,7 @@ TEST(EqOp, MatchesMaxKey) { TEST(EqOp, MatchesFullArray) { BSONObj operand = BSON("a" << BSON_ARRAY(1 << 2)); - const CollatorInterface* collator = nullptr; - EqualityMatchExpression eq(collator); + EqualityMatchExpression eq; ASSERT(eq.init("a", operand["a"]).isOK()); ASSERT(eq.matchesBSON(BSON("a" << BSON_ARRAY(1 << 2)), NULL)); ASSERT(!eq.matchesBSON(BSON("a" << BSON_ARRAY(1 << 2 << 3)), NULL)); @@ -206,8 +199,7 @@ TEST(EqOp, MatchesFullArray) { TEST(EqOp, MatchesThroughNestedArray) { BSONObj operand = BSON("a.b.c.d" << 3); - const CollatorInterface* collator = nullptr; - EqualityMatchExpression eq(collator); + EqualityMatchExpression eq; eq.init("a.b.c.d", operand["a.b.c.d"]); BSONObj obj = fromjson("{a:{b:[{c:[{d:1},{d:2}]},{c:[{d:3}]}]}}"); ASSERT(eq.matchesBSON(obj, NULL)); @@ -215,8 +207,7 @@ TEST(EqOp, MatchesThroughNestedArray) { TEST(EqOp, ElemMatchKey) { BSONObj operand = BSON("a" << 5); - const CollatorInterface* collator = nullptr; - EqualityMatchExpression eq(collator); + EqualityMatchExpression eq; ASSERT(eq.init("a", operand["a"]).isOK()); MatchDetails details; details.requestElemMatchKey(); @@ -235,8 +226,7 @@ TEST(EqOp, ElemMatchKey) { TEST(EqOp, ElemMatchKeyWithImplicitAndExplicitTraversal) { BSONObj operand = BSON("a.0.b" << 3); BSONElement operandFirstElt = operand.firstElement(); - const CollatorInterface* collator = nullptr; - EqualityMatchExpression eq(collator); + EqualityMatchExpression eq; ASSERT(eq.init(operandFirstElt.fieldName(), operandFirstElt).isOK()); MatchDetails details; details.requestElemMatchKey(); @@ -247,10 +237,9 @@ TEST(EqOp, ElemMatchKeyWithImplicitAndExplicitTraversal) { } TEST(EqOp, Equality1) { - const CollatorInterface* collator = nullptr; - EqualityMatchExpression eq1(collator); - EqualityMatchExpression eq2(collator); - EqualityMatchExpression eq3(collator); + EqualityMatchExpression eq1; + EqualityMatchExpression eq2; + EqualityMatchExpression eq3; BSONObj operand = BSON("a" << 5 << "b" << 5 << "c" << 4); @@ -320,8 +309,7 @@ TEST(LtOp, MatchesElement) { BSONObj notMatchEqual = BSON("a" << 5); BSONObj notMatchWrongType = BSON("a" << "foo"); - const CollatorInterface* collator = nullptr; - LTMatchExpression lt(collator); + LTMatchExpression lt; ASSERT(lt.init("", operand["$lt"]).isOK()); ASSERT(lt.matchesSingleElement(match.firstElement())); ASSERT(!lt.matchesSingleElement(notMatch.firstElement())); @@ -331,15 +319,13 @@ TEST(LtOp, MatchesElement) { TEST(LtOp, InvalidEooOperand) { BSONObj operand; - const CollatorInterface* collator = nullptr; - LTMatchExpression lt(collator); + LTMatchExpression lt; ASSERT(!lt.init("", operand.firstElement()).isOK()); } TEST(LtOp, MatchesScalar) { BSONObj operand = BSON("$lt" << 5); - const CollatorInterface* collator = nullptr; - LTMatchExpression lt(collator); + LTMatchExpression lt; ASSERT(lt.init("a", operand["$lt"]).isOK()); ASSERT(lt.matchesBSON(BSON("a" << 4.5), NULL)); ASSERT(!lt.matchesBSON(BSON("a" << 6), NULL)); @@ -347,8 +333,7 @@ TEST(LtOp, MatchesScalar) { TEST(LtOp, MatchesScalarEmptyKey) { BSONObj operand = BSON("$lt" << 5); - const CollatorInterface* collator = nullptr; - LTMatchExpression lt(collator); + LTMatchExpression lt; ASSERT(lt.init("", operand["$lt"]).isOK()); ASSERT(lt.matchesBSON(BSON("" << 4.5), NULL)); ASSERT(!lt.matchesBSON(BSON("" << 6), NULL)); @@ -356,8 +341,7 @@ TEST(LtOp, MatchesScalarEmptyKey) { TEST(LtOp, MatchesArrayValue) { BSONObj operand = BSON("$lt" << 5); - const CollatorInterface* collator = nullptr; - LTMatchExpression lt(collator); + LTMatchExpression lt; ASSERT(lt.init("a", operand["$lt"]).isOK()); ASSERT(lt.matchesBSON(BSON("a" << BSON_ARRAY(6 << 4.5)), NULL)); ASSERT(!lt.matchesBSON(BSON("a" << BSON_ARRAY(6 << 7)), NULL)); @@ -365,8 +349,7 @@ TEST(LtOp, MatchesArrayValue) { TEST(LtOp, MatchesWholeArray) { BSONObj operand = BSON("$lt" << BSON_ARRAY(5)); - const CollatorInterface* collator = nullptr; - LTMatchExpression lt(collator); + LTMatchExpression lt; ASSERT(lt.init("a", operand["$lt"]).isOK()); ASSERT(lt.matchesBSON(BSON("a" << BSON_ARRAY(4)), NULL)); ASSERT(!lt.matchesBSON(BSON("a" << BSON_ARRAY(5)), NULL)); @@ -379,8 +362,7 @@ TEST(LtOp, MatchesWholeArray) { TEST(LtOp, MatchesNull) { BSONObj operand = BSON("$lt" << BSONNULL); - const CollatorInterface* collator = nullptr; - LTMatchExpression lt(collator); + LTMatchExpression lt; ASSERT(lt.init("a", operand["$lt"]).isOK()); ASSERT(!lt.matchesBSON(BSONObj(), NULL)); ASSERT(!lt.matchesBSON(BSON("a" << BSONNULL), NULL)); @@ -391,8 +373,7 @@ TEST(LtOp, MatchesNull) { TEST(LtOp, MatchesDotNotationNull) { BSONObj operand = BSON("$lt" << BSONNULL); - const CollatorInterface* collator = nullptr; - LTMatchExpression lt(collator); + LTMatchExpression lt; ASSERT(lt.init("a.b", operand["$lt"]).isOK()); ASSERT(!lt.matchesBSON(BSONObj(), NULL)); ASSERT(!lt.matchesBSON(BSON("a" << BSONNULL), NULL)); @@ -406,8 +387,7 @@ TEST(LtOp, MatchesDotNotationNull) { TEST(LtOp, MatchesMinKey) { BSONObj operand = BSON("a" << MinKey); - const CollatorInterface* collator = nullptr; - LTMatchExpression lt(collator); + LTMatchExpression lt; ASSERT(lt.init("a", operand["a"]).isOK()); ASSERT(!lt.matchesBSON(BSON("a" << MinKey), NULL)); ASSERT(!lt.matchesBSON(BSON("a" << MaxKey), NULL)); @@ -416,8 +396,7 @@ TEST(LtOp, MatchesMinKey) { TEST(LtOp, MatchesMaxKey) { BSONObj operand = BSON("a" << MaxKey); - const CollatorInterface* collator = nullptr; - LTMatchExpression lt(collator); + LTMatchExpression lt; ASSERT(lt.init("a", operand["a"]).isOK()); ASSERT(!lt.matchesBSON(BSON("a" << MaxKey), NULL)); ASSERT(lt.matchesBSON(BSON("a" << MinKey), NULL)); @@ -426,8 +405,7 @@ TEST(LtOp, MatchesMaxKey) { TEST(LtOp, ElemMatchKey) { BSONObj operand = BSON("$lt" << 5); - const CollatorInterface* collator = nullptr; - LTMatchExpression lt(collator); + LTMatchExpression lt; ASSERT(lt.init("a", operand["$lt"]).isOK()); MatchDetails details; details.requestElemMatchKey(); @@ -497,8 +475,7 @@ TEST(LteOp, MatchesElement) { BSONObj notMatch = BSON("a" << 6); BSONObj notMatchWrongType = BSON("a" << "foo"); - const CollatorInterface* collator = nullptr; - LTEMatchExpression lte(collator); + LTEMatchExpression lte; ASSERT(lte.init("", operand["$lte"]).isOK()); ASSERT(lte.matchesSingleElement(match.firstElement())); ASSERT(lte.matchesSingleElement(equalMatch.firstElement())); @@ -508,15 +485,13 @@ TEST(LteOp, MatchesElement) { TEST(LteOp, InvalidEooOperand) { BSONObj operand; - const CollatorInterface* collator = nullptr; - LTEMatchExpression lte(collator); + LTEMatchExpression lte; ASSERT(!lte.init("", operand.firstElement()).isOK()); } TEST(LteOp, MatchesScalar) { BSONObj operand = BSON("$lte" << 5); - const CollatorInterface* collator = nullptr; - LTEMatchExpression lte(collator); + LTEMatchExpression lte; ASSERT(lte.init("a", operand["$lte"]).isOK()); ASSERT(lte.matchesBSON(BSON("a" << 4.5), NULL)); ASSERT(!lte.matchesBSON(BSON("a" << 6), NULL)); @@ -524,8 +499,7 @@ TEST(LteOp, MatchesScalar) { TEST(LteOp, MatchesArrayValue) { BSONObj operand = BSON("$lte" << 5); - const CollatorInterface* collator = nullptr; - LTEMatchExpression lte(collator); + LTEMatchExpression lte; ASSERT(lte.init("a", operand["$lte"]).isOK()); ASSERT(lte.matchesBSON(BSON("a" << BSON_ARRAY(6 << 4.5)), NULL)); ASSERT(!lte.matchesBSON(BSON("a" << BSON_ARRAY(6 << 7)), NULL)); @@ -533,8 +507,7 @@ TEST(LteOp, MatchesArrayValue) { TEST(LteOp, MatchesWholeArray) { BSONObj operand = BSON("$lte" << BSON_ARRAY(5)); - const CollatorInterface* collator = nullptr; - LTEMatchExpression lte(collator); + LTEMatchExpression lte; ASSERT(lte.init("a", operand["$lte"]).isOK()); ASSERT(lte.matchesBSON(BSON("a" << BSON_ARRAY(4)), NULL)); ASSERT(lte.matchesBSON(BSON("a" << BSON_ARRAY(5)), NULL)); @@ -547,8 +520,7 @@ TEST(LteOp, MatchesWholeArray) { TEST(LteOp, MatchesNull) { BSONObj operand = BSON("$lte" << BSONNULL); - const CollatorInterface* collator = nullptr; - LTEMatchExpression lte(collator); + LTEMatchExpression lte; ASSERT(lte.init("a", operand["$lte"]).isOK()); ASSERT(lte.matchesBSON(BSONObj(), NULL)); ASSERT(lte.matchesBSON(BSON("a" << BSONNULL), NULL)); @@ -559,8 +531,7 @@ TEST(LteOp, MatchesNull) { TEST(LteOp, MatchesDotNotationNull) { BSONObj operand = BSON("$lte" << BSONNULL); - const CollatorInterface* collator = nullptr; - LTEMatchExpression lte(collator); + LTEMatchExpression lte; ASSERT(lte.init("a.b", operand["$lte"]).isOK()); ASSERT(lte.matchesBSON(BSONObj(), NULL)); ASSERT(lte.matchesBSON(BSON("a" << BSONNULL), NULL)); @@ -574,8 +545,7 @@ TEST(LteOp, MatchesDotNotationNull) { TEST(LteOp, MatchesMinKey) { BSONObj operand = BSON("a" << MinKey); - const CollatorInterface* collator = nullptr; - LTEMatchExpression lte(collator); + LTEMatchExpression lte; ASSERT(lte.init("a", operand["a"]).isOK()); ASSERT(lte.matchesBSON(BSON("a" << MinKey), NULL)); ASSERT(!lte.matchesBSON(BSON("a" << MaxKey), NULL)); @@ -584,8 +554,7 @@ TEST(LteOp, MatchesMinKey) { TEST(LteOp, MatchesMaxKey) { BSONObj operand = BSON("a" << MaxKey); - const CollatorInterface* collator = nullptr; - LTEMatchExpression lte(collator); + LTEMatchExpression lte; ASSERT(lte.init("a", operand["a"]).isOK()); ASSERT(lte.matchesBSON(BSON("a" << MaxKey), NULL)); ASSERT(lte.matchesBSON(BSON("a" << MinKey), NULL)); @@ -595,8 +564,7 @@ TEST(LteOp, MatchesMaxKey) { TEST(LteOp, ElemMatchKey) { BSONObj operand = BSON("$lte" << 5); - const CollatorInterface* collator = nullptr; - LTEMatchExpression lte(collator); + LTEMatchExpression lte; ASSERT(lte.init("a", operand["$lte"]).isOK()); MatchDetails details; details.requestElemMatchKey(); @@ -676,15 +644,13 @@ TEST(LteOp, ElemMatchKey) { TEST(GtOp, InvalidEooOperand) { BSONObj operand; - const CollatorInterface* collator = nullptr; - GTMatchExpression gt(collator); + GTMatchExpression gt; ASSERT(!gt.init("", operand.firstElement()).isOK()); } TEST(GtOp, MatchesScalar) { BSONObj operand = BSON("$gt" << 5); - const CollatorInterface* collator = nullptr; - GTMatchExpression gt(collator); + GTMatchExpression gt; ASSERT(gt.init("a", operand["$gt"]).isOK()); ASSERT(gt.matchesBSON(BSON("a" << 5.5), NULL)); ASSERT(!gt.matchesBSON(BSON("a" << 4), NULL)); @@ -692,8 +658,7 @@ TEST(GtOp, MatchesScalar) { TEST(GtOp, MatchesArrayValue) { BSONObj operand = BSON("$gt" << 5); - const CollatorInterface* collator = nullptr; - GTMatchExpression gt(collator); + GTMatchExpression gt; ASSERT(gt.init("a", operand["$gt"]).isOK()); ASSERT(gt.matchesBSON(BSON("a" << BSON_ARRAY(3 << 5.5)), NULL)); ASSERT(!gt.matchesBSON(BSON("a" << BSON_ARRAY(2 << 4)), NULL)); @@ -701,8 +666,7 @@ TEST(GtOp, MatchesArrayValue) { TEST(GtOp, MatchesWholeArray) { BSONObj operand = BSON("$gt" << BSON_ARRAY(5)); - const CollatorInterface* collator = nullptr; - GTMatchExpression gt(collator); + GTMatchExpression gt; ASSERT(gt.init("a", operand["$gt"]).isOK()); ASSERT(!gt.matchesBSON(BSON("a" << BSON_ARRAY(4)), NULL)); ASSERT(!gt.matchesBSON(BSON("a" << BSON_ARRAY(5)), NULL)); @@ -717,8 +681,7 @@ TEST(GtOp, MatchesWholeArray) { TEST(GtOp, MatchesNull) { BSONObj operand = BSON("$gt" << BSONNULL); - const CollatorInterface* collator = nullptr; - GTMatchExpression gt(collator); + GTMatchExpression gt; ASSERT(gt.init("a", operand["$gt"]).isOK()); ASSERT(!gt.matchesBSON(BSONObj(), NULL)); ASSERT(!gt.matchesBSON(BSON("a" << BSONNULL), NULL)); @@ -729,8 +692,7 @@ TEST(GtOp, MatchesNull) { TEST(GtOp, MatchesDotNotationNull) { BSONObj operand = BSON("$gt" << BSONNULL); - const CollatorInterface* collator = nullptr; - GTMatchExpression gt(collator); + GTMatchExpression gt; ASSERT(gt.init("a.b", operand["$gt"]).isOK()); ASSERT(!gt.matchesBSON(BSONObj(), NULL)); ASSERT(!gt.matchesBSON(BSON("a" << BSONNULL), NULL)); @@ -744,8 +706,7 @@ TEST(GtOp, MatchesDotNotationNull) { TEST(GtOp, MatchesMinKey) { BSONObj operand = BSON("a" << MinKey); - const CollatorInterface* collator = nullptr; - GTMatchExpression gt(collator); + GTMatchExpression gt; ASSERT(gt.init("a", operand["a"]).isOK()); ASSERT(!gt.matchesBSON(BSON("a" << MinKey), NULL)); ASSERT(gt.matchesBSON(BSON("a" << MaxKey), NULL)); @@ -754,8 +715,7 @@ TEST(GtOp, MatchesMinKey) { TEST(GtOp, MatchesMaxKey) { BSONObj operand = BSON("a" << MaxKey); - const CollatorInterface* collator = nullptr; - GTMatchExpression gt(collator); + GTMatchExpression gt; ASSERT(gt.init("a", operand["a"]).isOK()); ASSERT(!gt.matchesBSON(BSON("a" << MaxKey), NULL)); ASSERT(!gt.matchesBSON(BSON("a" << MinKey), NULL)); @@ -764,8 +724,7 @@ TEST(GtOp, MatchesMaxKey) { TEST(GtOp, ElemMatchKey) { BSONObj operand = BSON("$gt" << 5); - const CollatorInterface* collator = nullptr; - GTMatchExpression gt(collator); + GTMatchExpression gt; ASSERT(gt.init("a", operand["$gt"]).isOK()); MatchDetails details; details.requestElemMatchKey(); @@ -836,8 +795,7 @@ TEST(GteOp, MatchesElement) { BSONObj notMatch = BSON("a" << 4); BSONObj notMatchWrongType = BSON("a" << "foo"); - const CollatorInterface* collator = nullptr; - GTEMatchExpression gte(collator); + GTEMatchExpression gte; ASSERT(gte.init("", operand["$gte"]).isOK()); ASSERT(gte.matchesSingleElement(match.firstElement())); ASSERT(gte.matchesSingleElement(equalMatch.firstElement())); @@ -847,15 +805,13 @@ TEST(GteOp, MatchesElement) { TEST(GteOp, InvalidEooOperand) { BSONObj operand; - const CollatorInterface* collator = nullptr; - GTEMatchExpression gte(collator); + GTEMatchExpression gte; ASSERT(!gte.init("", operand.firstElement()).isOK()); } TEST(GteOp, MatchesScalar) { BSONObj operand = BSON("$gte" << 5); - const CollatorInterface* collator = nullptr; - GTEMatchExpression gte(collator); + GTEMatchExpression gte; ASSERT(gte.init("a", operand["$gte"]).isOK()); ASSERT(gte.matchesBSON(BSON("a" << 5.5), NULL)); ASSERT(!gte.matchesBSON(BSON("a" << 4), NULL)); @@ -863,8 +819,7 @@ TEST(GteOp, MatchesScalar) { TEST(GteOp, MatchesArrayValue) { BSONObj operand = BSON("$gte" << 5); - const CollatorInterface* collator = nullptr; - GTEMatchExpression gte(collator); + GTEMatchExpression gte; ASSERT(gte.init("a", operand["$gte"]).isOK()); ASSERT(gte.matchesBSON(BSON("a" << BSON_ARRAY(4 << 5.5)), NULL)); ASSERT(!gte.matchesBSON(BSON("a" << BSON_ARRAY(1 << 2)), NULL)); @@ -872,8 +827,7 @@ TEST(GteOp, MatchesArrayValue) { TEST(GteOp, MatchesWholeArray) { BSONObj operand = BSON("$gte" << BSON_ARRAY(5)); - const CollatorInterface* collator = nullptr; - GTEMatchExpression gte(collator); + GTEMatchExpression gte; ASSERT(gte.init("a", operand["$gte"]).isOK()); ASSERT(!gte.matchesBSON(BSON("a" << BSON_ARRAY(4)), NULL)); ASSERT(gte.matchesBSON(BSON("a" << BSON_ARRAY(5)), NULL)); @@ -887,8 +841,7 @@ TEST(GteOp, MatchesWholeArray) { TEST(GteOp, MatchesNull) { BSONObj operand = BSON("$gte" << BSONNULL); - const CollatorInterface* collator = nullptr; - GTEMatchExpression gte(collator); + GTEMatchExpression gte; ASSERT(gte.init("a", operand["$gte"]).isOK()); ASSERT(gte.matchesBSON(BSONObj(), NULL)); ASSERT(gte.matchesBSON(BSON("a" << BSONNULL), NULL)); @@ -899,8 +852,7 @@ TEST(GteOp, MatchesNull) { TEST(GteOp, MatchesDotNotationNull) { BSONObj operand = BSON("$gte" << BSONNULL); - const CollatorInterface* collator = nullptr; - GTEMatchExpression gte(collator); + GTEMatchExpression gte; ASSERT(gte.init("a.b", operand["$gte"]).isOK()); ASSERT(gte.matchesBSON(BSONObj(), NULL)); ASSERT(gte.matchesBSON(BSON("a" << BSONNULL), NULL)); @@ -914,8 +866,7 @@ TEST(GteOp, MatchesDotNotationNull) { TEST(GteOp, MatchesMinKey) { BSONObj operand = BSON("a" << MinKey); - const CollatorInterface* collator = nullptr; - GTEMatchExpression gte(collator); + GTEMatchExpression gte; ASSERT(gte.init("a", operand["a"]).isOK()); ASSERT(gte.matchesBSON(BSON("a" << MinKey), NULL)); ASSERT(gte.matchesBSON(BSON("a" << MaxKey), NULL)); @@ -924,8 +875,7 @@ TEST(GteOp, MatchesMinKey) { TEST(GteOp, MatchesMaxKey) { BSONObj operand = BSON("a" << MaxKey); - const CollatorInterface* collator = nullptr; - GTEMatchExpression gte(collator); + GTEMatchExpression gte; ASSERT(gte.init("a", operand["a"]).isOK()); ASSERT(gte.matchesBSON(BSON("a" << MaxKey), NULL)); ASSERT(!gte.matchesBSON(BSON("a" << MinKey), NULL)); @@ -934,8 +884,7 @@ TEST(GteOp, MatchesMaxKey) { TEST(GteOp, ElemMatchKey) { BSONObj operand = BSON("$gte" << 5); - const CollatorInterface* collator = nullptr; - GTEMatchExpression gte(collator); + GTEMatchExpression gte; ASSERT(gte.init("a", operand["$gte"]).isOK()); MatchDetails details; details.requestElemMatchKey(); diff --git a/src/mongo/db/matcher/expression_parser.cpp b/src/mongo/db/matcher/expression_parser.cpp index be163353fb4..3bad4c45433 100644 --- a/src/mongo/db/matcher/expression_parser.cpp +++ b/src/mongo/db/matcher/expression_parser.cpp @@ -67,9 +67,11 @@ namespace mongo { using std::string; using stdx::make_unique; -StatusWithMatchExpression MatchExpressionParser::_parseComparison(const char* name, - ComparisonMatchExpression* cmp, - const BSONElement& e) { +StatusWithMatchExpression MatchExpressionParser::_parseComparison( + const char* name, + ComparisonMatchExpression* cmp, + const BSONElement& e, + const CollatorInterface* collator) { std::unique_ptr<ComparisonMatchExpression> temp(cmp); // Non-equality comparison match expressions cannot have @@ -83,6 +85,7 @@ StatusWithMatchExpression MatchExpressionParser::_parseComparison(const char* na Status s = temp->init(name, e); if (!s.isOK()) return s; + temp->setCollator(collator); return {std::move(temp)}; } @@ -96,7 +99,7 @@ StatusWithMatchExpression MatchExpressionParser::_parseSubField(const BSONObj& c // TODO: these should move to getGtLtOp, or its replacement if (mongoutils::str::equals("$eq", e.fieldName())) - return _parseComparison(name, new EqualityMatchExpression(collator), e); + return _parseComparison(name, new EqualityMatchExpression(), e, collator); if (mongoutils::str::equals("$not", e.fieldName())) { return _parseNot(name, e, collator, level); @@ -113,13 +116,13 @@ StatusWithMatchExpression MatchExpressionParser::_parseSubField(const BSONObj& c return {Status(ErrorCodes::BadValue, mongoutils::str::stream() << "unknown operator: " << e.fieldName())}; case BSONObj::LT: - return _parseComparison(name, new LTMatchExpression(collator), e); + return _parseComparison(name, new LTMatchExpression(), e, collator); case BSONObj::LTE: - return _parseComparison(name, new LTEMatchExpression(collator), e); + return _parseComparison(name, new LTEMatchExpression(), e, collator); case BSONObj::GT: - return _parseComparison(name, new GTMatchExpression(collator), e); + return _parseComparison(name, new GTMatchExpression(), e, collator); case BSONObj::GTE: - return _parseComparison(name, new GTEMatchExpression(collator), e); + return _parseComparison(name, new GTEMatchExpression(), e, collator); case BSONObj::NE: { if (RegEx == e.type()) { // Just because $ne can be rewritten as the negation of an @@ -127,7 +130,7 @@ StatusWithMatchExpression MatchExpressionParser::_parseSubField(const BSONObj& c return {Status(ErrorCodes::BadValue, "Can't have regex as arg to $ne.")}; } StatusWithMatchExpression s = - _parseComparison(name, new EqualityMatchExpression(collator), e); + _parseComparison(name, new EqualityMatchExpression(), e, collator); if (!s.isOK()) return s; std::unique_ptr<NotMatchExpression> n = stdx::make_unique<NotMatchExpression>(); @@ -137,7 +140,7 @@ StatusWithMatchExpression MatchExpressionParser::_parseSubField(const BSONObj& c return {std::move(n)}; } case BSONObj::Equality: - return _parseComparison(name, new EqualityMatchExpression(collator), e); + return _parseComparison(name, new EqualityMatchExpression(), e, collator); case BSONObj::opIN: { if (e.type() != Array) @@ -350,13 +353,13 @@ StatusWithMatchExpression MatchExpressionParser::_parse(const BSONObj& obj, } else if (mongoutils::str::equals("ref", rest) || mongoutils::str::equals("id", rest) || mongoutils::str::equals("db", rest)) { // DBRef fields. - // 'id' is collation-aware. 'ref' and 'db' are compared using binary comparison. std::unique_ptr<ComparisonMatchExpression> eq = - stdx::make_unique<EqualityMatchExpression>(str::equals("id", rest) ? collator - : nullptr); + stdx::make_unique<EqualityMatchExpression>(); Status s = eq->init(e.fieldName(), e); if (!s.isOK()) return s; + // 'id' is collation-aware. 'ref' and 'db' are compared using binary comparison. + eq->setCollator(str::equals("id", rest) ? collator : nullptr); root->add(eq.release()); } else { @@ -384,10 +387,11 @@ StatusWithMatchExpression MatchExpressionParser::_parse(const BSONObj& obj, } std::unique_ptr<ComparisonMatchExpression> eq = - stdx::make_unique<EqualityMatchExpression>(collator); + stdx::make_unique<EqualityMatchExpression>(); Status s = eq->init(e.fieldName(), e); if (!s.isOK()) return s; + eq->setCollator(collator); root->add(eq.release()); } @@ -806,10 +810,11 @@ StatusWithMatchExpression MatchExpressionParser::_parseAll(const char* name, return {Status(ErrorCodes::BadValue, "no $ expressions in $all")}; } else { std::unique_ptr<EqualityMatchExpression> x = - stdx::make_unique<EqualityMatchExpression>(collator); + stdx::make_unique<EqualityMatchExpression>(); Status s = x->init(name, e); if (!s.isOK()) return s; + x->setCollator(collator); myAnd->add(x.release()); } } diff --git a/src/mongo/db/matcher/expression_parser.h b/src/mongo/db/matcher/expression_parser.h index c1b9e09fc2b..0b210d69016 100644 --- a/src/mongo/db/matcher/expression_parser.h +++ b/src/mongo/db/matcher/expression_parser.h @@ -48,7 +48,6 @@ public: /** * caller has to maintain ownership obj * the tree has views (BSONElement) into obj - * 'collator' must outlive the returned MatchExpression and any clones made of it. */ static StatusWithMatchExpression parse(const BSONObj& obj, const ExtensionsCallback& extensionsCallback, @@ -120,7 +119,8 @@ private: StatusWithMatchExpression _parseComparison(const char* name, ComparisonMatchExpression* cmp, - const BSONElement& e); + const BSONElement& e, + const CollatorInterface* collator); StatusWithMatchExpression _parseMOD(const char* name, const BSONElement& e); diff --git a/src/mongo/db/matcher/expression_test.cpp b/src/mongo/db/matcher/expression_test.cpp index 1ca7eefa856..90d50cf5f47 100644 --- a/src/mongo/db/matcher/expression_test.cpp +++ b/src/mongo/db/matcher/expression_test.cpp @@ -47,8 +47,7 @@ TEST(MatchExpressionTest, Parse1) { TEST(LeafMatchExpressionTest, Equal1) { BSONObj temp = BSON("x" << 5); - const CollatorInterface* collator = nullptr; - EqualityMatchExpression e(collator); + EqualityMatchExpression e; e.init("x", temp["x"]); ASSERT_TRUE(e.matchesBSON(fromjson("{ x : 5 }"))); @@ -67,8 +66,7 @@ TEST(LeafMatchExpressionTest, Comp1) { BSONObj temp = BSON("x" << 5); { - const CollatorInterface* collator = nullptr; - LTEMatchExpression e(collator); + LTEMatchExpression e; e.init("x", temp["x"]); ASSERT_TRUE(e.matchesBSON(fromjson("{ x : 5 }"))); ASSERT_TRUE(e.matchesBSON(fromjson("{ x : 4 }"))); @@ -77,8 +75,7 @@ TEST(LeafMatchExpressionTest, Comp1) { } { - const CollatorInterface* collator = nullptr; - LTMatchExpression e(collator); + LTMatchExpression e; e.init("x", temp["x"]); ASSERT_FALSE(e.matchesBSON(fromjson("{ x : 5 }"))); ASSERT_TRUE(e.matchesBSON(fromjson("{ x : 4 }"))); @@ -87,8 +84,7 @@ TEST(LeafMatchExpressionTest, Comp1) { } { - const CollatorInterface* collator = nullptr; - GTEMatchExpression e(collator); + GTEMatchExpression e; e.init("x", temp["x"]); ASSERT_TRUE(e.matchesBSON(fromjson("{ x : 5 }"))); ASSERT_FALSE(e.matchesBSON(fromjson("{ x : 4 }"))); @@ -97,8 +93,7 @@ TEST(LeafMatchExpressionTest, Comp1) { } { - const CollatorInterface* collator = nullptr; - GTMatchExpression e(collator); + GTMatchExpression e; e.init("x", temp["x"]); ASSERT_FALSE(e.matchesBSON(fromjson("{ x : 5 }"))); ASSERT_FALSE(e.matchesBSON(fromjson("{ x : 4 }"))); diff --git a/src/mongo/db/matcher/expression_tree_test.cpp b/src/mongo/db/matcher/expression_tree_test.cpp index 8ede86c0f0d..eadfd99d889 100644 --- a/src/mongo/db/matcher/expression_tree_test.cpp +++ b/src/mongo/db/matcher/expression_tree_test.cpp @@ -42,8 +42,7 @@ using std::unique_ptr; TEST(NotMatchExpression, MatchesScalar) { BSONObj baseOperand = BSON("$lt" << 5); - const CollatorInterface* collator = nullptr; - unique_ptr<ComparisonMatchExpression> lt(new LTMatchExpression(collator)); + unique_ptr<ComparisonMatchExpression> lt(new LTMatchExpression()); ASSERT(lt->init("a", baseOperand["$lt"]).isOK()); NotMatchExpression notOp; ASSERT(notOp.init(lt.release()).isOK()); @@ -53,8 +52,7 @@ TEST(NotMatchExpression, MatchesScalar) { TEST(NotMatchExpression, MatchesArray) { BSONObj baseOperand = BSON("$lt" << 5); - const CollatorInterface* collator = nullptr; - unique_ptr<ComparisonMatchExpression> lt(new LTMatchExpression(collator)); + unique_ptr<ComparisonMatchExpression> lt(new LTMatchExpression()); ASSERT(lt->init("a", baseOperand["$lt"]).isOK()); NotMatchExpression notOp; ASSERT(notOp.init(lt.release()).isOK()); @@ -66,8 +64,7 @@ TEST(NotMatchExpression, MatchesArray) { TEST(NotMatchExpression, ElemMatchKey) { BSONObj baseOperand = BSON("$lt" << 5); - const CollatorInterface* collator = nullptr; - unique_ptr<ComparisonMatchExpression> lt(new LTMatchExpression(collator)); + unique_ptr<ComparisonMatchExpression> lt(new LTMatchExpression()); ASSERT(lt->init("a", baseOperand["$lt"]).isOK()); NotMatchExpression notOp; ASSERT(notOp.init(lt.release()).isOK()); @@ -130,10 +127,9 @@ TEST(AndOp, MatchesElementThreeClauses) { BSONObj notMatch3 = BSON("a" << "r"); - const CollatorInterface* collator = nullptr; - unique_ptr<ComparisonMatchExpression> sub1(new LTMatchExpression(collator)); + unique_ptr<ComparisonMatchExpression> sub1(new LTMatchExpression()); ASSERT(sub1->init("a", baseOperand1["$lt"]).isOK()); - unique_ptr<ComparisonMatchExpression> sub2(new GTMatchExpression(collator)); + unique_ptr<ComparisonMatchExpression> sub2(new GTMatchExpression()); ASSERT(sub2->init("a", baseOperand2["$gt"]).isOK()); unique_ptr<RegexMatchExpression> sub3(new RegexMatchExpression()); ASSERT(sub3->init("a", "1", "").isOK()); @@ -151,8 +147,7 @@ TEST(AndOp, MatchesElementThreeClauses) { TEST(AndOp, MatchesSingleClause) { BSONObj baseOperand = BSON("$ne" << 5); - const CollatorInterface* collator = nullptr; - unique_ptr<ComparisonMatchExpression> eq(new EqualityMatchExpression(collator)); + unique_ptr<ComparisonMatchExpression> eq(new EqualityMatchExpression()); ASSERT(eq->init("a", baseOperand["$ne"]).isOK()); unique_ptr<NotMatchExpression> ne(new NotMatchExpression()); ASSERT(ne->init(eq.release()).isOK()); @@ -171,14 +166,13 @@ TEST(AndOp, MatchesThreeClauses) { BSONObj baseOperand2 = BSON("$lt" << 10); BSONObj baseOperand3 = BSON("$lt" << 100); - const CollatorInterface* collator = nullptr; - unique_ptr<ComparisonMatchExpression> sub1(new GTMatchExpression(collator)); + unique_ptr<ComparisonMatchExpression> sub1(new GTMatchExpression()); ASSERT(sub1->init("a", baseOperand1["$gt"]).isOK()); - unique_ptr<ComparisonMatchExpression> sub2(new LTMatchExpression(collator)); + unique_ptr<ComparisonMatchExpression> sub2(new LTMatchExpression()); ASSERT(sub2->init("a", baseOperand2["$lt"]).isOK()); - unique_ptr<ComparisonMatchExpression> sub3(new LTMatchExpression(collator)); + unique_ptr<ComparisonMatchExpression> sub3(new LTMatchExpression()); ASSERT(sub3->init("b", baseOperand3["$lt"]).isOK()); AndMatchExpression andOp; @@ -197,11 +191,10 @@ TEST(AndOp, ElemMatchKey) { BSONObj baseOperand1 = BSON("a" << 1); BSONObj baseOperand2 = BSON("b" << 2); - const CollatorInterface* collator = nullptr; - unique_ptr<ComparisonMatchExpression> sub1(new EqualityMatchExpression(collator)); + unique_ptr<ComparisonMatchExpression> sub1(new EqualityMatchExpression()); ASSERT(sub1->init("a", baseOperand1["a"]).isOK()); - unique_ptr<ComparisonMatchExpression> sub2(new EqualityMatchExpression(collator)); + unique_ptr<ComparisonMatchExpression> sub2(new EqualityMatchExpression()); ASSERT(sub2->init("b", baseOperand2["b"]).isOK()); AndMatchExpression andOp; @@ -318,8 +311,7 @@ TEST( OrOp, MatchesElementThreeClauses ) { */ TEST(OrOp, MatchesSingleClause) { BSONObj baseOperand = BSON("$ne" << 5); - const CollatorInterface* collator = nullptr; - unique_ptr<ComparisonMatchExpression> eq(new EqualityMatchExpression(collator)); + unique_ptr<ComparisonMatchExpression> eq(new EqualityMatchExpression()); ASSERT(eq->init("a", baseOperand["$ne"]).isOK()); unique_ptr<NotMatchExpression> ne(new NotMatchExpression()); ASSERT(ne->init(eq.release()).isOK()); @@ -337,12 +329,11 @@ TEST(OrOp, MatchesThreeClauses) { BSONObj baseOperand1 = BSON("$gt" << 10); BSONObj baseOperand2 = BSON("$lt" << 0); BSONObj baseOperand3 = BSON("b" << 100); - const CollatorInterface* collator = nullptr; - unique_ptr<ComparisonMatchExpression> sub1(new GTMatchExpression(collator)); + unique_ptr<ComparisonMatchExpression> sub1(new GTMatchExpression()); ASSERT(sub1->init("a", baseOperand1["$gt"]).isOK()); - unique_ptr<ComparisonMatchExpression> sub2(new LTMatchExpression(collator)); + unique_ptr<ComparisonMatchExpression> sub2(new LTMatchExpression()); ASSERT(sub2->init("a", baseOperand2["$lt"]).isOK()); - unique_ptr<ComparisonMatchExpression> sub3(new EqualityMatchExpression(collator)); + unique_ptr<ComparisonMatchExpression> sub3(new EqualityMatchExpression()); ASSERT(sub3->init("b", baseOperand3["b"]).isOK()); OrMatchExpression orOp; @@ -362,10 +353,9 @@ TEST(OrOp, MatchesThreeClauses) { TEST(OrOp, ElemMatchKey) { BSONObj baseOperand1 = BSON("a" << 1); BSONObj baseOperand2 = BSON("b" << 2); - const CollatorInterface* collator = nullptr; - unique_ptr<ComparisonMatchExpression> sub1(new EqualityMatchExpression(collator)); + unique_ptr<ComparisonMatchExpression> sub1(new EqualityMatchExpression()); ASSERT(sub1->init("a", baseOperand1["a"]).isOK()); - unique_ptr<ComparisonMatchExpression> sub2(new EqualityMatchExpression(collator)); + unique_ptr<ComparisonMatchExpression> sub2(new EqualityMatchExpression()); ASSERT(sub2->init("b", baseOperand2["b"]).isOK()); OrMatchExpression orOp; @@ -482,8 +472,7 @@ TEST( NorOp, MatchesElementThreeClauses ) { TEST(NorOp, MatchesSingleClause) { BSONObj baseOperand = BSON("$ne" << 5); - const CollatorInterface* collator = nullptr; - unique_ptr<ComparisonMatchExpression> eq(new EqualityMatchExpression(collator)); + unique_ptr<ComparisonMatchExpression> eq(new EqualityMatchExpression()); ASSERT(eq->init("a", baseOperand["$ne"]).isOK()); unique_ptr<NotMatchExpression> ne(new NotMatchExpression()); ASSERT(ne->init(eq.release()).isOK()); @@ -502,12 +491,11 @@ TEST(NorOp, MatchesThreeClauses) { BSONObj baseOperand2 = BSON("$lt" << 0); BSONObj baseOperand3 = BSON("b" << 100); - const CollatorInterface* collator = nullptr; - unique_ptr<ComparisonMatchExpression> sub1(new GTMatchExpression(collator)); + unique_ptr<ComparisonMatchExpression> sub1(new GTMatchExpression()); ASSERT(sub1->init("a", baseOperand1["$gt"]).isOK()); - unique_ptr<ComparisonMatchExpression> sub2(new LTMatchExpression(collator)); + unique_ptr<ComparisonMatchExpression> sub2(new LTMatchExpression()); ASSERT(sub2->init("a", baseOperand2["$lt"]).isOK()); - unique_ptr<ComparisonMatchExpression> sub3(new EqualityMatchExpression(collator)); + unique_ptr<ComparisonMatchExpression> sub3(new EqualityMatchExpression()); ASSERT(sub3->init("b", baseOperand3["b"]).isOK()); NorMatchExpression norOp; @@ -527,10 +515,9 @@ TEST(NorOp, MatchesThreeClauses) { TEST(NorOp, ElemMatchKey) { BSONObj baseOperand1 = BSON("a" << 1); BSONObj baseOperand2 = BSON("b" << 2); - const CollatorInterface* collator = nullptr; - unique_ptr<ComparisonMatchExpression> sub1(new EqualityMatchExpression(collator)); + unique_ptr<ComparisonMatchExpression> sub1(new EqualityMatchExpression()); ASSERT(sub1->init("a", baseOperand1["a"]).isOK()); - unique_ptr<ComparisonMatchExpression> sub2(new EqualityMatchExpression(collator)); + unique_ptr<ComparisonMatchExpression> sub2(new EqualityMatchExpression()); ASSERT(sub2->init("b", baseOperand2["b"]).isOK()); NorMatchExpression norOp; @@ -552,10 +539,9 @@ TEST(NorOp, ElemMatchKey) { TEST(NorOp, Equivalent) { BSONObj baseOperand1 = BSON("a" << 1); BSONObj baseOperand2 = BSON("b" << 2); - const CollatorInterface* collator = nullptr; - EqualityMatchExpression sub1(collator); + EqualityMatchExpression sub1; ASSERT(sub1.init("a", baseOperand1["a"]).isOK()); - EqualityMatchExpression sub2(collator); + EqualityMatchExpression sub2; ASSERT(sub2.init("b", baseOperand2["b"]).isOK()); NorMatchExpression e1; diff --git a/src/mongo/db/query/canonical_query.cpp b/src/mongo/db/query/canonical_query.cpp index 653f73b51f9..fdcbddf91b7 100644 --- a/src/mongo/db/query/canonical_query.cpp +++ b/src/mongo/db/query/canonical_query.cpp @@ -332,8 +332,9 @@ MatchExpression* CanonicalQuery::normalizeTree(MatchExpression* root) { // IN of 1 equality is the equality. if (in->getEqualities().size() == 1 && in->getRegexes().empty()) { - auto eq = stdx::make_unique<EqualityMatchExpression>(in->getCollator()); + auto eq = stdx::make_unique<EqualityMatchExpression>(); eq->init(in->path(), *(in->getEqualities().begin())); + eq->setCollator(in->getCollator()); if (in->getTag()) { eq->setTag(in->getTag()->clone()); } |
