Skip to content

Support distinct projection queries? #1202

Closed

Description

@jgeewax

Related to #304 (#304 (comment))

and

http://stackoverflow.com/questions/33283759/how-to-do-a-gql-query-using-gcloud-python

How do we do the equivalent of GQL: SELECT DISTINCT p FROM Kind ?

/cc @Fkawala

Activity

  1. jgeewax commented on Oct 22, 2015

    @jgeewax
    ContributorAuthor

    @pcostell : Can the API even allow this type of thing using a structured query object ? Or is this only supported via GQL ?

  2. tseaver commented on Oct 22, 2015

    @tseaver
    Contributor

    Datastore queries take a projection parameter, which is a list of the fields to be returned. AFAICT, the API don't expose any way to do any "summary" operations (DISTINCT, COUNT, SUM, etc.) except to pull the values back and munge them client-side.

  3. pcostell commented on Oct 22, 2015

    @pcostell
    Contributor

    Sorry OOO so short reply:
    Yes it can. In v1beta2 you can use group_by, in v1beta3 you can use distinct_on.

    SELECT DISTINCT p FROM Kind == SELECT p FROM KIND GROUP BY p.

    Aggregation ops aren't supported because they would require full scans of the data to answer. DISTINCT however can be implemented efficiently.

  4. Fkawala commented on Oct 23, 2015

    @Fkawala

    @pcostell so the parameter group_by of object Query does what I expect, and there is not any interest (speed / efficiency ?) to use GQL SELECT DISTINCT ? Thanks.

  5. pcostell commented on Oct 23, 2015

    @pcostell
    Contributor

    @Fkawala -- yes, using group_by on all your projection properties is the exact same as using SELECT DISTINCT IN GQL. (In fact that is how GQL DISTINCT is implemented.

  6. dhermes commented on Dec 31, 2015

    @dhermes
    Contributor

    @pcostell I'm closing this out. It seems support already exists. LMK if I'm mistaken.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

api: datastoreIssues related to the Datastore API.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions