问题
I am trying to execute the below query using Objectify 5.1.8 :-
Query<Coupon> coupons = ObjectifyService.ofy().load().type(Coupon.class).filter("rewardPoints !=", "").project("code").distinct(true);
for (Coupon coupon : coupons) {
out.write(coupon.getCode());
}
It is giving me an error :
java.lang.IllegalArgumentException: Inequality filter on rewardPoints must also be a group by property when group by properties are set.
Basically, what I wish to achieve is to perform a filter and project query alongside the distinct query on an entity.
Please let me know if there is something wrong with the query.
Note: rewardPoints is Indexed.
回答1:
I don't know about Objectify but in the Google App Engine Datastore a Projection query limits the returned results to just the column(s) specified. Using distinct
is the same as grouping and from the error message, it looks like you need to add rewardPoints
to the projection in order to use the inequality filter and distinct at the same time.
回答2:
Looks like Josh was right. I changed the query and it worked perfectly.
Query<Coupon> coupons = ObjectifyService.ofy().load().type(Coupon.class).filter("rewardPoints !=", "").project("rewardPoints").project("code").distinct(true);
来源:https://stackoverflow.com/questions/32609684/error-using-filter-and-projection-in-objectify-google-datastore