diff options
author | David Hatch <david.hatch@mongodb.com> | 2015-07-27 14:45:01 -0400 |
---|---|---|
committer | David Hatch <david.hatch@mongodb.com> | 2015-07-28 16:23:46 -0400 |
commit | 4273fdf07c5af4bd0fd156f5a8a1d8efa56519fb (patch) | |
tree | a00da8baff7c3a62bd4a6ab00160f7e9c98cb3ca /src | |
parent | 645e9ad9dba32abf96a4d58abbf5c6be205c57cc (diff) | |
download | mongo-4273fdf07c5af4bd0fd156f5a8a1d8efa56519fb.tar.gz |
SERVER-19348, SERVER-19349: Correct index bounds on $type and $mod.
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/bson/bsonobjbuilder.cpp | 4 | ||||
-rw-r--r-- | src/mongo/db/query/index_bounds_builder_test.cpp | 28 |
2 files changed, 29 insertions, 3 deletions
diff --git a/src/mongo/bson/bsonobjbuilder.cpp b/src/mongo/bson/bsonobjbuilder.cpp index da6e31471fa..59baced7c26 100644 --- a/src/mongo/bson/bsonobjbuilder.cpp +++ b/src/mongo/bson/bsonobjbuilder.cpp @@ -46,7 +46,7 @@ void BSONObjBuilder::appendMinForType(StringData fieldName, int t) { case NumberInt: case NumberDouble: case NumberLong: - append(fieldName, -std::numeric_limits<double>::max()); + append(fieldName, std::numeric_limits<double>::quiet_NaN()); return; case Symbol: case String: @@ -116,7 +116,7 @@ void BSONObjBuilder::appendMaxForType(StringData fieldName, int t) { case NumberInt: case NumberDouble: case NumberLong: - append(fieldName, std::numeric_limits<double>::max()); + append(fieldName, std::numeric_limits<double>::infinity()); return; case Symbol: case String: diff --git a/src/mongo/db/query/index_bounds_builder_test.cpp b/src/mongo/db/query/index_bounds_builder_test.cpp index bd8b9d0d97e..d65907e1714 100644 --- a/src/mongo/db/query/index_bounds_builder_test.cpp +++ b/src/mongo/db/query/index_bounds_builder_test.cpp @@ -51,6 +51,7 @@ double numberMin = -numeric_limits<double>::max(); double numberMax = numeric_limits<double>::max(); double negativeInfinity = -numeric_limits<double>::infinity(); double positiveInfinity = numeric_limits<double>::infinity(); +double NaN = numeric_limits<double>::quiet_NaN(); /** * Utility function to create MatchExpression @@ -897,7 +898,8 @@ TEST(IndexBoundsBuilderTest, TranslateMod) { ASSERT_EQUALS(oil.intervals.size(), 1U); ASSERT_EQUALS( Interval::INTERVAL_EQUALS, - oil.intervals[0].compare(Interval(BSON("" << numberMin << "" << numberMax), true, true))); + oil.intervals[0].compare(Interval(BSON("" << NaN << "" << positiveInfinity), + true, true))); ASSERT_EQUALS(tightness, IndexBoundsBuilder::INEXACT_COVERED); } @@ -1438,4 +1440,28 @@ TEST(IndexBoundsBuilderTest, CodeWithScopeTypeBounds) { ASSERT(tightness == IndexBoundsBuilder::INEXACT_FETCH); } +// Test $type bounds for double BSON type. +TEST(IndexBoundsBuilderTest, DoubleTypeBounds) { + IndexEntry testIndex = IndexEntry(BSONObj()); + BSONObj obj = fromjson("{a: {$type: 1}}"); + unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); + BSONElement elt = obj.firstElement(); + + OrderedIntervalList oil; + IndexBoundsBuilder::BoundsTightness tightness; + IndexBoundsBuilder::translate(expr.get(), elt, testIndex, &oil, &tightness); + + // Build the expected interval. + BSONObjBuilder bob; + bob.appendNumber("", NaN); + bob.appendNumber("", positiveInfinity); + BSONObj expectedInterval = bob.obj(); + + // Check the output of translate(). + ASSERT_EQUALS(oil.name, "a"); + ASSERT_EQUALS(oil.intervals.size(), 1U); + ASSERT_EQUALS(Interval::INTERVAL_EQUALS, + oil.intervals[0].compare(Interval(expectedInterval, true, true))); + ASSERT(tightness == IndexBoundsBuilder::INEXACT_FETCH); +} } // namespace |