Skip to content
This repository has been archived by the owner on Mar 9, 2022. It is now read-only.

CouchDbConnector queryView(ViewQuery query) vs. queryView(ViewQuery query, Class<T> type) #85

Open
bhaskarmurthy opened this issue Feb 4, 2013 · 9 comments
Labels

Comments

@bhaskarmurthy
Copy link

When running a query using queryView(ViewQuery), I get the right results in ViewResult. However, when using queryView(ViewQuery, Class<T>), I get 0 results.

My TDView looks like:

TDView taskGroupAllView = db.getViewNamed("TaskGroup/all");
        taskGroupAllView.setMapReduceBlocks(new TDViewMapBlock() {

            @Override
            public void map(Map<String, Object> document, TDViewMapEmitBlock emitter) {
                Object type = document.get("type");
                Object groupId = document.get("groupId");
                Object createdAt = document.get("createdAt");

                if (type != null && type.equals(TaskGroup.ITEM_TYPE)) {
                    ComplexKey key = ComplexKey.of(groupId, createdAt);
                    emitter.emit(key, document.get("_id"));
                }
            }
        }, null, "1.0");

My repository looks like:

public class TaskGroupRepository extends CouchDbRepositorySupport<TaskGroup> {
    public TaskGroupRepository(CouchDbConnector db) {
        super(TaskGroup.class, db);
    }

    public List<TaskGroup> getAllByGroupId(String groupId) {
        ViewQuery query = createQuery("all")
            .descending(true)
            .startKey(ComplexKey.of(groupId, ComplexKey.emptyObject()))
            .endKey(ComplexKey.of(groupId));

        return db.queryView(query, TaskGroup.class);
    }
}

Result from queryView(ViewQuery) looks like:
ignoreNotFound = false
offset = 0
rows = [org.ektorp.ViewResult$Row@4155a408, org.ektorp.ViewResult$Row@4156a648]
totalRows = 2
updateSeq = null

Result from queryView(ViewQuery, Class) looks like:
modCount = 0

Is there a discrepancy in behaviour of these methods? Or could there be an issue in the mapping?

@jchris
Copy link
Contributor

jchris commented Jul 24, 2013

@jchris jchris closed this as completed Jul 24, 2013
@tleyden
Copy link

tleyden commented Jul 24, 2013

I don't think this is a duplicate of those, re-opening.

@tleyden tleyden reopened this Jul 24, 2013
@tleyden
Copy link

tleyden commented Jul 24, 2013

Maybe this issue will go away when we upgrade to ektorp 1.4

@tleyden
Copy link

tleyden commented Jul 24, 2013

Assuming 1.4 will fix this, closing as duplicate of https://github.com/couchbase/couchbase-lite-android/issues/38

@tleyden tleyden closed this as completed Jul 24, 2013
@stanch
Copy link

stanch commented Jul 25, 2013

I had this issue. I think the problem is that when you emit an _id in CouchDB, it is replaced with a document that has the respective id. CBLite deviates somehow. Here is a workaround (roughly translated from Scala, not tested):

ObjectMapper objectMapper = new ObjectMapper()
for (ViewResult.Row row : results.getRows()) {
  doc = objectMapper.readValue(row.getDoc(), clazz)
  // add the doc to a list
}

Namely, the difference to CouchDB is that row.getValue() just returns the _id, so you have to use row.getDoc() to fetch the document directly.

I doubt it’s an Ektorp issue.

@tleyden
Copy link

tleyden commented Jul 26, 2013

@stanch thanks for this insight. Re-opening based on your comment.

@tleyden tleyden reopened this Jul 26, 2013
@stanch
Copy link

stanch commented Jul 26, 2013

Do you think this could be tracked in couchbase-lite-android?

@stanch
Copy link

stanch commented Jul 26, 2013

One more thing, there is an include_docs query parameter in the HTTP API. In Ektorp it is represented by new ViewQuery(). ... .includeDocs(true).

@tleyden
Copy link

tleyden commented Jul 26, 2013

Do you think this could be tracked in couchbase-lite-android?

@stanch sure - can you open a bug in couchbase-lite-android which points back to this one, and then close this one? (to avoid duplication)

there is an include_docs query parameter ..

Lets consider that a separate issue for now. Can you file a ticket to track it? Be explicit and give an example of the actual api and the expected api.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants