Couchbase
  • Why NoSQL?
  • Couchbase Server
  • Download
  • Resources
  • Careers
Home | Forums | SDKs | SDKs

Couchbase 2.0: setting group_level in view queries with the Java API

3 replies [Last post]
  • Login or register to post comments
Wed, 02/01/2012 - 13:30
stefan
Offline
Joined: 02/01/2012
Groups: None

I was surprised to see that it makes a difference in which order arguments are passed to the Couchbase http api via port 8092 (the same seems to be true for CouchDB on port 5984). This is important if you are using "group_level" and "group" in one call (I know this doesn't make sense, but please continue reading). The second argument in the http request seems to override the first.

Say you have an array as an index and want to set the group_level to 1 to group by the first entry of the array.

Setting "group" to true or false before setting the group_level to 1 doesn't matter as it gets overwritten. So
reduce=true&group=false&group_level=1
and
reduce=true&group=true&group_level=1
both work to set the group_level to 1.

However if you set the group_level to 1 first and then set group in the query things are going wrong:
reduce=true&group_level=1&group=false
effectively deactivates grouping and
reduce=true&group_level=1&group=true
groups by the whole array.

So far so good, but here is the problem:

The only way to set the group_level in a Query with the Java API is this:
Query net.spy.memcached.protocol.couch.Query.setGroup(boolean group, int grouplevel)
It sets both "group" and "group_level" for a query.

The function adds both parameters as key->value mapping to a Hash with all parameters of the query, and when building the uri for the http query it loops over the entrySet of the Hash and adds all entries as parameters to the query. So effectivly both the "group" and "group_level" parameters are added in random order. This makes it impossible to query your views reliably with a desired group_level.

Do I miss someting or is this really a problem?

Stefan

PS: This is not a theoretical problem. For us (and I assume for others using group_level) this is a showstopper. We had to add

public Query setGroupLevel(int grouplevel) {
args.put(GROUPLEVEL, Integer.valueOf((grouplevel)));
return this;
}

to net.spy.memcached.protocol.couch.Query to make things work.

Top
  • Login or register to post comments
Mon, 03/19/2012 - 00:13
ingenthr
Offline
Joined: 03/16/2010
Groups:

Thanks for raising the issue Stefan. This is a problem and we'll have to address it.

It is true that view params can cancel each other out and the rules are not well documented.

We'll get this sorted out in the next update on the client.

Top
  • Login or register to post comments
Wed, 04/17/2013 - 06:10
devbalduz
Offline
Joined: 04/17/2013
Groups: None

It looks like that this is still an issue... At least to me.

I'm experiencing the same problem in my machine running couchbase server community edition 2.0.1 and Java Client 1.1.5, on mac osx 10.8.3.

I think this could be fixed in two way:
- on the server, by being able to process query parameters in any order
- on the java client, by fixing the Query.toString() method, making it creating the uri string with parameters in correct order.
For this issue, it seems that the group=true parameter MUST appear BEFORE group_level=X to make things work.

Top
  • Login or register to post comments
Thu, 04/18/2013 - 07:56
tgrall
Online
Joined: 09/05/2012
Groups: None

Hello,

In addition to Matt's answer, you have a work around for that, if you only send the "setGroupLevel(x)" to you query it works as expected.
I am only using this approach and this is why I have not seen that before.

You can test that with the direct URL too.

Regards

__________________

Tug
@tgrall

Top
  • Login or register to post comments
  • Login or register to post comments
  • Login
  • Register

Company

  • About Us
  • Leadership
  • Customers
  • Partners
  • Contact Us

Product

  • Couchbase Server
  • Couchbase SDKs
  • Use Cases
  • Documentation
  • Forums

Open Source

  • Couchbase Project
  • Couchbase vs. CouchDB

Commercial

  • Subscriptions & Support
  • Training & Services

News

  • Blog
  • Newsletter
  • Press Releases
  • Buzz

Follow Us

    
  • Customer Login
  • Terms of Service
  • Privacy Policy
  • Trademark Policy
  • Site Map

© 2013 COUCHBASE All rights reserved.

Sign in to Couchbase Community

close
  • Create new account
  • Request new password
You are logging into the Forums, Wiki and Issue Tracker