[SERVER-2269] Map/reduce with sorting fail Created: 22/Dec/10  Updated: 22/May/12  Resolved: 26/Dec/10

Status: Closed
Project: Core Server
Component/s: Build
Affects Version/s: 1.6.5
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Andrey Nikishaev Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Ubuntu 10.10 2.6.35-23-generic #41-Ubuntu SMP Wed Nov 24 11:55:36 UTC 2010 x86_64 GNU/Linux
python 2.6.6
pymongo 1.9


Attachments: File map-reduce.py    
Issue Links:
Related
is related to CSHARP-472 MapReduce fails with options SetQuery... Closed
Backwards Compatibility: Major Change
Operating System: Linux
Participants:

 Description   

When i trying to make sort on map/reduce it fails with "db assertion failure"
I wrote code in python, here it is:

m = Code("""function() {
data = {};
res = ''
if(this.result_id) {
res=

{'objectid':this.result_id.toString()}

;
} else

{ res=this.result; }

emit(this.data, res);
}""")
r = Code("""function(k,values) {
data={};
for(var i=0; i<values.length; i++ )

{ for(attr in values[i]) data[attr]=values[i][attr]; }

return data
}""")

res = self.db.tasks.map_reduce(m,r,query=

{'job_id':job_id}

,sort=

{'position':pymongo.ASCENDING}

)

But when i turn off sorting it works pretty fine.



 Comments   
Comment by Eliot Horowitz (Inactive) [ 26/Dec/10 ]

You need an index on job_id,position in order to use that.

Comment by Andrey Nikishaev [ 22/Dec/10 ]

Server version: Tried 1.4.4, 1.6.5, 1.7.4

Python traceback:

Traceback (most recent call last):
File "map-reduce.py", line 87, in <module>
reduce_job('4d121ac2ccab997705050000')
File "map-reduce.py", line 52, in reduce_job
res =
db.tasks.map_reduce(m,r,sort=

{'position':pymongo.ASCENDING}

,query=

{'job_id':ObjectId(job_id)}

)
File
"/usr/local/lib/python2.6/dist-packages/pymongo-1.9-py2.6-linux-x86_64.egg/pymongo/collection.py",
line 943, in map_reduce
map=map, reduce=reduce, **kwargs)
File
"/usr/local/lib/python2.6/dist-packages/pymongo-1.9-py2.6-linux-x86_64.egg/pymongo/database.py",
line 293, in command
msg, allowable_errors)
File
"/usr/local/lib/python2.6/dist-packages/pymongo-1.9-py2.6-linux-x86_64.egg/pymongo/helpers.py",
line 119, in _check_command_response
raise OperationFailure(msg % response["errmsg"])
pymongo.errors.OperationFailure: command SON([('mapreduce', u'tasks'),
('sort',

{'position': 1}

), ('query',

{'job_id': ObjectId('4d121ac2ccab997705050000')}

), ('reduce', Code('function(k,values)
{ \n\t data={};\n\t for(var i=0; i<values.length; i++ )

{\n\t for(attr in values[i])\n\t data[attr]=values[i][attr];\n\t }

\n\t return data\n\t}', {})), ('map', Code("function()

{\n\t data = {}

;\n\t res = ''\n\t if(this.result_id) {\n\t
res=

{'objectid':this.result_id.toString()}

;\n\t } else

{\n\t res=this.result;\n\t }

\n\t\tres['position'] = this.position;\n\t
emit(this.data, res);\n\t}", {}))]) failed: db assertion failure

Mongo log:

Wed Dec 22 17:36:56 [conn144] CMD: drop
seotools.tmp.mr.mapreduce_1293032215_1
Wed Dec 22 17:36:56 [conn144] CMD: drop
seotools.tmp.mr.mapreduce_1293032215_1_inc
Wed Dec 22 17:36:56 [conn144] Assertion: 13284:best guess plan requested,
but scan and order required: query:

{ job_id: ObjectId('4d121ac2ccab997705050000') }

order:

{ position: 1 }

choices: {
$natural: 1 }
Wed Dec 22 17:36:56 [conn144] mr failed, removing collection
Wed Dec 22 17:36:56 [conn144] CMD: drop
seotools.tmp.mr.mapreduce_1293032215_1
Wed Dec 22 17:36:56 [conn144] CMD: drop
seotools.tmp.mr.mapreduce_1293032215_1_inc

In attachment file that reproduce problem.

On version 1.4.4 i also notified that if sort param pass before query param
then it works but with big number of documents it return null.
i mean when we use:

res = self.db.tasks.map_reduce(m,r,sort=

{'position':pymongo.ASCENDING}

,
query=

{'job_id':job_id}

)

instead:

res =
self.db.tasks.map_reduce(m,r,query=

{'job_id':job_id}

,sort=

{'position':pymongo.ASCENDING}

)

Best regards,

Andrey Nikishaev

Blog http://creotiv.in.ua/
Skype creotiv.in.ua

2010/12/22 Eliot Horowitz (JIRA) <jira@mongodb.org>

Comment by Eliot Horowitz (Inactive) [ 22/Dec/10 ]

Can you send:

  • server log
  • server version
  • full error message
  • sample document
Generated at Thu Feb 08 02:59:27 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.