diff options
author | David Storch <david.storch@10gen.com> | 2017-08-24 16:12:52 -0400 |
---|---|---|
committer | David Storch <david.storch@10gen.com> | 2017-08-29 18:20:53 -0400 |
commit | 67f72740b1b93fb797d49397b207a03ec15afd5e (patch) | |
tree | 77419ad19fa595b834fbc196e464a72aa417fcd8 /src/mongo/db/query/index_bounds_builder_test.cpp | |
parent | b47d1bd254d543a8880ac226ea7daa2d4e2b0967 (diff) | |
download | mongo-67f72740b1b93fb797d49397b207a03ec15afd5e.tar.gz |
SERVER-30245 Add support for multiple types in JSON Schema 'type'/'bsonType' and in $type.
This change implements the 'type' and 'bsonType' JSON Schema
keywords accepting an array of type aliases. At the same
time, it adds support for an array of type aliases in the
$type match expression.
Diffstat (limited to 'src/mongo/db/query/index_bounds_builder_test.cpp')
-rw-r--r-- | src/mongo/db/query/index_bounds_builder_test.cpp | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/mongo/db/query/index_bounds_builder_test.cpp b/src/mongo/db/query/index_bounds_builder_test.cpp index f8bff9d6984..ec85f567ae1 100644 --- a/src/mongo/db/query/index_bounds_builder_test.cpp +++ b/src/mongo/db/query/index_bounds_builder_test.cpp @@ -2153,4 +2153,59 @@ TEST(IndexBoundsBuilderTest, InWithStringAgainstHashedIndexWithCollatorUsesHashO ASSERT_EQUALS(tightness, IndexBoundsBuilder::INEXACT_FETCH); } +TEST(IndexBoundsBuilderTest, TypeArrayWithAdditionalTypesHasOpenBounds) { + IndexEntry testIndex = IndexEntry(BSONObj()); + BSONObj obj = fromjson("{a: {$type: ['array', 'long']}}"); + unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); + BSONElement elt = obj.firstElement(); + + OrderedIntervalList oil; + IndexBoundsBuilder::BoundsTightness tightness; + IndexBoundsBuilder::translate(expr.get(), elt, testIndex, &oil, &tightness); + + ASSERT_EQUALS(oil.name, "a"); + ASSERT_EQUALS(oil.intervals.size(), 1U); + ASSERT_EQUALS(Interval::INTERVAL_EQUALS, + oil.intervals[0].compare(IndexBoundsBuilder::allValues())); + ASSERT(tightness == IndexBoundsBuilder::INEXACT_FETCH); +} + +TEST(IndexBoundsBuilderTest, TypeStringOrNumberHasCorrectBounds) { + IndexEntry testIndex = IndexEntry(BSONObj()); + BSONObj obj = fromjson("{a: {$type: ['string', 'number']}}"); + unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); + BSONElement elt = obj.firstElement(); + + OrderedIntervalList oil; + IndexBoundsBuilder::BoundsTightness tightness; + IndexBoundsBuilder::translate(expr.get(), elt, testIndex, &oil, &tightness); + + ASSERT_EQUALS(oil.name, "a"); + ASSERT_EQUALS(oil.intervals.size(), 2U); + ASSERT_EQUALS( + Interval::INTERVAL_EQUALS, + oil.intervals[0].compare(Interval(fromjson("{'': NaN, '': Infinity}"), true, true))); + ASSERT_EQUALS(Interval::INTERVAL_EQUALS, + oil.intervals[1].compare(Interval(fromjson("{'': '', '': {}}"), true, true))); + ASSERT(tightness == IndexBoundsBuilder::INEXACT_FETCH); +} + +TEST(IndexBoundsBuilderTest, RedundantTypeNumberHasCorrectBounds) { + IndexEntry testIndex = IndexEntry(BSONObj()); + BSONObj obj = fromjson("{a: {$type: ['number', 'int', 'long', 'double']}}"); + unique_ptr<MatchExpression> expr(parseMatchExpression(obj)); + BSONElement elt = obj.firstElement(); + + OrderedIntervalList oil; + IndexBoundsBuilder::BoundsTightness tightness; + IndexBoundsBuilder::translate(expr.get(), elt, testIndex, &oil, &tightness); + + ASSERT_EQUALS(oil.name, "a"); + ASSERT_EQUALS(oil.intervals.size(), 1U); + ASSERT_EQUALS( + Interval::INTERVAL_EQUALS, + oil.intervals[0].compare(Interval(fromjson("{'': NaN, '': Infinity}"), true, true))); + ASSERT(tightness == IndexBoundsBuilder::INEXACT_FETCH); +} + } // namespace |