summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mongo/bson/bsonobjbuilder.cpp4
-rw-r--r--src/mongo/db/query/index_bounds_builder_test.cpp28
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