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

Aggregation Framework does not have referential transparency for function calls

    • Type: Icon: Improvement Improvement
    • Resolution: Duplicate
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: Aggregation Framework
    • None
    • Query

      This is a problem that extends to all functions in the aggregation framework, both those that expect positional arguments in the form of arrays, and those that expect named arguments in the form of objects. Fixing this issue will be fairly labor intensive, and it is not a critical improvement; it just limits the amount of partial redundancy elimination we can do when optimizing pipelines.

      db.foo.aggregate({$project: {out: {$let: {vars: {x: [1,2]}, in: {$add: "$$x"}}}}})
      2019-04-02T14:21:18.263-0400 E QUERY    [js] Error: command failed: {
             "ok" : 0,
             "errmsg" : "$add only supports numeric or date types, not array",
             "code" : 16554,
             "codeName" : "Location16554"
      } : aggregate failed :
      

      This occurs because the parse methods for the individual expressions check for arrays and objects/specific object keys statically before the pipeline runs, so addressing this will also lose us some of our static checking capabilities.

            Assignee:
            backlog-server-query Backlog - Query Team (Inactive)
            Reporter:
            patrick.meredith@mongodb.com Patrick Meredith
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: