HAS ANCESTOR and HAS DESCENDANT clauses in google cloud datastore

3.2k views Asked by At

I'm studying the Google Cloud Datastore GQL grammar - specifically the HAS ANCESTOR and HAS DESCENDANT comparison operators.

Giving the following Person entities:

  • Amy
  • Fred, parent = Amy
  • Laura, parent = Amy
  • Paul
  • Agnes ...

Would the GQL queries below produce the same output?

SELECT * FROM Person WHERE key_name='Fred' HAS ANCESTOR KEY('Person', 'Amy')

SELECT * FROM Person WHERE KEY('Person', 'Amy') HAS DESCENDANT key_name='Fred'

If so, I don't understand the existence of HAS DESCENDANT clause.

Thanks in advance!

1

There are 1 answers

1
Alfred Fuller On BEST ANSWER

These two GQL queries should produce identical results:

SELECT * FROM Person WHERE __key__ HAS ANCESTOR KEY('Person', 'Amy')
SELECT * FROM Person WHERE KEY('Person', 'Amy') HAS DESCENDANT __key__