From user-return-5908-apmail-couchdb-user-archive=couchdb.apache.org@couchdb.apache.org Mon Aug 10 07:40:01 2009 Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 87278 invoked from network); 10 Aug 2009 07:40:01 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 10 Aug 2009 07:40:01 -0000 Received: (qmail 13469 invoked by uid 500); 10 Aug 2009 07:40:07 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 13386 invoked by uid 500); 10 Aug 2009 07:40:07 -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 13376 invoked by uid 99); 10 Aug 2009 07:40:07 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 10 Aug 2009 07:40:07 +0000 X-ASF-Spam-Status: No, hits=1.2 required=10.0 tests=SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (nike.apache.org: local policy) Received: from [83.97.50.139] (HELO jan.prima.de) (83.97.50.139) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 10 Aug 2009 07:39:56 +0000 Received: from [10.0.1.3] (i53879041.versanet.de [::ffff:83.135.144.65]) (AUTH: LOGIN jan, TLS: TLSv1/SSLv3,128bits,AES128-SHA) by jan.prima.de with esmtp; Mon, 10 Aug 2009 07:39:35 +0000 Message-Id: From: Jan Lehnardt To: user@couchdb.apache.org In-Reply-To: <921000908092348v57adaa29m31f360fc445863d3@mail.gmail.com> Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Mime-Version: 1.0 (Apple Message framework v935.3) Subject: Re: reduce fn for grouping items with same key Date: Mon, 10 Aug 2009 09:39:33 +0200 References: <921000908092348v57adaa29m31f360fc445863d3@mail.gmail.com> X-Mailer: Apple Mail (2.935.3) X-Virus-Checked: Checked by ClamAV on apache.org Hi Nitin, On 10 Aug 2009, at 08:48, Nitin Borwankar wrote: > Hello all, > > I am trying to write a reduce function which takes the map fn output > > > (k1, v11), > (k1, v12), > (k1, v13), > (k2, v21), > (k2, v22), > (k3,v31) > > and produces as a result of the reduce > > { > k1: [v11,v12,v13], > k2: [v21,v22], > k3: [v31] > } > You shouldn't do this in CouchDB. Reducing needs to truly reduce you data set. You are trying to turn tall lists into wide lists. that won't work. If you want to get the desired result, make your reduce function return null; and query the view with group=true. CouchDB does the grouping for you. > where v11 etc could themselves be lists and do not need to be > unpacked in > the final result but can stay as nested list of lists. > > But I am lost as far as the (keys, values, rereduce) signature. keys and values contain lists of keys and associated values. The reduce step calls you function in two different ways. The first way is when the map output gets fed into the reduce function. In this case rereduce is set to false. All other (one to N) invocations of reduce operate on the output the previous run produced. This is the default case and rereduce is set to true. Your code might want to (or have to) behave differently on the first normalization step and the second reduction step and the rereduce flag tells you what step you are in. Cheers Jan -- > So far I have managed by just reusing the return sum(values) on > numeric > values, but this is different and I need some conceptual help with > reduce/rereduce for non-numeric values and grouping into lists > instead of > taking the sum. > > Thanks much, > > Nitin > > 37% of all statistics are made up on the spot > ------------------------------------------------------------------------------------- > Nitin Borwankar > nborwankar@gmail.com