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

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

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 5.2.0, 5.0.4
    • Affects Version/s: None
    • Component/s: None
    • None
    • Minor Change
    • ALL
    • v5.1, v5.0
    • 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();
    • QE 2021-11-01

      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.

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

              Created:
              Updated:
              Resolved: