Return-Path: X-Original-To: apmail-couchdb-user-archive@www.apache.org Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id D39516B91 for ; Mon, 16 May 2011 15:42:22 +0000 (UTC) Received: (qmail 52345 invoked by uid 500); 16 May 2011 15:42:21 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 52315 invoked by uid 500); 16 May 2011 15:42:21 -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 52307 invoked by uid 99); 16 May 2011 15:42:21 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 16 May 2011 15:42:21 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_LOW,RFC_ABUSE_POST,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of sean.copenhaver@gmail.com designates 209.85.212.52 as permitted sender) Received: from [209.85.212.52] (HELO mail-vw0-f52.google.com) (209.85.212.52) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 16 May 2011 15:42:15 +0000 Received: by vws16 with SMTP id 16so4869693vws.11 for ; Mon, 16 May 2011 08:41:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type; bh=mdkmk73DXJQ0Pt3bc9px83i+3z9VJsKaMr0clu98/0g=; b=Xz3Bh7SDzf2bBFNWsnn3LpTE2untNRXyF2CAKLwqo9q2EaWOfWSSxqiXa2t74QgiRQ szG1eyYlixDoBzAQAwZ2oX3pS5dzddDq7s/qUC6ghGOB3PBsrZoq7hBmGNqVgpGYkdUT nN6pOlmGjagzGQbDMUXskihwfImC0aOExArIM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=Pj6Oly9ULGhXGXoU51WFG+dwxIwMY0+7k1XYniO214+J5QqbGGBbW53oAbXHWU2Hoi QAxVFEASJ57DendRwViRomQqpFF4/dNNJMxiEM14dkUI5qRVF4Pgb2frn1csqBXhMMbA kNpDew8oPTiM2uAUrDiL6MhbFy3H3/zP3iLmI= MIME-Version: 1.0 Received: by 10.52.98.137 with SMTP id ei9mr6538580vdb.64.1305560514335; Mon, 16 May 2011 08:41:54 -0700 (PDT) Received: by 10.52.115.99 with HTTP; Mon, 16 May 2011 08:41:54 -0700 (PDT) In-Reply-To: References: Date: Mon, 16 May 2011 11:41:54 -0400 Message-ID: Subject: Re: convert data query into map/reduce function From: Sean Copenhaver To: user@couchdb.apache.org Content-Type: multipart/alternative; boundary=20cf307ca2a8b093c104a3667ec3 X-Virus-Checked: Checked by ClamAV on apache.org --20cf307ca2a8b093c104a3667ec3 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable Dang hit the wrong key! Usually the convention is you have some kind of 'type' attribute (so type checking) on your documents or you check that all the fields you are interested in exist (more of the duck approach) in your map function. So perhaps your map function is something like: function(doc){ if (doc.type !=3D 'line_item') return; emit([doc.l_shipdate, doc.l_returnflag, doc.l_linestate], doc); } reduce function would then aggregate everything: function(key, values, rereduce){ var sum_qty =3D 0; for(var i =3D 0; i < values.length; i++){ sum_qty +=3D values[i].l_quantity; } /* aggregate others */ return { /* build return object */ } } You can filter by date with parameters to the view something like 'startkey=3D[""]' in the query parameters. Just trying to give you a rough idea (hopefully helping more the hurting yoru understanding), although there is probably a better way to do this. Yo= u may want to check out the book for some basic info. http://guide.couchdb.org/draft/cookbook.html On Mon, May 16, 2011 at 11:35 AM, Sean Copenhaver wrote: > Usually the convention is you have some kind of 'type' attribute (so type > checking) on your documents or you check that all the fields you are > interested in exist (more of the duck approach) in your map function. So > perhaps your map function is something like: > > function(doc){ > if (doc.type !=3D 'line_item') return; > > var value =3D { > > > > emit([doc.l_shipdate, doc.l_returnflag, doc.l_linestate], { > } > > On Mon, May 16, 2011 at 11:06 AM, Mauro Fagnoni = wrote: > >> Stefan I'm trying to convert this sql query in an identical to the >> document >> I created in couchdb. Unfortunately, it is the first time using this >> database and would like to understand how to translate the query using >> only >> the wiki because I have not figured out how to do a lot >> >> 2011/5/16 Stefan Matheis >> >> > i think a short example would be really helpful .. especially related >> > to your data-structure .. and the expected behaviour. do you already >> > have an reduce function, but it does not work like you'd have it to? >> > >> >> >> >> -- >> ----------------------------------------------- >> [-------WHOAMI------] Mauro Fagnoni >> [----------ICQ#---------] 279572903 >> [--------MSNID--------] maurofagnoni@yahoo.it >> [--YAHOOMSNID--] maurofagnoni@gmail.com >> [--GOOGLETALK--] mauro.fagnoni@gmail.com >> [-GOOGLEWAVE-] mauro.fagnoni@googlewave.com >> [------JABBER-------] mauro.fagnoni@gmail.com >> [------SKYPE--------] mauro.fagnoni >> [-----LinuxUser#----] 346345 >> [----------Blog---------] http://kingmauro.wordpress.com >> ----------------------------------------------- >> > > > > -- > =93The limits of language are the limits of one's world. =93 -Ludwig von > Wittgenstein > --=20 =93The limits of language are the limits of one's world. =93 -Ludwig von Wittgenstein --20cf307ca2a8b093c104a3667ec3--