1

我需要创建一个应用程序来收集以下信息(NameOfWebSite、DateTimeofVisit),然后我想接收有关每个定义期间(月、周、年)的访问次数的信息,按每个期间的访问次数排序。例如:

www.google.com 2345 次访问/定义时间段

www.yahoo.com 每个定义时间段的访问量为 1254 次

www.abracadabra.com 每个定义时间段 5 次访问

我可以在 GQL 的帮助下做到这一点吗?在普通的 SQL 中,它会像

按 NameOfWebSite 从 TABLE 组中选择 NameOfWebSite,count(*),其中 DateTimeofVisit>XXX 和 DateTimeofVisit < YYY

在 GAE 和 GQL 方面如何更好地实现这个逻辑?

4

2 回答 2

1

GQL does not support GROUP BY and aggregate functions like COUNT, MAX. That is why it is called GQL instead of SQL. Check GQL Reference for more information.

Google App Engine does not allow aggregate functions, it is a trade-off that is made for scalability. So if you need to perform aggregate functions over your data set you have to do this by yourself. If it is a simple counter you can store a counter and increment it every time you add a record that matches the criteria. For more complex aggregate functions with fuzzy dimensions (for grouping), you have to come up with your custom solution. There is not a simple answer.

Nick's suggestion could be one of the solutions; having a task to check the conditions and calculate the aggregate functions regularly. But it will never be accurate, it will always be something approximate. That is also why Google does not show the exact number of results that matches a specific search query because they don't know, at least they don't want to calculate it, they just provide an estimate.

于 2011-01-12T01:12:34.220 回答
0

您不能直接在 GQL 中执行此操作。相反,您应该使用 mapreduce API 或您自己的任务队列任务来定期计算聚合,并将它们存储在数据存储中。

于 2011-01-11T23:07:35.080 回答