Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 55546 invoked from network); 21 May 2010 17:54:31 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 21 May 2010 17:54:31 -0000 Received: (qmail 52551 invoked by uid 500); 21 May 2010 17:54:30 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 52517 invoked by uid 500); 21 May 2010 17:54:30 -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 52506 invoked by uid 99); 21 May 2010 17:54:29 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 21 May 2010 17:54:29 +0000 X-ASF-Spam-Status: No, hits=0.2 required=10.0 tests=AWL,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of jchris@gmail.com designates 74.125.83.180 as permitted sender) Received: from [74.125.83.180] (HELO mail-pv0-f180.google.com) (74.125.83.180) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 21 May 2010 17:54:21 +0000 Received: by pvc7 with SMTP id 7so603135pvc.11 for ; Fri, 21 May 2010 10:54:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:content-type:mime-version :subject:from:in-reply-to:date:content-transfer-encoding:message-id :references:to:x-mailer; bh=wj9UFk5gMgyyhq6HNh5QA/KtDneihEGZCZ/GLb5iWZ8=; b=IvGDvuLLbv7Pb8he9E0EAd+QnU5IwGTXYREsvejEznnFLxQacIJgwF9bNApFlSR1c+ nSKkJnWjJEiPav7qyoCR9B67N3QbvAqn84fR3weBToFgsafOymIhZfxc4v52BX5Z3Od4 wEgfiNg7zzrMBCo524g3zh0+xcfRgq129r8A8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=content-type:mime-version:subject:from:in-reply-to:date :content-transfer-encoding:message-id:references:to:x-mailer; b=GxHrqR3nqZY1Z7C+U5/HyJMaIwCpXT8wBmVxW50SPODxIXjxaiJELgFXPhA/5ivMiH R4GS3QHaNtYMn15Vcd+fPpGbcIS4xhPPn2IsjHbVq9HYEhjXqN3OZ2t3/mKTkXyMluEj 8JLLQ8+cV1aIDqgCj4ANsPfPLjuURGiRO1lsg= Received: by 10.141.105.16 with SMTP id h16mr1418513rvm.274.1274464441289; Fri, 21 May 2010 10:54:01 -0700 (PDT) Received: from [192.168.1.101] (c-98-248-172-14.hsd1.ca.comcast.net [98.248.172.14]) by mx.google.com with ESMTPS id h11sm1065345rvm.21.2010.05.21.10.53.59 (version=TLSv1/SSLv3 cipher=RC4-MD5); Fri, 21 May 2010 10:53:59 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Apple Message framework v1078) Subject: Re: Reduce function results From: J Chris Anderson In-Reply-To: <4BF6C4CA.2030405@gmail.com> Date: Fri, 21 May 2010 10:53:57 -0700 Content-Transfer-Encoding: quoted-printable Message-Id: <2FEF50BE-2500-4300-818D-E0246DBD4004@gmail.com> References: <4BF51F4F.4070706@gmail.com> <4BF5CC48.7010604@gmail.com> <4BF63DC9.7060304@gmail.com> <4BF6428F.9010802@gmail.com> <4DB9C42A-4B93-4634-A1FD-DB9540B4EA18@gmail.com> <4BF6C4CA.2030405@gmail.com> To: user@couchdb.apache.org X-Mailer: Apple Mail (2.1078) On May 21, 2010, at 10:37 AM, Tom Sante wrote: > Because the data was stored like that, but indeed for future database = this will be stored as a JSON number. Still doesn't explain why the = different behaviour of Number() in couch compared to 'js'. >=20 The only factor I can think of is the inclusion of json2.js in the = main.js source code... You might have a look through share/server for = clues. > Side question: > What would result in the smallest document byte size? storing it as a = string like "0.345" (only need precision of 0.001) or as a JSON number? You'd have to experiment to know for sure. I'm gonna guess that numbers = will store smaller than strings (they will definitely sort faster). Chris > For a few docs this will not matter but in my case a dataset size of = 10 million docs (seperated in different DB's), this could have a = significant impact. >=20 > On 21/05/10 18:41, J Chris Anderson wrote: >> It's this line that looked odd to me: >>=20 >>>>>> var v =3D new Number(values[val][v_n]); >>>>=20 >>=20 >>=20 >>=20 >> I don't usually see the new Number() construct. Why not just store as = a JSON number and then use values[val][v_n] directly? >>=20 >> Chris >>=20 >> On May 21, 2010, at 1:21 AM, Tom Sante wrote: >>=20 >>> Ok the log() helped to narrow things down: >>> res[v_n]=3D{'mi':v,'ma':v,'c':1,'t':v}; >>> in this context v isn't returned as a Number but as a {} >>> In number context, like in a Math.min(v,othernumber); it works fine. >>> Same thing happens with log: >>> log(v) returns {} >>> log(''+v) returns -0.453 >>>=20 >>> Any reason why this would be the case since this is not the = behaviour of a Number in normal js (JavaScript-C 1.7.0 2007-10-03) ? >>>=20 >>> I worked around it by forcing v to become a string here >>> res[v_n]=3D{'mi':''+v,'ma':''+v,'c':1,'t':''+v}; >>> But when i later do a sum like res[v_n].t +=3D v; >>> it just concats the v to it instead of adding its values >>> So there i have to convert it back to a Number() before adding. >>>=20 >>> On 21/05/10 10:01, Tom Sante wrote: >>>> Yeah I'll try that, see if it gives me any clues. >>>> Is there a way to run your code manually for debugging via the = command >>>> line with the JS engine the way couch calls it to build the view? = (like >>>> an interactive mode of couchjs) >>>>=20 >>>> On 21/05/10 04:59, Zachary Zolton wrote: >>>>> Reduce functions can be tricky. My best advice: try log()'ing all = your >>>>> input and intermediary results; the answer usually jumps out to = ya. >>>>>=20 >>>>> On Thursday, May 20, 2010, Tom Sante wrote: >>>>>> On 20/05/10 23:52, David Goodlad wrote: >>>>>>=20 >>>>>> On Thu, May 20, 2010 at 9:38 PM, Tom Sante = wrote: >>>>>>=20 >>>>>> Hi, >>>>>>=20 >>>>>> I have a reduce function like this: >>>>>> [snip] >>>>>> So for some reason if there is only 1 element to be reduced, on = the >>>>>> line of >>>>>> res[v_n]=3D{'mi':v,'ma':v,'c':1,'t':v}; >>>>>> v becomes v=3D{} and not the actual number. Any ideas why? >>>>>>=20 >>>>>> I tested the reduce function with the command line 'js' and send = it the >>>>>> above test keys manually as function argument and then it does = result >>>>>> in the >>>>>> correct return: >>>>>> "01:00:000074" -> {raw: {mi: -0.213, ma: -0.213, c: 1, t: = -0.213}} >>>>>> "01:00:000084" -> {raw: {mi: -0.213, ma: -0.213, c: 1, t: = -0.213}} >>>>>>=20 >>>>>>=20 >>>>>> Sounds like you need to specify group_level; Try playing around = in >>>>>> Futon, you'll see a group_level dropdown. >>>>>>=20 >>>>>> Dave >>>>>>=20 >>>>>>=20 >>>>>> Why would I need a group_level parameter? >>>>>> My key is a simple string "01:00:000074". >>>>>> Its my values don't get correctly generated by couchjs, since it = does >>>>>> out but proper values in normal commandline js. >>>>>>=20 >>>>>> var v =3D new Number(values[val][v_n]); >>>>>> if(res.hasOwnProperty(v_n)){ >>>>>> res[v_n].mi =3D Math.min(v,res[v_n].mi); >>>>>> res[v_n].ma =3D Math.max(v,res[v_n].ma); >>>>>> res[v_n].c++; >>>>>> res[v_n].t +=3D v; >>>>>> }else{ >>>>>> res[v_n]=3D{'mi':v,'ma':v,'c':1,'t':v}; >>>>>> } >>>>>>=20 >>>>>> It seems that in the above part in the 'else' case the v isn't a >>>>>> number but an empty object {} >>>>>>=20 >>>>=20 >>>=20 >>=20 >>=20 >=20