0
votes

I have a kind client that consists of entities with a property psets containing a list of Key

Using the JSON api psets this would expressed as :

psets = { listValue: [ {keyValue: { path: [...]} },{keyValue: { path: [...]} },... ]}

The KeyValues are made of path = [{ kind: 'project', name: 'projectn' }]

I am trying to run an 'ancestor' query on 'client' using

SELECT * from client where psets HAS ANCESTOR KEY( project, 'project1')

This query returns an error: unsupported property

What is unsupported ?

How can I run an 'HAS ANCESTOR' filter on a list of Keys ?

Please note that according the the DataStore Documentation (Operators and comparisons)

A condition can also test whether one entity has another entity as an ancestor, using the HAS ANCESTOR or HAS DESCENDANT operators. These operators test ancestor relationships between keys. They can operate on __key__, but they can also operate on a key-valued property. For HAS ANCESTOR, the right operand cannot be a property

(emphasis mine)

1
This looks like a documentation bug. I'm working on getting that fixed and hopefully providing a better error message. - Ed Davisson

1 Answers

1
votes

Datastore only supports the HAS ANCESTOR operator on entity keys (i.e. the special __key__ property), not on regular key values.

A possible workaround would be to explicitly include each of the ancestors as a property in the entity.

So for example, if your psets property contained a key project:project1/foo:2/bar:3, you could maintain a separate psets_ancestors list property that contained project:project1, project:project1/foo:2, and project:project1/foo:2/bar:3. Then you could do equality queries on the psets_ancestors property:

SELECT * FROM client WHERE psets_ancestors = KEY(project, 'project1')

(This comes at the cost of extra index entries and having to maintain the separate list property.)