-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cloud Datastore - Entity Count Query - StructuredQuery.Builder - Allow limit of 0 #5061
Comments
@codeconsole Why do you want setLimit to 0 instead of not setting at all? |
closing this due to staleness, please feel free to reopen should you need further help. |
@ajaaym You are asking a question that was explained in the description.
Which was referenced from here as explained by David Gray a Google Employee Mon, May 14, 2018 at 7:25 PM https://groups.google.com/forum/#!topic/gcd-discuss/wH8lVOA-a8Y |
@ajaaym I imagine this has to do with the fact that returning 1 key every time is useless, serves no purpose, and is wasting network traffic. Although the efficiency is most likely best for Google as I believe there are no is no charge for a Key only query? If you don't set a limit, you will get numerous keys returned which would be even less efficient. |
So we tried to implement a method to count results based on the above,
First locally using the But deployed I'm not getting correct counts at all, even though debugging live builds shows that Now the Java Doc for Returns the number of results skipped, typically because of an offset. A simple use case to count entities:
The sample code they have there is not clear, what if |
Just keep it simple and do not re-invent the wheel, I have not had any issues
|
Note: This isn't something you should be running all the time as the query takes a long time on large Tables. This is nothing like a count query in sql and is extremely slow. This is also not guaranteed to be accurate according to the limitations of this type of datastore. |
Thank you. I'm not trying something different here actually both codes are almost identical, only a while instead of a for loop,
|
According to the group, the best solution for counting entities is:
https://groups.google.com/forum/#!topic/gcd-discuss/wH8lVOA-a8Y
This was made possible by this ticket.
#3279
However, currently the setLimit enforces a value > 0.
https://googleapis.github.io/google-cloud-java/google-cloud-clients/apidocs/com/google/cloud/datastore/StructuredQuery.Builder.html#setLimit-java.lang.Integer-
StructuredQuery.java needs to be updated to allow a limit >= 0.
https://github.com/googleapis/google-cloud-java/blob/master/google-cloud-clients/google-cloud-datastore/src/main/java/com/google/cloud/datastore/StructuredQuery.java#L760
This will allow the following code to work:
The text was updated successfully, but these errors were encountered: