couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jan Lehnardt <...@apache.org>
Subject Re: Map Reduce aggregate queries
Date Wed, 30 Apr 2008 11:06:09 GMT

On Apr 30, 2008, at 04:36, Jason Eggleston wrote:
> Hello,
>
> I recently tried explaining the power of map / reduce to someone,
> using a simple example of adding up hours spent on a project over a
> period of time.
>
> The output of the mapping function would be:
>
> key, value
>
> 4/28/2008, 1
> 4/28/2008, 4
> 4/29/2008, 7
> 4/29/2008, 3
> ...
>
> The output of the reduce function would be:
>
> key, value
>
> 4/28/2008, 5
> 4/29/2008, 10
> ...
> etc.
>
> Shouldn't I then be able to issue a query for an arbitrary summation
> of some sequential portion of the output of reduce?  For example, a
> sum of all of the hours between two dates / keys?  It's the same
> reduction function except applied across multiple keys, it could be
> annotated in the b-tree index the same way the reduction per key is
> done now (or will be done).
>
> /db/_view/sum_hours/count? 
> start_combine=4/28/2008&end_combine=4/29/2009
>
> If it isn't safe to use the reduce function as the combine function,
> it could be explicit:
>
> "views": {
>
>             "all": "function (doc) {...snip...}",
>
>             "count": {
>
>                           "map": "function (doc){...snip...}"
>
>                           "reduce": "function (tag, counts) 
> {...snip...}"
>
>                           "combine": "function (counts){...snip...}"
>
>                           }
>
>             }
>
> }
>
> It seems very powerful to me, if this functionality were available.

If understand Damien's "whitepaper(s)" correctly, the implementation
of our reduce would be functionally equivalent to the combine you
ask for. What I haven't seen is how to run reduce again on its own
output. Damien?

See http://damienkatz.net/2008/02/incremental_map.html
http://damienkatz.net/2008/02/incremental_map_1.html and the
comments for details.


Cheers
Jan
--

Mime
View raw message