Search code examples
javagoogle-app-enginegoogle-cloud-datastoregcloudobjectify

Querying Stat tables using Objectify


I am trying to perform a low-level Datastore query on one of the Stat tables (Stat_Ns_Kind) using Objectify.

The operation I'm trying to run looks like this:

ofy()
.load()
.kind("__Stat_Ns_Kind__")
.filter("kind_name", entityName)

I've tried it using a .projection("count") to only get the specific column, but Datastore complained about a missing index... I've also tried omitting the projection and working with the full object from the result (.single().now()), but I always got a null result.

Can anyone suggest a proper way of doing this?

P.S. the operation executes within an Ofy context and all entities are registered properly. I've tried to execute the plain GQL on gcloud and I got the desired result, just need to translate that to OFY.


Solution

  • I tried your code and it does work; you'll get an com.google.cloud.datastore.Entity as response where you can get the count with getLong("count")

    Just make sure you are in the right namespace, as you are looking for the namespace specific stats. You can try to query __Stat_Kind__ to see if it's a namespace issue