How to get the number of all records of a certain type stored in the Google appengine data store?

What I'm essentially looking for is SQL translated into Google AppEngine terms (for Java):

select count(*) from Customers

It seems quite simple, but, reading the documentation, it seems that I will have to run a request that matches all Clients, loop and calculate the results, taking into account the paging. I don’t want to extract every element, I just want to count them.

Or in another way, there was an API to iterate over all records of this type (at the moment, it is not possible to find the exact API). This seems rather inefficient, not to mention the fact that calls for storage also have a limited quota.

Any clues would be appreciated.

Thanks Mark

+5
source share
5 answers

As wooble says, bigtable does not support line counting as a fundamental concept - you can write a wrapper function, as mcotton says, but as he quotes from the docs, this will still be limited to 1000.

To overcome these restrictions, you need to save for each type of object that you want to count, the counter that increments each time a new entity of this type is set decreases when an object of this type is deleted.

For your application to be very scalable, you probably want to outline such counters, see http://code.google.com/appengine/articles/sharding_counters.html (unfortunately, I don’t know the translation of this recipe into Java, but the concepts must be the same).

+8

mcotton, , count() "SELECT __ key __" , .

http://code.google.com/appengine/docs/python/datastore/queryclass.html#Query_count

Google Datastore. 1000. . , , .

API Google Mapper, , , . , Google [appengine mapreduce].

, , GQL "SELECT COUNT (*)". . , count(), , .

+3

, BigTable , . , , Google Google Reader, , 1000, , , key_only , 1000 , .

+1

This is just an assumption, but I think they will implement the count () method in java, similar to the python implementation. HERE is the count () method for python.

Quantity (limit)

Returns the number of results this query fetches.

count() is somewhat faster than retrieving all of the data by a constant factor, but the running time still grows with the size of the result set. It best to only use count() in cases where the count is expected to be small, or specify a limit.

Note: count() returns a maximum of 1000. If the actual number of entities that match the query criteria exceeds the maximum, count() returns a count of 1000.

Arguments:

limit

    The maximum number of results to count.
0
source

This is a very old thread, but just in case it helps other people looking at it, there are 3 ways to do it:

  • Access Data Warehouse Statistics
  • Saving a counter in a data warehouse
  • Shared Counters

Each of these methods is explained in this link .

0
source

All Articles