couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Devon Weller <dwel...@devonweller.com>
Subject Aggregate Sum Example is Broken
Date Thu, 05 Nov 2009 19:51:55 GMT
Hi.

I believe the aggregate sum example in the couchdb wiki does not work  
in CouchDB 0.10.


I am trying to implement the view snippet as shown on this page:

http://wiki.apache.org/couchdb/View_Snippets#aggregate_sum


Here is my database:

[
{"_id":"1","Type":"customer","name":"user1","address":"123 Somewhere  
St.","zip":"12345"},
{"_id":"2","Type":"customer","name":"user2","address":"456 Somewhere  
St.","zip":"23456"},
{"_id":"3","Type":"order","customer_id":"1"},
{"_id":"4","Type":"order","customer_id":"1"}
]

(ids shortened for clearer understanding)


Here is the map function:


function(doc) {
   if (doc.Type == "customer") {
     emit([doc._id, 0], doc);
   } else if (doc.Type == "order") {
     emit([doc.customer_id, 1], doc);
   }
}



Here is the reduce function:

// Reduce function
// Only produces meaningful output.customer_details if group_level >= 1
function(keys, values, rereduce) {
   var output = {};
   if (rereduce) {
     for (idx in values) {
       if (values[idx].total !== undefined) {
         output.total += values[idx].total;
       } else if (values[idx].customer_details !== undefined) {
         output.customer_details = values[idx].customer_details;
       }
     }
   } else {
     for (idx in values) {
       if (values[idx].Type == "customer") output.customer_details =  
values[idx];
       else if (values[idx].Type == "order") output.total += 1;
     }
   }
   return output;
}
// note that I made one correction at "output.customer_details = values 
[idx];"




When I call:

http://localhost:5984/mydb/_design/mydb/_view/aggregate_sum?group_level=1

I get this error:

{"error":"reduce_overflow_error","reason":"Reduce output must shrink  
more rapidly: Current output: '[{\"customer_details\": {\"_id\":  
\"1656635ff2687c1d5ef0dd799e74aaf9\",\"_rev\":  
\"1-652a40bc314cda302d9faf1b'... (first 100 of 207 bytes)"}



My question is this:

Should this example work and couchdb is broken?  Or is the example bad?


I am running CouchDBX-0.10.0-R13B02-64bit-Snow-Leopard.

Thanks,
- Devon

Mime
View raw message