[SERVER-82204] Classic window functions first/last handle missing field incorrectly Created: 16/Oct/23  Updated: 30/Oct/23  Resolved: 26/Oct/23

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 7.1.1, 7.2.0-rc0, 6.0.12, 5.0.23, 7.0.4

Type: Bug Priority: Major - P3
Reporter: Foteini Alvanaki Assignee: Rui Liu
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Depends
is depended on by TOOLS-3400 Investigate changes in SERVER-82204: ... Closed
is depended on by COMPASS-7376 Investigate changes in SERVER-82204: ... Closed
Documented
is documented by DOCS-16458 Investigate changes in SERVER-82204: ... Closed
Assigned Teams:
Query Execution
Backwards Compatibility: Minor Change
Operating System: ALL
Backport Requested:
v7.1, v7.0, v6.0, v5.0
Steps To Reproduce:

Dataset

db.missingData.find()
[
  { _id: 1, item: 'cd', price: 7 },
  { _id: 2, item: 'cd', price: 5, quantity: 5 },
  { _id: 3, item: 'cd', price: 2 }
]

Query : 

db.missingData.aggregate([ { $setWindowFields: { partitionBy: "$item", sortBy: { price: 1 }, "output" : {"first" : {$first : "$quantity", window: { } } } } }])

 

Results

[
{ _id: 3, item: 'cd', price: 2 },
{ _id: 2, item: 'cd', price: 5, quantity: 5 },
{ _id: 1, item: 'cd', price: 7 }
]

 

 

Expected Results

[
{ _id: 3, item: 'cd', price: 2, first: null },
{ _id: 2, item: 'cd', price: 5, quantity: 5, first: null },
{ _id: 1, item: 'cd', price: 7, first: null }
]

 

Participants:

 Description   

When the attribute tracked by first/last in the first/last document in the window has a missing attribute the functions return empty results. This is incorrect. According to the documentation they should return null to be consistent with the $group behaviour.



 Comments   
Comment by Githook User [ 26/Oct/23 ]

Author:

{'name': 'Rui Liu', 'email': 'lriuui0x0@gmail.com', 'username': 'lriuui0x0'}

Message: SERVER-82204 Make classic $first/$last window functions generate null on missing input

(cherry picked from commit 26ba1c041a35f74a7ea7f3f436ab011db2599e38)
Branch: v7.1
https://github.com/mongodb/mongo/commit/55a514ccc74fdaf06504de2304956b71fe1293d0

Comment by Githook User [ 26/Oct/23 ]

Author:

{'name': 'Rui Liu', 'email': 'lriuui0x0@gmail.com', 'username': 'lriuui0x0'}

Message: SERVER-82204 Make classic $first/$last window functions generate null on missing input

(cherry picked from commit 26ba1c041a35f74a7ea7f3f436ab011db2599e38)
Branch: v5.0
https://github.com/mongodb/mongo/commit/2a824d7209ad1f74dc91b088eeec9587c24fdac7

Comment by Githook User [ 26/Oct/23 ]

Author:

{'name': 'Rui Liu', 'email': 'lriuui0x0@gmail.com', 'username': 'lriuui0x0'}

Message: SERVER-82204 Make classic $first/$last window functions generate null on missing input

(cherry picked from commit 26ba1c041a35f74a7ea7f3f436ab011db2599e38)
Branch: v7.0
https://github.com/mongodb/mongo/commit/634a38e5398c063964b6b2842beb54f3d00382ac

Comment by Githook User [ 26/Oct/23 ]

Author:

{'name': 'Rui Liu', 'email': 'lriuui0x0@gmail.com', 'username': 'lriuui0x0'}

Message: SERVER-82204 Make classic $first/$last window functions generate null on missing input

(cherry picked from commit 26ba1c041a35f74a7ea7f3f436ab011db2599e38)
Branch: v6.0
https://github.com/mongodb/mongo/commit/48b52a9c374f2fbe76370aff190e1b7395c172de

Comment by Githook User [ 25/Oct/23 ]

Author:

{'name': 'Rui Liu', 'email': 'lriuui0x0@gmail.com', 'username': 'lriuui0x0'}

Message: SERVER-82204 Make classic $first/$last window functions generate null on missing input
Branch: master
https://github.com/mongodb/mongo/commit/26ba1c041a35f74a7ea7f3f436ab011db2599e38

Generated at Thu Feb 08 06:48:32 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.