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

project and setWindowFields accepts "continuous" and "discrete" values.

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 7.1.0-rc0, 7.0.0-rc4
    • Affects Version/s: 7.0.0-rc1
    • Component/s: None
    • Labels:
      None
    • Fully Compatible
    • OS X
    • v7.0
    • QI 2023-06-12

      I’ve been experimenting with different ‘method’ values as mentioned in the design documentation. I tested different values for the method parameter in the  $group stage using the following code snippet:

      test.aggregate( [
        {
          $group: {
            _id: "$t",
            Percentile: {
              $percentile: {
                p: [
                  0.9
                ],
                method: "discrete",
                input: "$a"
              }
            }
          }
        }
      ]) 

      For both ‘continuous’ and ‘discrete’ values, I received the error message{} 'MongoServerError: Currently only approximate percentiles are supported'.

      As I understand it, this aligns with the comment in the design documentation provided here “https://docs.google.com/document/d/1NVQ6hiD3rvt03Eegb9JZj5mtWMHnX1ueumAbejwdOWY/edit?disco=AAAAvPx8do4”. It seems that only ‘approximate’ is supported as of now.

      However, I noticed that when I used the $project stage with 'continuous', 'discrete' and 'approximate' values, they all worked fine if I used a field reference in the input parameter. Here’s an example:

      test.aggregate([
        {
          $project: {
            percentile: {
              $percentile: {
                input: $a,
                p: [
                  0.5,
                  0.9,
                  0.95
                ],
                method: "continuous"
              }
            }
          }
        }
      ]) 

      The same with $setWindowFields stage, it supports all three methods without any issues. For example:

      test.aggregate( {
        $setWindowFields: {
          partitionBy: "$t",
          sortBy: {
            t: 1
          },
          output: {
            sat_p95: {
              $percentile: {
                input: "$a",
                p: [
                  0.95
                ],
                method: "continuous"
              },
              window: {
                documents: [
                  -1,
                  0
                ]
              }
            }
          }
        }
      }) 

      Collection test data: 

      [
        { _id: ObjectId("6477bc4707718501f4056fab"), t: 0, a: 1 },
        { _id: ObjectId("6477bc4707718501f4056fac"), t: 0, a: 2 },
        { _id: ObjectId("6477bc4707718501f4056fad"), t: 1, a: 2 },
        { _id: ObjectId("6477bc4707718501f4056fae"), t: 1, a: 4 },
        { _id: ObjectId("6477bc4707718501f4056faf"), t: 1, a: 5 },
        { _id: ObjectId("6477bc4707718501f4056fb0"), t: 1, a: 6 },
        { _id: ObjectId("6477bc4707718501f4056fb1"), t: 1, a: 4 },
        { _id: ObjectId("6477bc4707718501f4056fb2"), t: 1, a: 1 },
        { _id: ObjectId("6477bc4707718501f4056fb3"), t: 1, a: 2 },
        { _id: ObjectId("6477bc4707718501f4056fb4"), t: 1, a: 3 },
        { _id: ObjectId("6477bc4707718501f4056fb5"), t: 1, a: 1 },
        { _id: ObjectId("6477bc4707718501f4056fb6"), t: 1, a: 100 }
      ] 

            Assignee:
            irina.yatsenko@mongodb.com Irina Yatsenko (Inactive)
            Reporter:
            slav.babanin@mongodb.com Slav Babanin
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: