Skip to content

query.filter with OR #82

Description

@pcostell

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.

Activity

  1. changed the title [-]query.filter with OR[/-] [+]datastore: query.filter with OR[/+] on Aug 1, 2014
  2. added this to the milestone on Aug 5, 2014
  3. changed the title [-]datastore: query.filter with OR[/-] [+]query.filter with OR[/+] on Jan 20, 2015
  4. ryanseys commented on Jan 30, 2015

    @ryanseys
    Contributor

    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.

  5. dhermes commented on Jan 31, 2015

    @dhermes
    Contributor

    @pcostell This is presumably something that should happen across all libraries, yes?

    @ryanseys I'm curious, does the Java implementation attempt to squash / merge duplicates?

    /cc @tseaver

  6. ryanseys commented on Jan 31, 2015

    @ryanseys
    Contributor

    @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).

  7. modified the milestones: Datastore Stable, on Feb 2, 2015
  8. pcostell commented on Feb 2, 2015

    @pcostell
    ContributorAuthor

    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.

  9. ryanseys commented on Feb 2, 2015

    @ryanseys
    Contributor

    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.

  10. 91 remaining items

  11. added a commit that references this issue on Mar 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

🚨This issue needs some love.api: datastoreIssues related to the Datastore API.triage meI really want to be triaged.

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions