我試圖使用AppEngine實現一個大型(ish)數據集的彙總視圖。如何彙總Google AppEngine中的數據
我的模型看起來像:
def TxRecord(db.Model):
expense_type = db.StringProperty()
amount = db.IntegerProperty()
def ExpenseType(db.Model):
name = db.StringProperty()
total = db.IntegerProperty()
我的數據存儲包含的TxRecord
100K情況下,我想通過expense_type
總結這些。
在SQL它會是這樣的:
select expense_type as name, sum(amount) as total
from TxRecord
group by expense_type
什麼我目前做的是使用Python MapReduce framework遍歷所有TxRecords
的使用下面的映射:
def generate_expense_type(rec):
expense_type = type.get_or_insert(name, name = rec.expense_type)
expense_type.total += rec.amount
yield op.db.Put(expense_type)
這似乎工作,但我覺得我必須使用1的shard_count
來運行它,以確保總數不會被寫入併發寫入。
有沒有一種策略可以用來使用AppEngine來解決這個問題或者它是什麼?
我目前正在嘗試使用內存緩存條目類似的東西。我無法與op.counters一起工作的是如何獲得回調處理程序中的計數器......是否有時間處理另一個問題? – 2011-03-27 11:29:22