[SERVER-59159] $min/max window function null semantics are different than their accumulator counterparts Created: 06/Aug/21  Updated: 29/Oct/23  Resolved: 22/Oct/21

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 5.2.0, 5.0.4

Type: Bug Priority: Major - P3
Reporter: Nicholas Zolnierz Assignee: Mihai Andrei
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Related
Backwards Compatibility: Minor Change
Operating System: ALL
Backport Requested:
v5.1, v5.0
Steps To Reproduce:

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
Participants:

 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.



 Comments   
Comment by Githook User [ 28/Oct/21 ]

Author:

{'name': 'Mihai Andrei', 'email': 'mihai.andrei@10gen.com', 'username': 'mtandrei'}

Message: SERVER-59159 Update $min/max window functions to ignore null values to match their accumulator counterparts (cherry picked from commit ba83473ade3ee39cd9053ed3b2b3bf3e5f64ba28) (cherry picked from commit 2704db5962489e679e2cc8f3556a0c10482271ad)
Branch: v5.0
https://github.com/mongodb/mongo/commit/c7ef3f7397bece16952c308c5d691189bb05eadb

Comment by Githook User [ 27/Oct/21 ]

Author:

{'name': 'Mihai Andrei', 'email': 'mihai.andrei@10gen.com', 'username': 'mtandrei'}

Message: SERVER-59159 Update $min/max window functions to ignore null values to match their accumulator counterparts

(cherry picked from commit ba83473ade3ee39cd9053ed3b2b3bf3e5f64ba28)
Branch: v5.1
https://github.com/mongodb/mongo/commit/2704db5962489e679e2cc8f3556a0c10482271ad

Comment by Kyle Suarez [ 22/Oct/21 ]

Thanks for verifying!

Comment by Mihai Andrei [ 22/Oct/21 ]

I don't think the documentation needs changing; the page for $min already describes the behavior that this patch implements.

Comment by Kyle Suarez [ 22/Oct/21 ]

mihai.andrei, should we documentation changes as "Needed"?

Comment by Githook User [ 21/Oct/21 ]

Author:

{'name': 'Mihai Andrei', 'email': 'mihai.andrei@10gen.com', 'username': 'mtandrei'}

Message: SERVER-59159 Update $min/max window functions to ignore null values to match their accumulator counterparts
Branch: master
https://github.com/mongodb/mongo/commit/ba83473ade3ee39cd9053ed3b2b3bf3e5f64ba28

Comment by Nicholas Zolnierz [ 06/Aug/21 ]

CC mihai.andrei david.percy

Generated at Thu Feb 08 05:46:31 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.