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 73C4C1108B for ; Mon, 9 Jun 2014 18:18:06 +0000 (UTC) Received: (qmail 71211 invoked by uid 500); 9 Jun 2014 18:18:05 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 71156 invoked by uid 500); 9 Jun 2014 18:18:05 -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 71146 invoked by uid 99); 9 Jun 2014 18:18:05 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 09 Jun 2014 18:18:05 +0000 X-ASF-Spam-Status: No, hits=2.2 required=5.0 tests=HTML_MESSAGE,NORMAL_HTTP_TO_IP,SPF_PASS,WEIRD_PORT X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of g@gandrade.net designates 93.95.227.213 as permitted sender) Received: from [93.95.227.213] (HELO mail.gandrade.net) (93.95.227.213) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 09 Jun 2014 18:18:01 +0000 Message-ID: <5395FA14.30506@gandrade.net> Date: Mon, 09 Jun 2014 19:16:52 +0100 From: Guilherme Andrade User-Agent: - MIME-Version: 1.0 To: user@couchdb.apache.org Subject: Re: Question on views References: <14256C9E890B874D989F0828DDB264F2C51F2C86@MX45A.corp.emc.com> <5395E772.5090108@gandrade.net> <14256C9E890B874D989F0828DDB264F2C51F2CB5@MX45A.corp.emc.com> In-Reply-To: <14256C9E890B874D989F0828DDB264F2C51F2CB5@MX45A.corp.emc.com> OpenPGP: id=35CB8191 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="Onv3d2FMH8xiVq3R17GvJEQa0DvGC0Pt9" X-Virus-Checked: Checked by ClamAV on apache.org --Onv3d2FMH8xiVq3R17GvJEQa0DvGC0Pt9 Content-Type: multipart/alternative; boundary="------------010309000901000301000609" This is a multi-part message in MIME format. --------------010309000901000301000609 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable I'm sorry, it looks like I've induced you in error; too much Erlang ;). In any case, range queries make use of 'startkey' and 'endkey' instead of just 'key'. I don't remember the exact syntax for complete wildcards but Stack Overflow gave me the answer. Looks like |this might do:|| startkey=3D["target ID"]&endkey=3D["target ID",{}] | Cheers, [1]: https://stackoverflow.com/questions/11623154/couchdb-querying-array-key-v= alue-for-first-key-element-only || On 09-06-2014 19:05, Ramanadham, Radhika wrote: > Thanks. > I think I can change the keys -> key2, key1.=20 > What would be the query? > > The below throws me an error. > > http://127.0.0.1:5984/longevity/_design/perfstats/_view/by_server?key=3D= [key2,_] > > example: > > http://127.0.0.1:5984/longevity/_design/perfstats/_view/by_server?key=3D= [" lglod025.lss.emc.com",_] > > What am I doing wrong? > > -----Original Message----- > From: Guilherme Andrade [mailto:g@gandrade.net]=20 > Sent: Monday, June 09, 2014 12:57 PM > To: user@couchdb.apache.org > Subject: Re: Question on views > > Unfortunately there's no performant way to do it like that, views have = strict ordering and ranges/subranges are only possible within the confine= ments of the composite key order. > > One way to do it is to have a second view that emits keys in reverse ([= key2, key1]); then you may do a range query based on [key2, _]. > > Cheers, > > On 09-06-2014 17:36, Ramanadham, Radhika wrote: >> Hi, >> >> I have a view which has 2 keys- key1 and key2: >> >> "by_server": { >> "map": "function(doc) { if ((doc.type =3D=3D 'performa= nce_stats')) emit([key1, key2],{ 'Start_time':doc.start_time ,'CPU': doc= =2ECPU, 'Memory': doc.Memory, 'FileSystem':doc.FileSystem }) }" >> }, >> >> >> If I want to query the view where I need all the rows for key2 and key= 1 being anything, how do I do it? >> >> Let's say my data is-> >> >> {"id":"server_lglod025.lss.emc.com_2014-06-09_10:24:18","key":["lglod0= >> 25.lss.emc.com","SRMSuite_3.0.2_test1"],"value":{"Start_time":"2014-06= >> -09 09:00:00","CPU":12,"Memory":98,"FileSystem":96}}, >> {"id":"server_lglod093.lss.emc.com_2014-06-09_11:24:18","key":["lglod0= >> 93.lss.emc.com","SRMSuite_3.0.2_test2"],"value":{"Start_time":"2014-06= >> -09 10:00:00","CPU":12,"Memory":98,"FileSystem":97}}, >> {"id":"server_lglod174.lss.emc.com_2014-06-04_14:01:44","key":["lglod1= >> 74.lss.emc.com","SRMSuite_3.0.2_test2"],"value":{"Start_time":"2014-06= >> -04 10:00:00","CPU":67,"Memory":97,"FileSystem":17}}, >> >> I only want the below 2 rows who have a key2 =3D SRMSuite_3.0.2_test2,= how do I do it? >> >> {"id":"server_lglod093.lss.emc.com_2014-06-09_11:24:18","key":["lglod0= >> 93.lss.emc.com","SRMSuite_3.0.2_test2"],"value":{"Start_time":"2014-06= >> -09 10:00:00","CPU":12,"Memory":98,"FileSystem":97}}, >> {"id":"server_lglod174.lss.emc.com_2014-06-04_14:01:44","key":["lglod1= >> 74.lss.emc.com","SRMSuite_3.0.2_test2"],"value":{"Start_time":"2014-06= >> -04 10:00:00","CPU":67,"Memory":97,"FileSystem":17}}, >> >> Thanks, >> Radhika >> > -- > Guilherme Andrade > > PGP fingerprint: 1968 5252 3901 B40F ED8A D67A 9330 79B1 35CB 8191 > > --=20 Guilherme Andrade PGP fingerprint: 1968 5252 3901 B40F ED8A D67A 9330 79B1 35CB 8191 --------------010309000901000301000609 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable I'm sorry, it looks like I've induced you in error; too much Erlang ;). In any case, range queries make use of 'startkey' and 'endkey' instead of just 'key'.

I don't remember the exact syntax for complete wildcards but Stack Overflow gave me the answer. Looks like this might do:

    startkey=3D["target ID"]&endkey=3D["target I= D",{}]


Cheers,


[1]: https://stackoverflow.com/questions/11623154/couchdb-querying-array-ke= y-value-for-first-key-element-only

On 09-06-2014 19:05, Ramanadham, Radhika wrote:
Thanks.
I think I can change the keys -> key2, key1.=20
What would be the query?

The below throws me an error.

http://127.0.0.1:5984/longevi=
ty/_design/perfstats/_view/by_server?key=3D[key2,_]

example:

http://127.0.0.1:5984/longevi=
ty/_design/perfstats/_view/by_server?key=3D[" lglod025.lss.emc.com",_=
]

What am I doing wrong?

-----Original Message-----
From: Guilherme Andrade [mailto:g@gandrade.net]=20
Sent: Monday, June 09, 2014 12:57 PM
To: user@couchdb.apache.org
Subject: Re: Question on views

Unfortunately there's no performant way to do it like that, views have st=
rict ordering and ranges/subranges are only possible within the confineme=
nts of the composite key order.

One way to do it is to have a second view that emits keys in reverse ([ke=
y2, key1]); then you may do a range query based on [key2, _].

Cheers,

On 09-06-2014 17:36, Ramanadham, Radhika wrote:
Hi,

I have a view which has 2 keys- key1 and key2:

"by_server": {
                "map": "function(doc) { if ((doc.type =3D=3D 'performance=
_stats'))  emit([key1, key2],{ 'Start_time':doc.start_time ,'CPU': doc.CP=
U, 'Memory': doc.Memory, 'FileSystem':doc.FileSystem }) }"
 },


If I want to query the view where I need all the rows for key2 and key1 b=
eing anything, how do I do it?

Let's say my data is->

{"id":"server_lglod025.lss.emc.com_2014-06-09_10:24:18","key":["lglod0
25.lss.emc.com","SRMSuite_3.0.2_test1"],"value":{"Start_time":"2014-06
-09 09:00:00","CPU":12,"Memory":98,"FileSystem":96}},
{"id":"server_lglod093.lss.emc.com_2014-06-09_11:24:18","key":["lglod0
93.lss.emc.com","SRMSuite_3.0.2_test2"],"value":{"Start_time":"2014-06
-09 10:00:00","CPU":12,"Memory":98,"FileSystem":97}},
{"id":"server_lglod174.lss.emc.com_2014-06-04_14:01:44","key":["lglod1
74.lss.emc.com","SRMSuite_3.0.2_test2"],"value":{"Start_time":"2014-06
-04 10:00:00","CPU":67,"Memory":97,"FileSystem":17}},

I only want the below 2 rows who have a key2 =3D SRMSuite_3.0.2_test2, ho=
w do I do it?

{"id":"server_lglod093.lss.emc.com_2014-06-09_11:24:18","key":["lglod0
93.lss.emc.com","SRMSuite_3.0.2_test2"],"value":{"Start_time":"2014-06
-09 10:00:00","CPU":12,"Memory":98,"FileSystem":97}},
{"id":"server_lglod174.lss.emc.com_2014-06-04_14:01:44","key":["lglod1
74.lss.emc.com","SRMSuite_3.0.2_test2"],"value":{"Start_time":"2014-06
-04 10:00:00","CPU":67,"Memory":97,"FileSystem":17}},

Thanks,
Radhika

--
Guilherme Andrade

PGP fingerprint: 1968 5252 3901 B40F ED8A  D67A 9330 79B1 35CB 8191



--=20
Guilherme Andrade

PGP fingerprint: 1968 5252 3901 B40F ED8A  D67A 9330 79B1 35CB 8191
= --------------010309000901000301000609-- --Onv3d2FMH8xiVq3R17GvJEQa0DvGC0Pt9 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- iQEcBAEBCgAGBQJTlfoUAAoJEJMwebE1y4GRqAYH/2FMgTsmB56O4QhKG3uTfgPR 5Yy6IAyNKN+3DJ/xuN71Jnl2hlij7gSHaGPuS/Huy68Ch1TETwDtd6VPMOem1QMI uc8yClXWBDijoAvVZN/8Q7R17mGpBCGXPV5wwwx+YIQeGRiFo7WNVuWraApRSfLA Nb2fMJ7M9RaBNLpkSOdn6GT3VvWxtX06rrExYfLVayR4Lev7P/LbT2nwnyuQaa9o veFKCGfQW+iUWVHJLFeqqLNxcaaNGQMGRj6wCjmwfjdEfxScftuxht2Iz+YReZcC INYoFbdJbk2nSS1+kC9OE+2AarBDf5wglIKB1h5DuIq/8hPLRaFS0Oe89ngZJrc= =E3WL -----END PGP SIGNATURE----- --Onv3d2FMH8xiVq3R17GvJEQa0DvGC0Pt9--