Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 41266 invoked from network); 28 Sep 2010 13:04:48 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 28 Sep 2010 13:04:48 -0000 Received: (qmail 16784 invoked by uid 500); 28 Sep 2010 13:04:47 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 16472 invoked by uid 500); 28 Sep 2010 13:04: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 16460 invoked by uid 99); 28 Sep 2010 13:04:43 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 28 Sep 2010 13:04:43 +0000 X-ASF-Spam-Status: No, hits=2.2 required=10.0 tests=FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,NORMAL_HTTP_TO_IP,RCVD_IN_DNSWL_NONE,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL,WEIRD_PORT X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of reeder.29@gmail.com designates 209.85.216.180 as permitted sender) Received: from [209.85.216.180] (HELO mail-qy0-f180.google.com) (209.85.216.180) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 28 Sep 2010 13:04:36 +0000 Received: by qyk5 with SMTP id 5so9357435qyk.11 for ; Tue, 28 Sep 2010 06:04:15 -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=sVDPYJm0hWML+K1UPXSz+uRmtS3Sfns2Z0kCrsbC+mY=; b=pJ94N2QQVTVorBa0nXbLCc/O2Wt3rcoTYXuKPCXG5NEgJyZ6IqW8u7IOux+UfgiMyd eQgXBwJIFSj4tLEDeWIlYA4oRe+cXbm9xXkIYuN0gu0KVdsiaXkofU1TbIwZfOZ7YK2X Vq8Me/ZfPB4oOMQAA4YuGQXvpRYuV/GJtSsRE= 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=ApWH30JhUlsSNUJVIdVLwdvEOB9HWBoP1XPqd+n+xf5qvWlS1Mrx+6rngbBf2j23g1 3Y1ifo1BCFhysdDD1IYALMU3wKNqMROnBrlBRngG/ru5InOwAvLuOPI4lDXqFNvcXx0Q rWjFHogxK3B0nFefTL8xWcNv1ty2Wn96pAOgs= Received: by 10.229.189.211 with SMTP id df19mr7042359qcb.146.1285679054431; Tue, 28 Sep 2010 06:04:14 -0700 (PDT) Received: from [192.168.2.5] (cpe-76-181-42-9.columbus.res.rr.com [76.181.42.9]) by mx.google.com with ESMTPS id e6sm8021228qcr.17.2010.09.28.06.04.12 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 28 Sep 2010 06:04:13 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Apple Message framework v1081) Subject: Re: Subselect Possible? From: Doug Reeder In-Reply-To: Date: Tue, 28 Sep 2010 09:04:11 -0400 Content-Transfer-Encoding: quoted-printable Message-Id: References: <69CA7E1C-E158-4FE2-94FB-436D1D4508E2@gmail.com> To: user@couchdb.apache.org X-Mailer: Apple Mail (2.1081) X-Virus-Checked: Checked by ClamAV on apache.org Sorry, my earlier response seems to have gone astray. Thank you, but this map and reduce function produce exactly the same = results as mine. Is there a general method of structuring data and map-reduce functions = to do the same thing that a subselect does? On Sep 26, 2010, at 8:16 PM, Paul Davis wrote: > Hrm, I haven't thought this through to the end, but something that > might get you started: >=20 > Change your emit to emit(key, 1); >=20 > Change your reduce to: >=20 > function(keys, vals) { > return sum(vals); > } >=20 > Then query like such: >=20 > ?key=3Dquery_key&limit=3D1 > ?group_level=3Dlength(query_key)&key=3Dquery_key >=20 > It seems like there should be a fancy way to get the reduce call to > tell you if the original node had < 0 work but I'm distracted by other > code right now. >=20 > HTH, > Paul Davis >=20 > On Sun, Sep 26, 2010 at 7:46 PM, Doug Reeder = wrote: >> I've searched the wiki and googled for "subselect" and "subquery", = and not found anything relevelant. >>=20 >> I'm evaluating whether CouchDB can handle an app which currently = stores a tree structure in a relational database using the "materialized = path" represenation. For example, the item with path "QG" is a child of = the item with path "Q" and a parent of the item with path "QGC". >>=20 >> The trickiest query is, in English, "find all items with work less = than zero and whether they have any children with work less than zero". = The SQL for this is >> SELECT item.*, EXISTS (SELECT work FROM item AS d WHERE d.path > = item.path AND d.path <=3D item.path || '\ufffd' AND d.work < 0) AS = undonePrereq, FROM item WHERE work < 0 >>=20 >> Can this be done in CouchDB, using a limited, small number of = queries? >>=20 >> My closest sally is the map function >> function(doc) { >> if (doc.work < 0) { >> var key =3D []; >> var i; >> for (i=3D0; i> key.push(doc._id.charCodeAt(i)); >> emit(key, doc.work); >> } >> } >>=20 >> and the reduce function >> function(keys, values, rereduce) { >> var shortestKeyLength =3D Infinity; >> for (var i=3D0; i> if (keys[i][0].length < shortestKeyLength) >> shortestKeyLength =3D keys[i][0].length; >> } >>=20 >> return [keys.length, shortestKeyLength, = keys[0][0].slice(0,shortestKeyLength), values.length]; >> } >>=20 >> A query such as >> curl -X GET = 'http://127.0.0.1:5984/tracker1/_design/trackerA/_view/undoneArrayNum?star= tkey=3D\[45,65,65\]&endkey=3D\[45,65,9999\]&group_level=3D2' >> will return the data necessary for items at the second level, but the = desired items could be at any level. Doug Reeder reeder.29@gmail.com http://reeder29.livejournal.com/ https://twitter.com/reeder29 https://twitter.com/hominidsoftware http://outlinetracker.com