Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 52938 invoked from network); 30 Aug 2009 10:27:46 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 30 Aug 2009 10:27:46 -0000 Received: (qmail 27720 invoked by uid 500); 30 Aug 2009 10:27:45 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 27628 invoked by uid 500); 30 Aug 2009 10:27:44 -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 27618 invoked by uid 99); 30 Aug 2009 10:27:44 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 30 Aug 2009 10:27:44 +0000 X-ASF-Spam-Status: No, hits=1.2 required=10.0 tests=SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (athena.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; Sun, 30 Aug 2009 10:27:35 +0000 Received: from [192.168.1.17] (f053000140.adsl.alicedsl.de [::ffff:78.53.0.140]) (AUTH: LOGIN jan, TLS: TLSv1/SSLv3,128bits,AES128-SHA) by jan.prima.de with esmtp; Sun, 30 Aug 2009 10:27:13 +0000 Content-Type: text/plain; charset=us-ascii; format=flowed; delsp=yes Mime-Version: 1.0 (Apple Message framework v1075.2) Subject: Re: averaging and rereduce From: Jan Lehnardt In-Reply-To: <7FBFD14C-8236-4317-A868-B3DC1F8C2EEB@freshout.us> Date: Sun, 30 Aug 2009 12:27:12 +0200 Content-Transfer-Encoding: 7bit Message-Id: References: <7FBFD14C-8236-4317-A868-B3DC1F8C2EEB@freshout.us> To: user@couchdb.apache.org X-Mailer: Apple Mail (2.1075.2) X-Virus-Checked: Checked by ClamAV on apache.org On 30 Aug 2009, at 11:36, Francisco Viramontes wrote: > Hi list! > > I hava a question about grouping and the reduce function > > If aI want to average the sum of manu values returned by my map > function on a large database (~100000 rows ) the reduce function > gets called with the rereduce boolean > > The thing is a am not sure if its mathematically correct to average > sets of floats in groups as optimized by couch where I can have to > average smaller sets of previously averaged values. I certainly dont > get the exact same result of averaging a whole set than a grouped set. > > My question is how can I handle my reduce function to reduce a whole > set and not in groups? > > Note the emit call is done with complex keys: > > map: > > function(doc) { > if ((doc['couchrest-type'] == 'RawData') && doc > ['device_variable_id']) { > date = new Date(doc.date_time); > emit([doc.device_variable_id, date.getFullYear(), > date.getUTCMonth() + 1, date.getUTCDate(), date.getUTCHours(), > parseInt(date.getUTCMinutes() / 20 + 1) ], doc.value); > } > } > > reduce: > > function( keys, values, rereduce ) { > if(rereduce){ > log("rereduce"); > } > return sum( values ) / values.length ; > } You cannot ignore the call where rereduce is true. See http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/test/reduce.js?revision=804727&content-type=text%2Fplain scroll down a little: " var reduceCombine = function (keys, values, rereduce) { " for an example.