You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@couchdb.apache.org by "Robert Newson (JIRA)" <ji...@apache.org> on 2012/07/30 15:38:34 UTC
[jira] [Resolved] (COUCHDB-1506) View returns null value after
adding a document
[ https://issues.apache.org/jira/browse/COUCHDB-1506?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Robert Newson resolved COUCHDB-1506.
------------------------------------
Resolution: Invalid
The user's reduce function does not anticipate receiving some of values emitted by the corresponding map function, causing algorithmic expectations to fail.
> View returns null value after adding a document
> -----------------------------------------------
>
> Key: COUCHDB-1506
> URL: https://issues.apache.org/jira/browse/COUCHDB-1506
> Project: CouchDB
> Issue Type: Bug
> Components: JavaScript View Server
> Affects Versions: 1.2
> Environment: Windows XP SP3
> Reporter: Marcin Stefaniuk
>
> I have three types of documents: customer, refill and purchase. I defined a view that aggregates customer data with current balance (from refill / purchase values). Values customer._id and purchase/refill.customer are joining keys. Map function looks as follows:
> function(doc) {
> if (doc.type=='purchase' || doc.type=='refill') {
> emit(doc.customer, {value: doc.value, type: doc.type});
> } else if (doc.type=='customer') {
> emit(doc._id, doc);
> }
> }
> Reduce function is:
> function(keys, values, rereduce) {
> var customer = null, sum = 0;
> values.forEach(function(element) {
> if (element.type=='purchase') {
> sum -= element.value;
> } else if (element.type=='refill') {
> sum += element.value;
> } else if (customer==null && element.type=='customer') {
> customer = element;
> }
> });
> customer.credit = sum;
> return customer;
> }
> This view is working with success but after several adding of purchase documents it returns null as value.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira