couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Couchdb Wiki] Update of "Introduction to CouchDB views" by JedediahSmith
Date Mon, 01 Dec 2008 10:57:35 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Couchdb Wiki" for change notification.

The following page has been changed by JedediahSmith:
http://wiki.apache.org/couchdb/Introduction_to_CouchDB_views

The comment on the change is:
expand 'Reduce Functions'

------------------------------------------------------------------------------
  
  === Reduce Functions ===
  
- '''This section is only a stub.  Please help by expanding it.'''
+ If a view has a reduce function, it is used to produce aggregate results for that view.
A reduce function is passed a set of intermediate values and combines them to a single value.
Reduce functions must accept, as input, results emitted by its corresponding map function
'''as well as results returned by the reduce function itself'''. The latter case is referred
to as a ''rereduce''.
  
  Here is an example of a reduce function:
  
  {{{
- function (keys, values, combine) {
+ function (keys, values, rereduce) {
      return sum(values);
  }
  }}}
  
- Reduce functions should return a single scalar value.
+ Reduce functions are passed three arguments in the order ''keys'', ''values'' and ''rereduce''
+ 
+ Reduce functions must handle two cases:
+ 
+ 1. When ''rereduce'' is ''false'':
+  * ''keys'' will be an array whose elements are arrays of the form ''[key,id]'', where ''key''
is a key emitted by the map function and ''id'' is that of the document from which the key
was generated. 
+  * ''values'' will be an array of the values emitted for the respective elements in ''keys''
+ 2. When ''rereduce'' is ''true'':
+  * ''keys'' will be ''null''
+  * ''values'' will be an array of values returned by previous calls to the reduce function
+ 
+ Reduce functions should return a single value, suitable for both the ''value'' field of
the final view and as a member of the ''values'' array passed to the reduce function.
+ 
+ Often, reduce functions can be written to handle rereduce calls without any extra code,
like the summation function above. In that case, the ''rereduce'' argument can be ignored
and in JavaScript, it can be omitted from the function definition entirely.
  
  == Lookup Views ==
  
@@ -115, +128 @@

  
  Keys are not limited to simple values. You can use arbitrary JSON values to influence sorting.
See ViewCollation for the rules.
  
+ When the key is an array, view results can be grouped by a sub-section of the key. For example,
if keys have the form [''year'', ''month'', ''day''] then results can be reduced to a single
value or by year, month, or day. See HttpViewApi for more information.
+ 
  == Views in Practice ==
  
  See HttpViewApi to learn how to work with views.

Mime
View raw message