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

$multiply with NaN operand violates commutativity

    XMLWordPrintable

Details

    • ALL
    • Hide

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

      repro_multiply.js

      assert.commandWorked(db.my_coll.insert({}));
       
      assert.throws(() => db.my_coll.aggregate(
      [{                                                                             
          "$project": {                                                                        
              "a": {                                                                           
                      "$multiply": [                                                           
                          NaN,                                                                 
                          {                                                                    
                              "$const": NumberDecimal("1")                                     
                          }                                                                    
                      ]                                                                        
              },
              _id: 0                                                                                
          }                                                                                    
      }]));
       
      let res = db.my_coll.aggregate(
      [{                                                                             
          "$project": {                                                                        
              "a": {                                                                           
                      "$multiply": [                                                                                                                            
                          {                                                                    
                              "$const": NumberDecimal("1")                                     
                          },
                          NaN                                                                    
                      ]                                                                        
              },
              _id: 0                                                                                
          }                                                                                    
      }]);
      assert.neq(res, null);
      

      Show
      python buildscripts/resmoke.py --storageEngine wiredTiger --suites aggregation repro_multiply.js repro_multiply.js assert.commandWorked(db.my_coll.insert({}));   assert.throws(() => db.my_coll.aggregate( [{ "$project" : { "a" : { "$multiply" : [ NaN, { "$const" : NumberDecimal( "1" ) } ] }, _id: 0 } }]));   let res = db.my_coll.aggregate( [{ "$project" : { "a" : { "$multiply" : [ { "$const" : NumberDecimal( "1" ) }, NaN ] }, _id: 0 } }]); assert.neq(res, null );
    • Query 2019-08-26

    Description

      When $multiply is evaluated, if an expression that evaluates to NaN is encountered first then the pipeline errors with the following message:

      Error: command failed: {
         	"ok" : 0,
         	"errmsg" : "Failed to optimize pipeline :: caused by :: Can't coerce out of range value nan to long",
         	"code" : 31109,
         	"codeName" : "Location31109"
         } : aggregate failed
      

      However if NaN is evaluated second, the command runs and returns results. This means that changing the order of the operands changes whether the command runs or errors, invalidating commutativity.

      Attachments

        Issue Links

          Activity

            People

              anton.korshunov@mongodb.com Anton Korshunov
              claire.childs@mongodb.com Claire Childs (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: