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

Handle non "neutral" init functions in $accumulator

    • Type: Icon: Improvement Improvement
    • Resolution: Won't Fix
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None
    • Query Execution
    • 45

      $accumulator allows users to specify their own accumulator using JavaScript.

      It has several functions. We will focus on this three:

      init - created a new group (may use group id as arguments).
      accumulate - adds a new document to the group.
      merge - merges two groups (in case of sharding or spilling).

      Currently our code assumes that we can call init() any number of times.

      For example, consider group of two documents.

      If there is no spilling, we will call the following functions:

      init() -> accumulate() -> accumulate()
      

      However, if we spill after each document, we will have the following sequence of calls:

      init() -> accumulate() -> /spill/ -> init() -> accumulate() -> /spill/ -> init() -> merge() -> merge().
      

      If init() doesn't return a neutral element in relation to accumulate() and merge(), we are in trouble.

      In this ticket we should discuss how we want to handle this case: either assert init is correct and provide users with a comprehensive error message or re-design $accumulator to call init exactly once.

      We also should note our decision in documentation to be more explicit.

            Assignee:
            backlog-query-execution [DO NOT USE] Backlog - Query Execution
            Reporter:
            ivan.fefer@mongodb.com Ivan Fefer
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: