You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Giridhar Addepalli <gi...@gmail.com> on 2016/09/01 10:22:38 UTC
Reason for keys parameter to reduce function instead of key
Hi,
Function declaration for reduce functions look like
function(keys, values, rereduce) {
}
My doubt is regarding the 'keys' parameter.
Can multiple keys be passed to single invocation of custom reduce function ?
In Hadoop world, only one key is passed to reduce function along with all
the values against the key.
From what i have read on internet so far, it seems that multiple keys can
be sent to reduce function.
if this is the case, then against which key does the result of reduce
function be assigned to ?
Thanks,
Giridhar.
Re: Reason for keys parameter to reduce function instead of key
Posted by Giridhar Addepalli <gi...@gmail.com>.
Thank you so much Stefan.
Your reply is very helpful.
On Thu, Sep 1, 2016 at 4:09 PM, Stefan Klein <st...@gmail.com> wrote:
> Hi,
>
> 2016-09-01 12:22 GMT+02:00 Giridhar Addepalli <gi...@gmail.com>:
>
> > Hi,
> >
> > Function declaration for reduce functions look like
> >
> > function(keys, values, rereduce) {
> > }
> >
> > My doubt is regarding the 'keys' parameter.
> > Can multiple keys be passed to single invocation of custom reduce
> function
> > ?
> >
>
> Yes. Each key corresponds to the value of the same index.
> The keys could be same but could also differ if the view was queried with a
> grouplevel.
>
> e.g. you have 3 documents, the view emits the keys:
> [1,2,3]
> [1,2,4]
> [1,3,5]
>
> if you call the view with "group_level" = 1, reduce will be called once¹
> and keys² will be:
> [
> [[1,2,3], documentid],
> [[1,2,4], documentid],
> [[1,3,5], documentid]
> ]
>
> the result is assigned to "[1]"
>
> if you call the view with "group_level" = 2, reduce will be called twice¹
> and keys² will be:
> [
> [[1,2,3], documentid],
> [[1,2,4], documentid]
> ]
>
> this result is assigned to "[1,2]"
>
> and
> [
> [[1,3,5], documentid]
> ]
>
> this result is assigned to "[1,3]"
>
>
> Hope this helps,
> Stefan
>
>
> [1]: ignoring rereduce
> [2]: CouchDB 1.6.1 here
>
Re: Reason for keys parameter to reduce function instead of key
Posted by Stefan Klein <st...@gmail.com>.
Hi,
2016-09-01 12:22 GMT+02:00 Giridhar Addepalli <gi...@gmail.com>:
> Hi,
>
> Function declaration for reduce functions look like
>
> function(keys, values, rereduce) {
> }
>
> My doubt is regarding the 'keys' parameter.
> Can multiple keys be passed to single invocation of custom reduce function
> ?
>
Yes. Each key corresponds to the value of the same index.
The keys could be same but could also differ if the view was queried with a
grouplevel.
e.g. you have 3 documents, the view emits the keys:
[1,2,3]
[1,2,4]
[1,3,5]
if you call the view with "group_level" = 1, reduce will be called once¹
and keys² will be:
[
[[1,2,3], documentid],
[[1,2,4], documentid],
[[1,3,5], documentid]
]
the result is assigned to "[1]"
if you call the view with "group_level" = 2, reduce will be called twice¹
and keys² will be:
[
[[1,2,3], documentid],
[[1,2,4], documentid]
]
this result is assigned to "[1,2]"
and
[
[[1,3,5], documentid]
]
this result is assigned to "[1,3]"
Hope this helps,
Stefan
[1]: ignoring rereduce
[2]: CouchDB 1.6.1 here