JAVA Google App Engine, JDO select specific data and do summ on all (like excel)
I am new to GAE and my skill level in JAVA is novice to intermediate somehow..
So I need help on retriving a specific filed that is an integer from JDO, and on that do the sum all, like in excel where you select all numbers and do auto sum. Hope is clear what I wont.
This is my JDO query where i select all field and all data from my datastore using jdo:
PersistenceManager pm = PMF.get().getPersistenceManager();
List<JDO> greetings = (List<JDO>) pm.newQuery(JDO.class).execute();
How do I do to select a field from my class that is called "Cost" and ma开发者_如何学Cke a sum off all the values tha are stored inside?
Lets say:
Type Cost Food 30 Drink 20 Drink 10 ... ...
And I wont the sum of all the costs? How can I make it?
Please help me!!! And thank you!!
If it is a small dataset do the calculation in java and optionally store it in a cache and separate datastore entry.
For calculating it on many entries I would go for a map and reduce method to do calculation initially.
Check out http://code.google.com/p/appengine-mapreduce/
http://gbayer.com/big-data/mapreduce-analytics-on-google-appengine/ lists a few other alternatives, like the sharding method described by T. Abilo
The answer mentioning aggregation in the database, stored procedures and PL-SQL in the context of App Engine is not very helpful, as these are features which are currently not available in the App Engine datastore.
I would advise to check the JAVA code of this example: http://code.google.com/intl/de-DE/appengine/articles/sharding_counters.html
I believe getCount() may point you in the right direction.
精彩评论