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

$min/max window function null semantics are different than their accumulator counterparts

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 5.2.0
    • Component/s: None
    • Labels:
      None
    • Backwards Compatibility:
      Minor Change
    • Operating System:
      ALL
    • Backport Requested:
      v5.1, v5.0
    • Steps To Reproduce:
      Hide

      coll.drop();
      coll.insert([{a: 1}, {a: null}]);
      let results =
          coll.aggregate([
                  {
                      $setWindowFields: {
                          sortBy: {a: 1},
                          output: {
                              docs: {$push: "$a", window: {documents: [-1, 1]}},
                              min: {$min: "$a", window: {documents: [-1, 1]}},
                          }
                      }
                  }
              ])
              .toArray();
      

      Show
      coll.drop(); coll.insert([{a: 1}, {a: null}]); let results = coll.aggregate([ { $setWindowFields: { sortBy: {a: 1}, output: { docs: {$push: "$a", window: {documents: [-1, 1]}}, min: {$min: "$a", window: {documents: [-1, 1]}}, } } } ]) .toArray();
    • Sprint:
      QE 2021-11-01

      Description

      The $min/max accumulators specifically throw out nullish values, whereas they are kept in a multiset for window functions. The behavior may end up being correct for $max since nulls will generally sort before other types, but for $min we will always return null.

        Attachments

          Activity

            People

            Assignee:
            mihai.andrei Mihai Andrei
            Reporter:
            nicholas.zolnierz Nicholas Zolnierz
            Participants:
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: