Skip to content

Commit

Permalink
some mr tests for SERVER-1787 SERVER-2272
Browse files Browse the repository at this point in the history
  • Loading branch information
erh committed Jan 16, 2011
1 parent 5803871 commit ba78158
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
50 changes: 50 additions & 0 deletions jstests/mr_index3.js
@@ -0,0 +1,50 @@

t = db.mr_index3
t.drop();

t.insert( { _id : 1, name : 'name1', tags : ['dog', 'cat'] } );
t.insert( { _id : 2, name : 'name2', tags : ['cat'] } );
t.insert( { _id : 3, name : 'name3', tags : ['mouse', 'cat', 'dog'] } );
t.insert( { _id : 4, name : 'name4', tags : [] } );

m = function(){
for ( var i=0; i<this.tags.length; i++ )
emit( this.tags[i] , 1 )
};

r = function( key , values ){
return Array.sum( values );
};

a1 = db.runCommand({ mapreduce : 'mr_index3', map : m, reduce : r , out : { inline : true } } ).results
a2 = db.runCommand({ mapreduce : 'mr_index3', map : m, reduce : r, query: {name : 'name1'} , out : { inline : true }}).results
a3 = db.runCommand({ mapreduce : 'mr_index3', map : m, reduce : r, query: {name : {$gt:'name'} } , out : { inline : true }}).results

assert.eq( [
{
"_id" : "cat",
"value" : 3
},
{
"_id" : "dog",
"value" : 2
},
{
"_id" : "mouse",
"value" : 1
}
] , a1 , "A1" );
assert.eq( [ { "_id" : "cat", "value" : 1 }, { "_id" : "dog", "value" : 1 } ] , a2 , "A2" )
assert.eq( a1 , a3 , "A3" )

t.ensureIndex({name:1, tags:1});

b1 = db.runCommand({ mapreduce : 'mr_index3', map : m, reduce : r , out : { inline : true } } ).results
b2 = db.runCommand({ mapreduce : 'mr_index3', map : m, reduce : r, query: {name : 'name1'} , out : { inline : true }}).results
b3 = db.runCommand({ mapreduce : 'mr_index3', map : m, reduce : r, query: {name : {$gt:'name'} } , out : { inline : true }}).results

assert.eq( a1 , b1 , "AB1" )
assert.eq( a2 , b2 , "AB2" )
assert.eq( a3 , b3 , "AB3" )


27 changes: 27 additions & 0 deletions jstests/mr_outreduce2.js
@@ -0,0 +1,27 @@

normal = "mr_outreduce2"
out = normal + "_out"

t = db[normal]
t.drop();

db[out].drop()

t.insert( { _id : 1 , x : 1 } )
t.insert( { _id : 2 , x : 1 } )
t.insert( { _id : 3 , x : 2 } )

m = function(){ emit( this.x , 1 ); }
r = function(k,v){ return Array.sum( v ); }

res = t.mapReduce( m , r , { out : { reduce : out } , query : { _id : { $gt : 0 } } } )

assert.eq( 2 , db[out].findOne( { _id : 1 } ).value , "A1" )
assert.eq( 1 , db[out].findOne( { _id : 2 } ).value , "A2" )


t.insert( { _id : 4 , x : 2 } )
res = t.mapReduce( m , r , { out : { reduce : out } , query : { _id : { $gt : 3 } } , finalize : null } )

assert.eq( 2 , db[out].findOne( { _id : 1 } ).value , "B1" )
assert.eq( 2 , db[out].findOne( { _id : 2 } ).value , "B2" )

0 comments on commit ba78158

Please sign in to comment.