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

N from MaxN not accepting max uint64 , likely the same for the other "TopN" functions

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None
    • Query Execution
    • ALL
    • Hide

      Repro steps

      Using the schema defined in the testfile

      jstests/aggregation/accumulators/min_n_max_n.js

       

      Do this 

      coll.aggregate([ {$group: {_id: '$state', maxSales: {$maxN: {output: '$sales', n: NumberDecimal("18446744073709551615")}}}}, {$sort: {_id: 1}} ])
      uncaught exception: Error: command failed:

      { "ok" : 0, "errmsg" : "PlanExecutor error during aggregation :: caused by :: Value for 'n' must be of integral type, but found 18446744073709551615", "code" : 5787903, "codeName" : "Location5787903" }

      with original command request: {
      "aggregate" : "min_n_max_n",
      "pipeline" : [
      {
      "$group" : {
      "_id" : "$state",
      "maxSales" : {
      "$maxN" :

      { "output" : "$sales", "n" : NumberDecimal("18446744073709551615") }

      }
      }
      },
      {
      "$sort" :

      { "_id" : 1 }

      }
      ],
      "cursor" : {

      },
      "lsid" :

      { "id" : UUID("36f8c6e2-3d73-49e0-9729-87a97454392f") }

      } on connection: connection to 127.0.0.1:27017 : aggregate failed :
      _getErrorWithCode@src/mongo/shell/utils.js:24:13
      doassert@src/mongo/shell/assert.js:18:14
      _assertCommandWorked@src/mongo/shell/assert.js:737:17
      assert.commandWorked@src/mongo/shell/assert.js:829:16
      DB.prototype._runAggregate@src/mongo/shell/db.js:280:5
      DBCollection.prototype.aggregate@src/mongo/shell/collection.js:970:12
      @(shell):1:1
      >

       

      If I use max signed int64, I don't get the error, but if I add 1 to it, I get back the error.

      coll.aggregate([ {$group: {_id: '$state', maxSales: {$maxN: {output: '$sales', n: NumberDecimal("9223372036854775807")}}}}, {$sort: {_id: 1}} ])

      { "_id" : "CA", "maxSales" : [ 1000, 900, 800, 700, 600, 500, 400, 300, 200, 100 ] } { "_id" : "NY", "maxSales" : [ 700, 600, 500, 400, 300, 200, 100 ] } { "_id" : "TX", "maxSales" : [ 400, 300, 200, 100 ] }

      > coll.aggregate([ {$group: {_id: '$state', maxSales: {$maxN: {output: '$sales', n: NumberDecimal("9223372036854775808")}}}}, {$sort: {_id: 1}} ])
      uncaught exception: Error: command failed:

      { "ok" : 0, "errmsg" : "PlanExecutor error during aggregation :: caused by :: Value for 'n' must be of integral type, but found 9223372036854775808", "code" : 5787903, "codeName" : "Location5787903" }

      with original command request: {
      "aggregate" : "min_n_max_n",
      "pipeline" : [
      {
      "$group" : {
      "_id" : "$state",
      "maxSales" : {
      "$maxN" :

      { "output" : "$sales", "n" : NumberDecimal("9223372036854775808") }

      }
      }
      },
      {
      "$sort" :

      { "_id" : 1 }

      }
      ],
      "cursor" : {

      },
      "lsid" :

      { "id" : UUID("36f8c6e2-3d73-49e0-9729-87a97454392f") }

      } on connection: connection to 127.0.0.1:27017 : aggregate failed :
      _getErrorWithCode@src/mongo/shell/utils.js:24:13
      doassert@src/mongo/shell/assert.js:18:14
      _assertCommandWorked@src/mongo/shell/assert.js:737:17
      assert.commandWorked@src/mongo/shell/assert.js:829:16
      DB.prototype._runAggregate@src/mongo/shell/db.js:280:5
      DBCollection.prototype.aggregate@src/mongo/shell/collection.js:970:12
      @(shell):1:1
      >

      Show
      Repro steps Using the schema defined in the testfile jstests/aggregation/accumulators/min_n_max_n.js   Do this  coll.aggregate([ {$group: {_id: '$state', maxSales: {$maxN: {output: '$sales', n: NumberDecimal("18446744073709551615")}}}}, {$sort: {_id: 1}} ]) uncaught exception: Error: command failed: { "ok" : 0, "errmsg" : "PlanExecutor error during aggregation :: caused by :: Value for 'n' must be of integral type, but found 18446744073709551615", "code" : 5787903, "codeName" : "Location5787903" } with original command request: { "aggregate" : "min_n_max_n", "pipeline" : [ { "$group" : { "_id" : "$state", "maxSales" : { "$maxN" : { "output" : "$sales", "n" : NumberDecimal("18446744073709551615") } } } }, { "$sort" : { "_id" : 1 } } ], "cursor" : { }, "lsid" : { "id" : UUID("36f8c6e2-3d73-49e0-9729-87a97454392f") } } on connection: connection to 127.0.0.1:27017 : aggregate failed : _getErrorWithCode@src/mongo/shell/utils.js:24:13 doassert@src/mongo/shell/assert.js:18:14 _assertCommandWorked@src/mongo/shell/assert.js:737:17 assert.commandWorked@src/mongo/shell/assert.js:829:16 DB.prototype._runAggregate@src/mongo/shell/db.js:280:5 DBCollection.prototype.aggregate@src/mongo/shell/collection.js:970:12 @(shell):1:1 >   If I use max signed int64, I don't get the error, but if I add 1 to it, I get back the error. coll.aggregate([ {$group: {_id: '$state', maxSales: {$maxN: {output: '$sales', n: NumberDecimal("9223372036854775807")}}}}, {$sort: {_id: 1}} ]) { "_id" : "CA", "maxSales" : [ 1000, 900, 800, 700, 600, 500, 400, 300, 200, 100 ] } { "_id" : "NY", "maxSales" : [ 700, 600, 500, 400, 300, 200, 100 ] } { "_id" : "TX", "maxSales" : [ 400, 300, 200, 100 ] } > coll.aggregate([ {$group: {_id: '$state', maxSales: {$maxN: {output: '$sales', n: NumberDecimal("9223372036854775808")}}}}, {$sort: {_id: 1}} ]) uncaught exception: Error: command failed: { "ok" : 0, "errmsg" : "PlanExecutor error during aggregation :: caused by :: Value for 'n' must be of integral type, but found 9223372036854775808", "code" : 5787903, "codeName" : "Location5787903" } with original command request: { "aggregate" : "min_n_max_n", "pipeline" : [ { "$group" : { "_id" : "$state", "maxSales" : { "$maxN" : { "output" : "$sales", "n" : NumberDecimal("9223372036854775808") } } } }, { "$sort" : { "_id" : 1 } } ], "cursor" : { }, "lsid" : { "id" : UUID("36f8c6e2-3d73-49e0-9729-87a97454392f") } } on connection: connection to 127.0.0.1:27017 : aggregate failed : _getErrorWithCode@src/mongo/shell/utils.js:24:13 doassert@src/mongo/shell/assert.js:18:14 _assertCommandWorked@src/mongo/shell/assert.js:737:17 assert.commandWorked@src/mongo/shell/assert.js:829:16 DB.prototype._runAggregate@src/mongo/shell/db.js:280:5 DBCollection.prototype.aggregate@src/mongo/shell/collection.js:970:12 @(shell):1:1 >

      External Impact:
      We expect user be able to provide max uint64 as N in MaxN and other function of the same family, but that returns an error.  It appears we can only go up to max signed int64

            Assignee:
            backlog-query-execution [DO NOT USE] Backlog - Query Execution
            Reporter:
            steve.la@mongodb.com Steve La (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: