flimzy commented on a change in pull request #279: Expand docs on builtin 
reducers, add _approx_count_distinct
URL: 
https://github.com/apache/couchdb-documentation/pull/279#discussion_r191262164
 
 

 ##########
 File path: src/ddocs/ddocs.rst
 ##########
 @@ -166,6 +184,82 @@ JavaScript:
         }
     }
 
+The ``_stats`` function will also work with "pre-aggregated" values from a map
+phase. A map function that emits an object containing ``sum``, ``min``, 
``max``,
+``count``, and ``sumsqr`` keys and numeric values for each can use the
+``_stats`` function to combine these results with the data from other 
documents.
+The emitted object may contain other keys (these are ignored by the reducer),
+and it is also possible to mix raw numeric values and pre-aggregated objects
+in a single view and obtain the correct aggregated statistics.
+
+Finally, ``_stats`` can operate on key-value pairs where each value is an array
+comprised of numbers or pre-aggregated objects. In this case **every** value
+emitted from the map function must be an array, and the arrays must all be the
+same length, as ``_stats`` will compute the statistical quantities above
+*independently* for each element in the array. Users who want to compute
+statistics on multiple values from a single document should either ``emit`` 
each
+value into the index separately, or compute the statistics for the set of 
values
+using the JavaScript example above and emit a pre-aggregated object.
+
+.. data:: _sum
+
+In it simplest variation, ``_sum`` sums the numeric values associated with each
+key, as in the following JavaScript:
+
+.. code-block:: javascript
+
+    // could be replaced by _sum
+    function(keys, values) {
+        return sum(values);
+    }
+
+As with ``_stats``, the ``_sum`` function offers a number of extended
+capabilities. The _sum function requires that map values be numbers, arrays of
 
 Review comment:
   Missing double quotes around `_sum` on this line.
   
       capabilities. The ``_sum`` function ...

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to