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

com.couchbase.client.protocol.views.Query and numeric keys

1 reply [Last post]
  • Login or register to post comments
Thu, 08/23/2012 - 09:07
mambler
Offline
Joined: 08/22/2012
Groups: None

Not sure if I found a bug, or if it was by design, or I'm using the java client API incorrectly. I wanted to perform a range query using numeric keys and kept getting empty collections. When I tested the corresponding numeric values in the web UI it worked fine. Seems all key value pairs are treated as strings wrapped with double quotes when the getArgs method is invoked in the Query object. I applied an incomplete/quick fix on a local copy of the SDK on my local. Below are the changes referenced in the Query class that helped me out with the range query.

changed the args member to:

private Map args;

altered the setRange method to:

public Query setRange(Object startkey, Object endkey) {
args.put(ENDKEY, endkey);
args.put(STARTKEY, startkey);
return this;
}

altered the getArgs method to:

private String getArg(String key, Object value) {
// Special case
if (key.equals(STARTKEYDOCID)) {
return key + "=" + value;

} else if (value instanceof Stale) {
return key + "=" + ((Stale) value).toString();

} else if (StringUtils.isJsonObject(value.toString())) {
return key + "=" + value.toString();

} else {

if(value instanceof String){
return key + "=\"" + value + "\"";

}else{
return key + "=" + String.valueOf(value);
}

}
}

Thanks

-Mark

Top
  • Login or register to post comments
Fri, 08/24/2012 - 12:27
ingenthr
Offline
Joined: 03/16/2010
Groups:

Hi Mark,

We're actually making a similar change here shortly. Thanks for pointing out your changes.

We're also adding a new, very simple class, for handling complex keys. These are situations where you have an array value.

Sorry they weren't in there already!

Matt

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