as I always have trouble imagining the results of a some reduce function with group_level and stuff alike, I made this app for quickly simulating these things: http://fiatjaf.github.io/couchdb-mr-simulator/
here's the same simulation Aurélien did: http://fiatjaf.github.io/couchdb-mr-simulator/#{%22params%22:%22reduceFn:%20_count\nreduce:%20true\ngroup:%20true\ngroup_level:%202\nstartkey:%20[2013]\nendkey:%20[2014,%20{}]%22,%22emitted%22:%222012,%20\%22A\%22\n2012,%20\%22B\%22\n2012,%20\%22C\%22\n2013,%20\%22A\%22\n2013,%20\%22A\%22\n2013,%20\%22A\%22\n2013,%20\%22C\%22\n2014,%20\%22A\%22\n2014,%20\%22A\%22\n2014,%20\%22B\%22%22} <http://fiatjaf.github.io/couchdb-mr-simulator/#%7B%22params%22:%22reduceFn:%20_count%5Cnreduce:%20true%5Cngroup:%20true%5Cngroup_level:%202%5Cnstartkey:%20[2013]%5Cnendkey:%20[2014,%20%7B%7D]%22,%22emitted%22:%222012,%20%5C%22A%5C%22%5Cn2012,%20%5C%22B%5C%22%5Cn2012,%20%5C%22C%5C%22%5Cn2013,%20%5C%22A%5C%22%5Cn2013,%20%5C%22A%5C%22%5Cn2013,%20%5C%22A%5C%22%5Cn2013,%20%5C%22C%5C%22%5Cn2014,%20%5C%22A%5C%22%5Cn2014,%20%5C%22A%5C%22%5Cn2014,%20%5C%22B%5C%22%22%7D> On Sun, Oct 5, 2014 at 9:05 AM, Aurélien Bénel <[email protected]> wrote: > > Thanks Aurélien for a better explanation of my problem :-) > > Good to hear :) > > For the additional computation step, you can: > > 1. switch to CloudAnt's BigCouch to get chained mapreduce > http://examples.cloudant.com/sales/_design/sales/index.html > > 2. or wait for BigCouch integration into Apache CouchDB (in version 2.0) > https://issues.apache.org/jira/browse/COUCHDB/fixforversion/12315572 > > 3. or "cheat" and do it with a list. > > > Regards, > > Aurélien > > > >>>> I need to filter by date and group by group... > >>> You can use the second with group_level=1 and get all the groups at the > >> same time. And you can use _count > >> > >> > >> I'm afraid this is not so easy... > >> Using a filter by date will also *group* by date. > >> > >> Let's take a very simple example... > >> > >> Here are keys emitted by a map: > >> [2012, 'A'] > >> [2012, 'B'] > >> [2012, 'C'] > >> [2013, 'A'] > >> [2013, 'A'] > >> [2013, 'A'] > >> [2013, 'C'] > >> [2014, 'A'] > >> [2014, 'A'] > >> [2014, 'B'] > >> > >> If we query it with `_count` as the reduce function, `group=true`, > >> `startkey=[2013]` and `endkey=[2014,{}]`, we'll get: > >> [2013, 'A'] -> 3 > >> [2013, 'C'] -> 1 > >> [2014, 'A'] -> 2 > >> [2014, 'B'] -> 1 > >> > >> Boaz will need additional computation to get: > >> 'A' -> 5 > >> 'B' -> 1 > >> 'C' -> 1 > >> > >> > >> Regards, > >> > >> Aurélien > >
