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

Scope "leaking" with map-reduce and CodeWScope

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major - P3
    • Resolution: Unresolved
    • Affects Version/s: 2.0.0
    • Fix Version/s: Backlog
    • Component/s: MapReduce
    • Environment:
      Pymongo 2.0.1/OS X
    • Operating System:
      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

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

              Dates

              Created:
              Updated: