开发者

GAE Application and GQL

I need to create an application that will collect the folloving info (NameOfWebSite, DateTimeofVisit) and after that I'd like to receive开发者_运维问答 infomation about number of visits per defined period(month, week, year), sorted by number of visits per period. For example:

www.google.com 2345 visits per defined period

www.yahoo.com 1254 visits per defined period

www.abracadabra.com 5 visits per defined period

Can I do this with help of GQL? In normal SQL it would be smth like

select NameOfWebSite, count(*) from TABLE group by NameOfWebSite where DateTimeofVisit>XXX and DateTimeofVisit < YYY

How it is better to implement this logic in terms of GAE and GQL?


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.


You can't do this in GQL directly. Instead, you should use the mapreduce API, or your own task queue task, to calculate aggregates on a regular basis, and store them in the datastore.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜