You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Scott Robertson <sc...@zeepmobile.com> on 2008/12/31 23:48:23 UTC
group_level and intermediate reduce results
I think I understand how group_level works. Is there a way to get the
results of multiple levels with one get?
For example say I'm creating a view that counts how many documents a
member has created and how many docs all the members of each group has
created. Using a two part key.
My map would look something like this
function(doc){
emit([doc.group, doc.member], 1);
}
And my reduce sums the values
function(keys, values){
return sum(values);
}
I can get the counts for each member like this
http://localhost:5984/mydb/_view/sums/all?group_level=2
Which return something like
key | value
==================================
[group1,member1] | 5
[group1,member2] | 3
[group1,member3] | 1
[group2,member4] | 1
And I can get the sums for each group
http://localhost:5984/mydb/_view/sums/all?group_level=1
key | value
==================================
[group1] | 9
[group2] | 1
Is there away that I can request those values merged, so that it looks
like this?
key | value
==================================
[group1] | 9
[group1,member1] | 5
[group1,member2] | 3
[group1,member3] | 1
[group2] | 1
[group2,member4] | 1
W/o having to make two separate requests?
Re: group_level and intermediate reduce results
Posted by Scott Robertson <sr...@codeit.com>.
>
> If you have the results of group_level=2 for a range you can calculate
> the group_level=1 results trivially on the client.
>
>
True it's trivial with the example I gave, that's because I gave a
trivial example. My actual reduction is more complex. I'd rather not
have to maintain two separate code bases if possible.
Re: group_level and intermediate reduce results
Posted by Chris Anderson <jc...@gmail.com>.
>> I can get the counts for each member like this
>> http://localhost:5984/mydb/_view/sums/all?group_level=2
>>
>> Which return something like
>>
>> key | value
>> ==================================
>> [group1,member1] | 5
>> [group1,member2] | 3
>> [group1,member3] | 1
>> [group2,member4] | 1
>>
>> And I can get the sums for each group
>> http://localhost:5984/mydb/_view/sums/all?group_level=1
>>
>> key | value
>> ==================================
>> [group1] | 9
>> [group2] | 1
>>
>> Is there away that I can request those values merged, so that it looks
>> like this?
>>
>> key | value
>> ==================================
>> [group1] | 9
>> [group1,member1] | 5
>> [group1,member2] | 3
>> [group1,member3] | 1
>> [group2] | 1
>> [group2,member4] | 1
>>
>> W/o having to make two separate requests?
If you have the results of group_level=2 for a range you can calculate
the group_level=1 results trivially on the client.
--
Chris Anderson
http://jchris.mfdz.com
Re: group_level and intermediate reduce results
Posted by Paul Davis <pa...@gmail.com>.
On Wed, Dec 31, 2008 at 5:48 PM, Scott Robertson <sc...@zeepmobile.com> wrote:
> I think I understand how group_level works. Is there a way to get the
> results of multiple levels with one get?
>
> For example say I'm creating a view that counts how many documents a
> member has created and how many docs all the members of each group has
> created. Using a two part key.
>
> My map would look something like this
>
> function(doc){
> emit([doc.group, doc.member], 1);
> }
>
> And my reduce sums the values
>
> function(keys, values){
> return sum(values);
> }
>
> I can get the counts for each member like this
> http://localhost:5984/mydb/_view/sums/all?group_level=2
>
> Which return something like
>
> key | value
> ==================================
> [group1,member1] | 5
> [group1,member2] | 3
> [group1,member3] | 1
> [group2,member4] | 1
>
> And I can get the sums for each group
> http://localhost:5984/mydb/_view/sums/all?group_level=1
>
> key | value
> ==================================
> [group1] | 9
> [group2] | 1
>
> Is there away that I can request those values merged, so that it looks
> like this?
>
> key | value
> ==================================
> [group1] | 9
> [group1,member1] | 5
> [group1,member2] | 3
> [group1,member3] | 1
> [group2] | 1
> [group2,member4] | 1
>
> W/o having to make two separate requests?
>
No, not at the moment. The way the group_level is implemented you'd
basically need to fold over the view twice or make that work.