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

Error when deciding whether documents are inside a window in classic

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 8.1.0-rc0, 7.3.4, 8.0.0-rc10, 7.0.13
    • Affects Version/s: None
    • Component/s: None
    • None
    • Query Execution
    • Fully Compatible
    • ALL
    • v8.0, v7.3, v7.0, v6.0
    • QE 2024-06-10, QE 2024-06-24
    • 200

      When we compute the threshold we convert both values to Decimal128 and the threshold is Decimal128. However, when we decide whether a document is inside the window we use the original value which is of type double and compare it against the Decimal128 threshold. This comparison gives wrong results and the current document is considered to be outside of the window. Thus, we try to remove from the window a document that was never added to it.

      The issue can be reproduced using the following example

      Data

      [
          {_id: 0, time: new Date("2023-07-01T20:53:50.932Z"), "str": "ric"},
          {_id: 1, time: new Date("2023-07-02T20:57:42.383Z"), "str": "alc"},
          {_id: 2, time: new Date("2023-07-04T01:39:14.265Z"), "str": ""},
          {_id: 3, time: new Date("2023-07-04T04:01:29.983Z"), "str": "ric"},
          {_id: 4, time: new Date("2023-07-05T15:08:22.541Z"), "str": ""},
          {_id: 5, time: new Date("2023-07-05T22:56:30.949Z"), "str": ""},
      ]
      

      Query

      [
          {
              $setWindowFields:
                  {partitionBy: "$str", sortBy: {"any": -1}, output: {"num": {$sum: {$pow: [9, 20]}}}}
          },
          {
              $setWindowFields:
                  {sortBy: {"num": 1},
                   output: {"res": {$max: "$num", window: {range: [-4, "current"]}}}}
          }
      ]
      

            Assignee:
            foteini.alvanaki@mongodb.com Foteini Alvanaki
            Reporter:
            foteini.alvanaki@mongodb.com Foteini Alvanaki
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: