As I understand the reduce function takes all the values of a particular key and we can write code to perform some kind of action on those values. I do not understand what is the use of the rereduce parameter. Can somebody explain with an example?
Thanks...
As I understand the reduce function takes all the values of a particular key and we can write code to perform some kind of action on those values. I do not understand what is the use of the rereduce parameter. Can somebody explain with an example?
Thanks...
Share Improve this question edited Mar 30, 2012 at 3:12 aaaidan 7,3468 gold badges68 silver badges107 bronze badges asked Mar 29, 2012 at 21:13 ManojManoj 5,09714 gold badges56 silver badges77 bronze badges2 Answers
Reset to default 8I think http://wiki.apache/couchdb/Introduction_to_CouchDB_views#Reduce_vs_rereduce gives you an good overview. Due to performance optimations, the reduce function may be called on two levels:
- to reduce a block
- to reduce results of the first step
In the second level, the parameter rereduce
is true
. For an example see http://wiki.apache/couchdb/Built-In_Reduce_Functions#A_sum. In the first step the length of the block (values
) is returned, on the rereduce level these lengths must be summed up.
There's an explanation of the rereduce parameter here.
Quote: paraphrased. More info at the link.
Here is an example of a reduce function:
function (key, values, rereduce) { return sum(values); }
Reduce functions must handle two cases, when rereduce is true and when it is false.