[SERVER-55124] $derivative should return null on a 1-element window Created: 10/Mar/21  Updated: 27/Oct/23  Resolved: 21/Apr/21

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

Type: Task Priority: Major - P3
Reporter: David Percy Assignee: David Percy
Resolution: Gone away Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Sprint: Query Optimization 2021-04-05, Query Optimization 2021-04-19, Query Optimization 2021-05-03
Participants:

 Description   

Currently I don't think it handles this case specially, so it would divide 0/0 and return NaN.



 Comments   
Comment by David Percy [ 21/Apr/21 ]

Looks like I was mistaken about this:

> db.c.find()
{ "_id" : ObjectId("6080461f7171ef8654d5eabe"), "t" : 1.5 }
> db.c.aggregate({$setWindowFields: {
    sortBy: {t: 1}, 
    output: {
        v: {$derivative: {input: "$t"},
             window: {range: ['unbounded', 'unbounded']}}
    }
  }})
{ "_id" : ObjectId("6080461f7171ef8654d5eabe"), "t" : 1.5, "v" : null }

I thought {$divide: [0.0, 0.0]} would be NaN, but it's an error, which $derivative handles.

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