Java client 1.1-dp not returning documents when querying views
Hi all,
I'm using the Java 1.1-dp client to do queries against views. Setting query.setIncludeDocs(true) doesn't actually result in the query ViewResponse having documents (ViewRow.getDocument() returns null).
Digging into the code, it looks like that the Query class doesn't actually set the "include_docs" parameter, nor does DocsOperationImpl.parseResult try to extract the "doc" element from the returned JSON.
Is this deliberate? Or am I missing something? I'd really prefer not having to make a separate call to get the docs while iterating through a ViewResponse.
Cheers,
Tim Pedersen
Hmm, I must be missing something then - how do I get the docs asynchronously? This is my code (couchbaseTemplate is just a Spring bean that wraps a pool of clients, and handles async gets and sets):
@Test
public void testViews() throws Exception {
CouchbaseClient client = couchbaseTemplate.getClientPool().borrowObject();
try {
View view = client.getView("person", "links");
Query query = new Query();
query.setRange("[\"person:12346\",0]", "[\"person:12346\",999]");
query.setIncludeDocs(true);
ViewResponse viewResponse = client.query(view, query);
for(ViewRow viewRow:viewResponse){
String id = viewRow.getId(); // id ok
String key = viewRow.getKey(); // key ok
String value = viewRow.getValue(); // value ok - although I in this case I don't emit a value in view
String doc = (String) viewRow.getDocument(); // returns null - should return something :(
log.debug(doc);
}
} catch (Exception e) {
throw(e);
} finally {
couchbaseTemplate.getClientPool().returnObject(client);
}
}
/TP
I just realised that the problem isn't with the query/view code but is because of an issue when using CouchbaseConnectionFactoryBuilder.
With 1.1-dp, if I set up a client like so:
URI base = new URI(String.format("http://%s:8091/pools", server));
List baseURIs = new ArrayList();
baseURIs.add(base);
CouchbaseConnectionFactoryBuilder cfb = new CouchbaseConnectionFactoryBuilder();
cfb.setOpTimeout(10000);
cfb.setOpQueueMaxBlockTime(10000);
CouchbaseConnectionFactory cf = cfb.buildCouchbaseConnection(baseURIs, bucket, "", "");
CouchbaseClient client = new CouchbaseClient(cf);
getFuture = client.asyncGet(key);
value = (String) getFuture.get(); // value is not null and contains the document for the key
client.get() and viewRow.getDocument() return null values.
If I just use CouchbaseConnectionFactory:
URI base = new URI(String.format("http://%s:8091/pools", server));
List baseURIs = new ArrayList();
baseURIs.add(base);
CouchbaseConnectionFactory cf = new CouchbaseConnectionFactory(baseURIs, bucket, "");
CouchbaseClient client = new CouchbaseClient(cf);
getFuture = client.asyncGet(key);
value = (String) getFuture.get(); // value is not null and contains the document for the key
client.get() and viewRow.getDocument() return the correct values.
I've raised a Jira for this: http://www.couchbase.com/issues/browse/JCBC-102
/TP
It is deliberate. We've done a logical "include docs" rather than a physical HTTP query for it. When you set setIncludeDocs(true) as long as the view rows have document IDs associated with them, you can fetch the doc from the results. In background, the client will retrieve the documents asynchronously such that they're ready when your code gets there.