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

$setIntersection with null and empty intersections violates commutativity

    XMLWordPrintable

Details

    • Fully Compatible
    • ALL
    • v4.2
    • Hide

      python buildscripts/resmoke.py --storageEngine wiredTiger --suites aggregation repro_set_intersection.js
      

      repro_set_intersection.js

      assert.commandWorked(db.my_coll.insert({ a: []}));
      const res1 = db.my_coll
                       .aggregate([{
                           $project: {
                               a: {
                                   $setIntersection: [
                                       "$a",
                                       "$missing",
                                   ]
                               },
                               _id: 0,
                           }
                       }])
                       .toArray();
      const res2 = db.my_coll
                       .aggregate([{
                           $project: {
                               a: {
                                   $setIntersection: [
                                       "$missing",
                                       "$a",
                                   ]
                               },
                               _id: 0,
                           }
                       }])
                       .toArray();
      assert.eq(res1, res2);
      

       

      Show
      python buildscripts/resmoke.py --storageEngine wiredTiger --suites aggregation repro_set_intersection.js repro_set_intersection.js assert.commandWorked(db.my_coll.insert({ a: []})); const res1 = db.my_coll .aggregate([{ $project: { a: { $setIntersection: [ "$a" , "$missing" , ] }, _id: 0, } }]) .toArray(); const res2 = db.my_coll .aggregate([{ $project: { a: { $setIntersection: [ "$missing" , "$a" , ] }, _id: 0, } }]) .toArray(); assert.eq(res1, res2);  
    • Query 2019-07-15, Query 2019-07-29
    • 0

    Description

      When $setIntersection is evaluated, if a nullish expression is encountered first then null is returned. If instead the intersection becomes empty, then an empty array is returned. This means that changing the order of the operands changes the result, invalidating commutativity.

      [js_test:repro] 2019-06-27T17:23:27.757-0400 2019-06-27T17:23:27.755-0400 E QUERY [js] uncaught exception: Error: [[ \{ "a" : [ ] } ]] != [[ \{ "a" : null } ]] are not equal :
      [js_test:repro] 2019-06-27T17:23:27.757-0400 doassert@src/mongo/shell/assert.js:20:14
      [js_test:repro] 2019-06-27T17:23:27.757-0400 assert.eq@src/mongo/shell/assert.js:180:9
      [js_test:repro] 2019-06-27T17:23:27.757-0400 @repro.js:30:1
      [js_test:repro] 2019-06-27T17:23:27.757-0400 2019-06-27T17:23:27.755-0400 F - [main] failed to load: repro.js
      [js_test:repro] 2019-06-27T17:23:27.757-0400 2019-06-27T17:23:27.755-0400 E - [main] exiting with code -3
      

      Attachments

        Issue Links

          Activity

            People

              george.wangensteen@mongodb.com George Wangensteen
              claire.childs@mongodb.com Claire Childs (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: