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

Possible Date Precision Bug in 6.0.10

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: Query Execution
    • None
    • Query Execution
    • ALL
    • QE 2023-10-02

      This error came up in our normal BI Connector tdvt waterfall tests.

      If this is an intentional change, we can fix the tests on our end, but there has been a change in date math between 6.0.9 and 6.0.10.

      This is only occurring on 6.0.10, however, while working fine in 6.2 (we are not yet running this test on 7.0).

      I've reduced the test case down here to a fairly minimal query. The sort is just to make the results easier to compare.

      The dataset itself is encoded in the test. $num4 is is a double that is conditionally $floored or $ceil'd and subtracted from the $date0 field, which is a date. I can confirm all the $floor and $ceil calculations are the same between versions, so it's coming down to date $subtract.

      The outputs are differing by .001 second for two of the five documents in the result

        db = connect( 'mongodb://localhost/fullblackbox' )
        printjson(
        db.Calcs.aggregate(
        [{"$project":
        {"date0": 1,
         "num4": 1,
         "out": {"$let": {
                "vars": {"date": {
                            "$subtract": ["$date0",{"$multiply": [
                                {"$cond": {"if": {"$lt": [{"$floor": ["$num4"]},{"$literal": 0.0}]},
                                    "then": {"$ceil": [{"$subtract": [{"$floor": ["$num4"]},0.5]}]},
                                    "else": {"$floor": [{"$add": [{"$floor": ["$num4"]},0.5]}]}}},
                                    {"$literal": NumberInt("86400000")}]}]}},
                "in": {"$cond": {"if": {"$lte": ["$$date",{"$literal": null}]},
                               "then": {"$literal": null},
                               "else": {"$subtract": ["$$date",{"$multiply": [{"$literal": NumberLong("86400")},
                                                               {"$subtract": ["$num4",{"$floor": ["$num4"]}]},{"$literal": NumberInt("1000")}]}]}}}
                }},
         "_id": NumberInt("0")}
        },
        {$sort: {"date0": 1}}
        ]
        )
        ) 

       

      The results for 6.0.9 are:

          1 [
          2   {
          3     num4: 10.85,
          4     date0: ISODate("1972-07-04T00:00:00.000Z"),
          5     out: ISODate("1972-06-23T03:36:00.001Z")
          6   },
          7   {
          8     num4: -13.47,
          9     date0: ISODate("1975-11-12T00:00:00.000Z"),
         10     out: ISODate("1975-11-25T11:16:48.001Z")
         11   },
         12   { num4: null, date0: ISODate("2004-04-15T00:00:00.000Z"), out: null },
         13   {
         14     num4: -6.05,
         15     date0: ISODate("2004-06-04T00:00:00.000Z"),
         16     out: ISODate("2004-06-10T01:12:00.000Z")
         17   },
         18   {
         19     num4: 8.32,
         20     date0: ISODate("2004-06-19T00:00:00.000Z"),
         21     out: ISODate("2004-06-10T16:19:12.000Z")
         22   }
         23 ] 

      While the results for 6.0.10 are:

          1 [
          2   {
          3     num4: 10.85,
          4     date0: ISODate("1972-07-04T00:00:00.000Z"),
          5     out: ISODate("1972-06-23T03:36:00.000Z")
          6   },
          7   {
          8     num4: -13.47,
          9     date0: ISODate("1975-11-12T00:00:00.000Z"),
         10     out: ISODate("1975-11-25T11:16:48.000Z")
         11   },
         12   { num4: null, date0: ISODate("2004-04-15T00:00:00.000Z"), out: null },
         13   {
         14     num4: -6.05,
         15     date0: ISODate("2004-06-04T00:00:00.000Z"),
         16     out: ISODate("2004-06-10T01:12:00.000Z")
         17   },
         18   {
         19     num4: 8.32,
         20     date0: ISODate("2004-06-19T00:00:00.000Z"),
         21     out: ISODate("2004-06-10T16:19:12.000Z")
         22   }
         23 ] 

            Assignee:
            projjal.chanda@mongodb.com Projjal Chanda
            Reporter:
            patrick.meredith@mongodb.com Patrick Meredith
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: