com.couchbase.client.protocol.views.Query and numeric keys
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
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