Repository navigation
query.filter with OR #82
Description
Activity
- changed the title
[-]datastore: query.filter with OR[/-][+]query.filter with OR[/+]on Jan 20, 2015 - addedapi: datastoreIssues related to the Datastore API.Issues related to the Datastore API.
on Jan 20, 2015 Currently queries are ANDed together by chaining
.filter()calls:var companyQuery = datastore.createQuery('Animal', ['Lion', 'Chimp']) .filter('name =', 'Frank'); .filter('kgs <', 50);
We could support OR with the addition of a
.or()and rename.filter()to.and():var companyQuery = datastore.createQuery('Animal', ['Lion', 'Chimp']) .and('name =', 'Frank'); .or('kgs <', 50);
The Java library supports this by making a separate API call for every filter separated by ORs. In this sense, the entire filter is always evaluated in disjunctive normal form which is the simplest way to define it and evaluate it. If an
.or()is attempted first before an.and()(.filter()) we could just throw an error.@dhermes I'm not experienced with the Java library's implementation but as far as I understand from their documentation, they make no such attempt to squash duplicates or handle logical errors in the filter (e.g. height < 400 AND height > 400).
There is a future goal to support or natively in the Cloud Datastore API. I'm not sure on a timeline, but it may be worth it to just wait so there is native support. There are a lot of weird edge cases with using the DNF.
Ok I'm going to close this until support is made. Feel free to reopen once the API supports that functionality. I don't think it should be too difficult to support it in this library once the API does.
91 remaining items
- added a commit that references this issue
on Mar 5, 2026 - added 2 commits that reference this issue
on Mar 5, 2026 - added 2 commits that reference this issue
on Mar 9, 2026 - added a commit that references this issue
on Mar 11, 2026 - added a commit that references this issue
on Mar 12, 2026 - added a commit that references this issue
on Mar 18, 2026 - added a commit that references this issue
on Mar 27, 2026 - added a commit that references this issue
on May 5, 2026
Right now Datastore doesn't natively support OR filters, however it is a feature we'd like to support. When switching from GAE Datastore to Cloud Datastore filters were explicitly changed from being represented as a list to a more hierarchical model to support this. There should be a plan in place for how to expose this, since now filters are assumed to be AND'ed together.