Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-3839

Scope "leaking" with map-reduce and CodeWScope

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major - P3 Major - P3
    • None
    • 2.0.0
    • MapReduce
    • Pymongo 2.0.1/OS X
    • Query Optimization
    • ALL

    Description

      Re-using the same variable in the scope option to two different CodeWScope objects (bson.code.Code, with scope keyword arg) results in the scope from reduce "leaking" into the scope of map.

      I've read the Python code, and I don't believe this is due to a bug in Pymongo.

      Short Python script to reproduce:

      from bson.code import Code
      import pymongo
       
      conn = pymongo.Connection()
      db = conn.test
       
      db.foo.drop()
      db.foo.save({'a': 1})
      db.foo.save({'a': 1})
      db.foo.save({'a': 2})
      db.foo.save({'a': 2})
       
       
      map = Code(
          """
          function() {
              emit( this.a, {one: scopevar, two: 0} );
          }
          """,
          scope={'scopevar': 1}
      )
       
      reduce = Code(
          """
          function(key, values) {
              var out = {one: 0, two: 0};
              for (var i=0; i<values.length; i++) {
                  out.one += values[i].one;
                  out.two += scopevar;
              }
              return out;
          }""",
          scope={'scopevar': 2}
      )
       
      # should give in 2 results, each with
      # field "one" == 2, and field "two" == 4
      for result in db.foo.inline_map_reduce(map, reduce):
          print result

      Actual results:

      {u'_id': 1.0, u'value': {u'two': 4.0, u'one': 4.0}}
      {u'_id': 2.0, u'value': {u'two': 4.0, u'one': 4.0}}

      Attachments

        Activity

          People

            backlog-query-optimization Backlog - Query Optimization
            dcrosta Daniel Crosta
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated: