有没有办法在Google

有没有办法在Google

本文介绍了有没有办法在Google App Engine上执行汇总功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关系数据库支持的好处之一是count,sum,avg等聚合函数。但是,如果你使用的是GAE,当插入或更新记录时,你必须计算并存储count,sum,avg等整个表的值。但是如果你有很多有条件的分组呢?给定一个人:

  class Person {
@Id
整数年龄;
字符串城市;

$ / code>

如果我想要


  1. 总人数

  2. 平均年龄

每次我创建,更新或删除一个人时,我都应该计算两个聚合并将它们作为单独的列存储在同一个表中。如果我还想要每个城市的总值和平均值,我是否应该将每个城市的这些值也作为单独的列存储在同一个表中?

解决方案

右键:正确使用GAE存储,您需要选择性地去规范模型的某些方面,数据,这些数据以正常形式存在于数据库中,您可以即时重新计算,例如聚合数据(总体数据和分组数据)。

然而,将这些字段添加到您的案例中的 Person 表中 - 这没什么意义!创建另一个 PersonAggregates 表,其中包含City(总空值为空/缺失),Count,TotalAges等列(更容易维护:随时计算总计除以count )。


One of the nice things relational databases support are the aggregate functions like count, sum, avg etc. But it seems that if you are using GAE, when inserting or updating a record you must calculate and store the count, sum, avg, etc. values of the whole table. But what if you have many conditional groupings? Given a Person:

class Person {
    @Id
    Integer age;
    String city;
}

If I want

  1. the total number of personsand
  2. the average age

Is it correct that everytime I create, update or delete a person I should also calculate both aggregates and store them as separate columns in the same table. If I also want the total and average values per city, should I store these values for each city also as separate columns in the same table?

解决方案

Right: to use GAE storage properly, you need to selectively de-normalize some aspects of your model, keeping "redundant" data which, in a DB in normal form, you'd recompute on the fly, such as aggregates (overall and "grouped by" ones).

However, don't add such fields to the Person table in your case -- that makes little sense! Make another PersonAggregates table with columns such as City (null/missing for overall totals), Count, TotalAges (easier to maintain: compute the average at any time as total divided by count).

这篇关于有没有办法在Google App Engine上执行汇总功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 12:03