Search code examples
google-cloud-datastoregoogle-cloud-platform

Operator.IN in Google Datastore


According to Datastore Queries there is Operator.IN keyword, allowing to specify multiple query values in single request.

However, it looks absent in gcloud-java-datastore:0.2.2.

What's the workaround to minimize the round-trip time of multiple single requests?

Is there any limitation on how many parallel queries are allowed?


Solution

  • The IN operator is a client-side feature of the Python NDB Client Library, it is not a native Cloud Datastore feature.

    Under the covers, the client library splits the query by the IN clause and issues a separate query for each of values. It will then merge all the results together client-side to give you the result.

    Since it is a client-side feature, you'll not that other query features cannot really be used with it, such as paging/cursors.

    Alternative

    If you are issue a static list of values for the IN clause (e.g. 'NEW', 'OPEN', 'ASSIGNED'), consider creating a Boolean field that is set at write-time (e.g. 'is_active') that pre-calcs the total IN clause for the entity.

    This will perform better and work in client libraries other than NDB.