Closed GoogleCodeExporter closed 9 years ago
While writing this new post, I just realized I forgot a line of code in my last
post :
query = query.order("-lastUpdateDate");
While searching into the documentation, I found something interesting :
https://developers.google.com/appengine/docs/java/datastore/queries#Properties_i
n_Inequality_Filters_Must_Be_Sorted_before_Other_Sort_Orders
If I add a sort by id before the sort by last update date, the error message
disappears :
Query<Document> query = ObjectifyService.begin().query(Document.class);
query = query.filter("id in ", keys); // keys is an ArrayList
query = query.order("id");
query = query.order("-lastUpdateDate");
But, now, documents are not sorted by lastUddateDate, but by id first, and then
by lastUpdateDate. Not exactly what I wanted...
Do you have any idea how to sort the result by lastUpdateDate within a query
using a IN filter ?
Thanks for help,
Original comment by jmo...@gpartner.eu
on 30 Apr 2012 at 1:10
Are you trying to do a fetchKeys()? The original error message is what you get
when you try to do that kind of query without fetching the entity data. The
GAE SDK needs the entity data so that it can do in-memory sorting.
Do a regular fetch() and you will probably be ok.
Original comment by lhori...@gmail.com
on 30 Apr 2012 at 2:19
Thanks for your answer.
You are right, with a regular fetch(), it's ok, but I am doing a fetchKeys()
because, of what I understood, the fetchKeys() only works with Indexes, and do
not execute "real queries" to datastore.
I want to optimize the number of queries I am doing to the datastore, that's
why I fetch keys only. Can you confirm that this mechanisme will not count as
read operations on the datastore with fetchKeys() ?
Is there a way to make this query working with fetchKeys() ?
Thanks,
Original comment by jmo...@gpartner.eu
on 30 Apr 2012 at 2:41
Keys-only queries still cost datastore operations. They cost 1 read op, plus 1
small op per key returned.
However, if you want a sorted IN query, the sorting must be done client-side.
You cannot make this query work with fetchKeys(). If you have questions about
application design, please open up a discussion on the objectify mailing list
rather than the bug tracker. Thanks!
Original comment by lhori...@gmail.com
on 30 Apr 2012 at 3:02
Original issue reported on code.google.com by
jmo...@gpartner.eu
on 30 Apr 2012 at 7:34