Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 69255 invoked from network); 29 Jul 2009 09:36:34 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 29 Jul 2009 09:36:34 -0000 Received: (qmail 46444 invoked by uid 500); 29 Jul 2009 09:36:34 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 46368 invoked by uid 500); 29 Jul 2009 09:36:33 -0000 Mailing-List: contact user-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@couchdb.apache.org Delivered-To: mailing list user@couchdb.apache.org Received: (qmail 46354 invoked by uid 99); 29 Jul 2009 09:36:33 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 29 Jul 2009 09:36:33 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of b.candler@pobox.com designates 208.72.237.25 as permitted sender) Received: from [208.72.237.25] (HELO sasl.smtp.pobox.com) (208.72.237.25) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 29 Jul 2009 09:36:23 +0000 Received: from localhost.localdomain (unknown [127.0.0.1]) by a-sasl-quonix.sasl.smtp.pobox.com (Postfix) with ESMTP id 22AF618EC4; Wed, 29 Jul 2009 05:36:02 -0400 (EDT) Received: from mappit (unknown [80.45.95.114]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by a-sasl-quonix.sasl.smtp.pobox.com (Postfix) with ESMTPSA id B790E18EC3; Wed, 29 Jul 2009 05:35:57 -0400 (EDT) Received: from brian by mappit with local (Exim 4.69) (envelope-from ) id 1MW5Zi-0002yr-8C; Wed, 29 Jul 2009 10:35:54 +0100 Date: Wed, 29 Jul 2009 10:35:54 +0100 From: Brian Candler To: Jochen Kempf Cc: user@couchdb.apache.org Subject: Re: Problems with reduce in view appear when record size > 6 Message-ID: <20090729093554.GC10984@uk.tiscali.com> References: <6d692b470907271733o3edca47aj4b4664fb0abeb559@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <6d692b470907271733o3edca47aj4b4664fb0abeb559@mail.gmail.com> User-Agent: Mutt/1.5.17+20080114 (2008-01-14) X-Pobox-Relay-ID: 3AE01E1A-7C23-11DE-8C07-F699A5B33865-28021239!a-sasl-quonix.pobox.com X-Virus-Checked: Checked by ClamAV on apache.org On Mon, Jul 27, 2009 at 08:33:48PM -0400, Jochen Kempf wrote: > But once I define the following reduce function it stops working from 6 or 7 > records on upwards (if the total record size of the corresponding database > is < 6 it works fine): > > > function(key, values, combine) { > > var ids = []; > > var revs = []; > > var variables = []; > > for (i in values) { > > ids.push(values[i][0]); > > revs.push(values[i][1]); > > variables.push([values[i][2], values[i][3], values[i][4], > > values[i][5], values[i][6]]); > > } > > return [ids, revs, variables]; > > } > > > This is the error message: > > > Error: case_clause > > > {{badmatch,<<"Cannot encode 'undefined' value as JSON">>}, > > [{couch_query_servers,'-rereduce/3-fun-0-',3}, > > {lists,zipwith,3}, > > {couch_query_servers,rereduce,3}, > > {couch_view_group,'-init_group/4-fun-0-',4}, > > {couch_btree,'-write_node/3-lc$^0/1-0-',3}, > > {couch_btree,write_node,3}, > > {couch_btree,complete_root,2}, > > {couch_btree,query_modify,4}]} > > > > Anyone knows what is going on? Yes, one of ids, revs or variables is undefined :-) You can use 'log' to see what values are being passed into your reduce function. As a guess, I'd say that a re-reduce operation is taking place: 'combine' will be true, 'key' will be null, and 'values' will be the output of a previous reduce operation. That is: your reduce function must be written in such a way as to be able to process values generated by a previous reduce function, as well as values emitted by a document. The Wiki talks about this further.