diff options
author | Eliot Horowitz <eliot@10gen.com> | 2013-05-16 15:29:32 -0400 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2013-05-16 18:16:30 -0400 |
commit | 6fa7a15256d8058b982bf259cad34c051c1f245a (patch) | |
tree | 917002b526bf0141e25e3543a7497eef18488aad | |
parent | 8a59bbfdd1b947ef42de4a1e598c6cc06c459b19 (diff) | |
download | mongo-6fa7a15256d8058b982bf259cad34c051c1f245a.tar.gz |
SERVER-6400: Remove NinMatchExpression, $nin is now just a parses issue
-rw-r--r-- | src/mongo/db/matcher/expression_leaf.cpp | 37 | ||||
-rw-r--r-- | src/mongo/db/matcher/expression_leaf.h | 20 | ||||
-rw-r--r-- | src/mongo/db/matcher/expression_leaf_test.cpp | 127 | ||||
-rw-r--r-- | src/mongo/db/matcher/expression_parser.cpp | 10 |
4 files changed, 8 insertions, 186 deletions
diff --git a/src/mongo/db/matcher/expression_leaf.cpp b/src/mongo/db/matcher/expression_leaf.cpp index 32b4535d5bf..df697fd38e1 100644 --- a/src/mongo/db/matcher/expression_leaf.cpp +++ b/src/mongo/db/matcher/expression_leaf.cpp @@ -518,43 +518,6 @@ namespace mongo { _arrayEntries.copyTo( toFillIn->_arrayEntries ); } - - - // ---------- - - void NinMatchExpression::init( const StringData& path ) { - initPath( path ); - _allHaveToMatch = true; - _in.init( path ); - } - - - bool NinMatchExpression::matchesSingleElement( const BSONElement& e ) const { - return !_in.matchesSingleElement( e ); - } - - - void NinMatchExpression::debugString( StringBuilder& debug, int level ) const { - _debugAddSpace( debug, level ); - debug << path() << " $nin: TODO\n"; - } - - bool NinMatchExpression::equivalent( const MatchExpression* other ) const { - if ( matchType() != other->matchType() ) - return false; - - return _in.equivalent( &(static_cast<const NinMatchExpression*>(other)->_in) ); - - } - - LeafMatchExpression* NinMatchExpression::shallowClone() const { - NinMatchExpression* next = new NinMatchExpression(); - next->init( path() ); - _in.copyTo( &next->_in ); - return next; - } - - } diff --git a/src/mongo/db/matcher/expression_leaf.h b/src/mongo/db/matcher/expression_leaf.h index cf95a5b3258..3f846e0bf18 100644 --- a/src/mongo/db/matcher/expression_leaf.h +++ b/src/mongo/db/matcher/expression_leaf.h @@ -307,25 +307,5 @@ namespace mongo { ArrayFilterEntries _arrayEntries; }; - class NinMatchExpression : public LeafMatchExpression { - public: - NinMatchExpression() : LeafMatchExpression( NIN ){} - void init( const StringData& path ); - - virtual LeafMatchExpression* shallowClone() const; - - ArrayFilterEntries* getArrayFilterEntries() { return _in.getArrayFilterEntries(); } - - virtual bool matchesSingleElement( const BSONElement& e ) const; - - virtual void debugString( StringBuilder& debug, int level ) const; - - virtual bool equivalent( const MatchExpression* other ) const; - - private: - InMatchExpression _in; - }; - - } diff --git a/src/mongo/db/matcher/expression_leaf_test.cpp b/src/mongo/db/matcher/expression_leaf_test.cpp index 17109b4f00e..8bd74fc2da7 100644 --- a/src/mongo/db/matcher/expression_leaf_test.cpp +++ b/src/mongo/db/matcher/expression_leaf_test.cpp @@ -1549,131 +1549,4 @@ namespace mongo { } */ - TEST( NinMatchExpression, MatchesElementSingle ) { - BSONObj operands = BSON_ARRAY( 1 ); - BSONObj match = BSON( "a" << 2 ); - BSONObj notMatch = BSON( "a" << 1 ); - NinMatchExpression nin; - nin.getArrayFilterEntries()->addEquality( operands.firstElement() ); - ASSERT( nin.matchesSingleElement( match[ "a" ] ) ); - ASSERT( !nin.matchesSingleElement( notMatch[ "a" ] ) ); - } - - TEST( NinMatchExpression, MatchesElementMultiple ) { - BSONArray operand = BSON_ARRAY( 1 << "r" << true << 1 ); - BSONObj match = BSON( "a" << false ); - BSONObj notMatchFirst = BSON( "a" << 1 ); - BSONObj notMatchSecond = BSON( "a" << "r" ); - BSONObj notMatchThird = BSON( "a" << true ); - NinMatchExpression nin; - nin.getArrayFilterEntries()->addEquality( operand[0] ); - nin.getArrayFilterEntries()->addEquality( operand[1] ); - nin.getArrayFilterEntries()->addEquality( operand[2] ); - nin.getArrayFilterEntries()->addEquality( operand[3] ); - ASSERT( nin.matchesSingleElement( match[ "a" ] ) ); - ASSERT( !nin.matchesSingleElement( notMatchFirst[ "a" ] ) ); - ASSERT( !nin.matchesSingleElement( notMatchSecond[ "a" ] ) ); - ASSERT( !nin.matchesSingleElement( notMatchThird[ "a" ] ) ); - } - - TEST( NinMatchExpression, MatchesScalar ) { - BSONObj operand = BSON_ARRAY( 5 ); - NinMatchExpression nin; - nin.init( "a" ); - nin.getArrayFilterEntries()->addEquality( operand.firstElement() ); - ASSERT( nin.matchesBSON( BSON( "a" << 4 ), NULL ) ); - ASSERT( !nin.matchesBSON( BSON( "a" << 5 ), NULL ) ); - ASSERT( !nin.matchesBSON( BSON( "a" << 5.0 ), NULL ) ); - } - - TEST( NinMatchExpression, MatchesArrayValue ) { - BSONObj operand = BSON_ARRAY( 5 ); - NinMatchExpression nin; - nin.init( "a" ); - nin.getArrayFilterEntries()->addEquality( operand.firstElement() ); - ASSERT( !nin.matchesBSON( BSON( "a" << BSON_ARRAY( 5.0 << 6 ) ), NULL ) ); - ASSERT( nin.matchesBSON( BSON( "a" << BSON_ARRAY( 6 << 7 ) ), NULL ) ); - ASSERT( nin.matchesBSON( BSON( "a" << BSON_ARRAY( BSON_ARRAY( 5 ) ) ), NULL ) ); - } - - TEST( NinMatchExpression, MatchesNull ) { - BSONObjBuilder ninArray; - ninArray.appendNull( "0" ); - BSONObj operand = ninArray.obj(); - NinMatchExpression nin; - nin.init( "a" ); - nin.getArrayFilterEntries()->addEquality( operand.firstElement() ); - ASSERT( !nin.matchesBSON( BSONObj(), NULL ) ); - ASSERT( !nin.matchesBSON( BSON( "a" << BSONNULL ), NULL ) ); - ASSERT( nin.matchesBSON( BSON( "a" << 4 ), NULL ) ); - } - - TEST( NinMatchExpression, MatchesFullArray ) { - BSONArray operand = BSON_ARRAY( BSON_ARRAY( 1 << 2 ) << 4 << 5 ); - NinMatchExpression nin; - nin.init( "a" ); - nin.getArrayFilterEntries()->addEquality( operand[0] ); - nin.getArrayFilterEntries()->addEquality( operand[1] ); - nin.getArrayFilterEntries()->addEquality( operand[2] ); - ASSERT( !nin.matchesBSON( BSON( "a" << BSON_ARRAY( 1 << 2 ) ), NULL ) ); - ASSERT( nin.matchesBSON( BSON( "a" << BSON_ARRAY( 1 << 2 << 3 ) ), NULL ) ); - ASSERT( nin.matchesBSON( BSON( "a" << BSON_ARRAY( 1 ) ), NULL ) ); - ASSERT( nin.matchesBSON( BSON( "a" << 1 ), NULL ) ); - } - - TEST( NinMatchExpression, ElemMatchKey ) { - BSONArray operand = BSON_ARRAY( 5 << 2 ); - NinMatchExpression nin; - nin.init( "a" ); - nin.getArrayFilterEntries()->addEquality( operand[0] ); - nin.getArrayFilterEntries()->addEquality( operand[1] ); - - MatchDetails details; - details.requestElemMatchKey(); - ASSERT( !nin.matchesBSON( BSON( "a" << 2 ), &details ) ); - ASSERT( !details.hasElemMatchKey() ); - ASSERT( nin.matchesBSON( BSON( "a" << 3 ), &details ) ); - ASSERT( !details.hasElemMatchKey() ); - ASSERT( nin.matchesBSON( BSON( "a" << BSON_ARRAY( 1 << 3 << 6 ) ), &details ) ); - // The elemMatchKey feature is not implemented for $nin. - ASSERT( !details.hasElemMatchKey() ); - } - - TEST( NinMatchExpression, Equivalent ) { - BSONArray operand = BSON_ARRAY( 5 << 2 ); - - NinMatchExpression e1; - NinMatchExpression e2; - NinMatchExpression e3; - - e1.init( "a" ); - e2.init( "a" ); - e3.init( "b" ); - - e1.getArrayFilterEntries()->addEquality( operand[0] ); - e1.getArrayFilterEntries()->addEquality( operand[1] ); - - e2.getArrayFilterEntries()->addEquality( operand[0] ); - - e3.getArrayFilterEntries()->addEquality( operand[0] ); - e3.getArrayFilterEntries()->addEquality( operand[1] ); - - ASSERT( e1.equivalent( &e1 ) ); - ASSERT( !e1.equivalent( &e2 ) ); - ASSERT( !e1.equivalent( &e3 ) ); - } - - - /** - TEST( NinMatchExpression, MatchesIndexKey ) { - BSONObj operand = BSON( "$nin" << BSON_ARRAY( 5 ) ); - NinMatchExpression nin; - ASSERT( nin.init( "a", operand[ "$nin" ] ).isOK() ); - IndexSpec indexSpec( BSON( "a" << 1 ) ); - BSONObj indexKey = BSON( "" << "7" ); - ASSERT( MatchMatchExpression::PartialMatchResult_Unknown == - nin.matchesIndexKey( indexKey, indexSpec ) ); - } - */ - } diff --git a/src/mongo/db/matcher/expression_parser.cpp b/src/mongo/db/matcher/expression_parser.cpp index 810d9574432..db0650fa4b8 100644 --- a/src/mongo/db/matcher/expression_parser.cpp +++ b/src/mongo/db/matcher/expression_parser.cpp @@ -95,12 +95,18 @@ namespace mongo { case BSONObj::NIN: { if ( e.type() != Array ) return StatusWithMatchExpression( ErrorCodes::BadValue, "$nin needs an array" ); - std::auto_ptr<NinMatchExpression> temp( new NinMatchExpression() ); + std::auto_ptr<InMatchExpression> temp( new InMatchExpression() ); temp->init( name ); Status s = _parseArrayFilterEntries( temp->getArrayFilterEntries(), e.Obj() ); if ( !s.isOK() ) return StatusWithMatchExpression( s ); - return StatusWithMatchExpression( temp.release() ); + + std::auto_ptr<NotMatchExpression> temp2( new NotMatchExpression() ); + s = temp2->init( temp.release() ); + if ( !s.isOK() ) + return StatusWithMatchExpression( s ); + + return StatusWithMatchExpression( temp2.release() ); } case BSONObj::opSIZE: { |