[英]DISTINCT query on multiple columns doesn't work - Google App engine Datastore
I want to fetch distinct multiple columns from Google app engine Datastore in endpoint
class. 我想从Google App Engine数据存储区的
endpoint
类中获取不同的多个列。 For that i am using below code but problem is that if i try to fetch only single column then only it works properly and returns DISTINCT data. 为此,我正在使用下面的代码,但是问题是,如果我尝试仅获取单列,则只能正常工作并返回DISTINCT数据。 If i try to fetch multiple columns then
DISTINCT
doesn't work and it returns all records without any effect of Distinct query. 如果我尝试获取多个列,则
DISTINCT
不起作用,它将返回所有记录,而对Distinct查询没有任何影响。 I don't know what is wrong with my code. 我不知道我的代码有什么问题。 Please suggest any solution and guide me where i am going wrong.
请提出任何解决方案,并指导我哪里出错了。 Thank you.
谢谢。
Code: 码:
@SuppressWarnings({ "unchecked" })
@ApiMethod(name = "getDistinctFollow", httpMethod = HttpMethod.GET, path = "userendpoint/userName_fk3")
public ObjectListContainer getDistinctFollower(
@Named("followName") ArrayList<String> lstFollower,
@Nullable @Named("cursor") String cursorString,
@Nullable @Named("limit") Integer limit) {
EntityManager mgr = null;
Cursor cursor = null;
List<Object[]> lstNames;
List<String> lstString;
ObjectListContainer object;
try {
mgr = getEntityManager();
Query query = mgr.createQuery("select distinct f.uFullName,f.uUrl from UMaster f where f.uName in (:followName)");
query.setParameter("followName", lstFollower);
if (cursorString != null && cursorString != "") {
cursor = Cursor.fromWebSafeString(cursorString);
query.setHint(JPACursorHelper.CURSOR_HINT, cursor);
}
if (limit != null) {
query.setFirstResult(0);
query.setMaxResults(limit);
}
lstNames = (List<Object[]>) query.getResultList();
cursor = JPACursorHelper.getCursor(lstNames);
if (cursor != null)
cursorString = cursor.toWebSafeString();
lstString = new ArrayList<String>();
for (Object obj[] : lstNames) {
lstString.add(obj != null ? obj[0].toString() : null);
lstString.add(obj != null ? obj[1].toString() : null);
}
object = new ObjectListContainer();
object.setObjectsList(lstString);
} finally {
mgr.close();
}
return object;
}
Notice that DISTINCT
only works with Indexed properties. 请注意,
DISTINCT
仅适用于索引属性。 Is any of uFullName
or uName
are not indexed, then the projection won't work. 如果没有对
uFullName
或uName
中的任何一个进行索引,则投影将不起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.