couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mark J. Reed" <markjr...@gmail.com>
Subject Re: Testing map/reduce functions
Date Mon, 13 Sep 2010 15:49:59 GMT
On Mon, Sep 13, 2010 at 11:08 AM, PaweĊ‚ Stawicki
<pawelstawicki@gmail.com> wrote:
> You can take a look on my blog post:
> http://pawelstawicki.blogspot.com/2009/12/couchdb.html
> At the end are reduce parameters explained.

Nitpick: this reduce call given in your post is invalid:

> function(["developer", "manager", "administrator"], [17, 4, 2], true);

Because when rereduce is true, the first parameter (keys) is presumably null.

Basically, a map function emits a (key, value) pair; the plumbing
automatically adds the document id that was being processed when the
pair was emitted, so what you get out of the map phase is essentially
a bunch of triples: (key1, value1, document1), (key2, value2,
document2), etc.

The reduce function, pre-rereduce, gets some subset of those triples,
slightly re-organized.  A single call to reduce might look like this:

reduce([[key1, document1], [key2, document2], [value1, value2], false)

Unlike classical map/reduce, the reduce function is not guaranteed to
get all of the values associated with a given key.  Nonetheless, it is
expected to return a single result value (which may be a complex value
like an array or object).

The results of the reduce function may be passed back into another
reduce pass.  In this case, there are no keys, values, or documents,
just a single array of results from a previous call to the same reduce
function.

reduce(null, [reduced1, reduced2, reduced3], true)

-
Mark J. Reed <markjreed@gmail.com>

Mime
View raw message