Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Querying for entities with missing properties in app engine Datastore?

I have a model which looks like this:

class Example (db.Model) :
 row_num = db.IntegerProperty(required=True)
 updated = db.IntegerProperty()
 ...
 ...

Now when i store values, I may not fill the value for the updated property every time, which implies that in some entities it may not exist.

I want to construct a datastore query so that i can get all entities of kind Example which do not have the property updated set.

How do i do this?

p.s. i know i can set a default value and then query on it. But the issue is i have over 3 million entities and updated will be marked only for 1% of them, so i do not want to waste so much of datastore space by setting the rest to 0.

like image 254
demos Avatar asked Jul 26 '10 03:07

demos


People also ask

What is the query language we can use with Datastore?

The Python Datastore API provides two classes for preparing and executing queries: Query uses method calls to prepare the query. GqlQuery uses a SQL-like query language called GQL to prepare the query from a query string.

Is a Datastore an entity?

Data objects in Datastore are known as entities. An entity has one or more named properties, each of which can have one or more values. Entities of the same kind do not need to have the same properties, and an entity's values for a given property do not all need to be of the same data type.

What is ancestor in Datastore?

For highly related or hierarchical data, Datastore allows entities to be stored in a parent/child relationship. This is known as an entity group or ancestor/descendent relationship. This is an example of an entity group with kinds of types person, pet, and toy. The 'Grandparent' in this relationship is the 'Person'.

What are kinds in Datastore?

An Entity is an individual record that gets stored and retrieved from the datastore. The Kind is the unique string identifier of the type of entity.


1 Answers

In GQL, objects which do not have a value for a property cannot be returned by queries on that property, so what you're asking for is impossible without a default value.

Reference: section headed "Entities Without a Filtered Property Are Never Returned by a Query" on this page.

like image 119
Amber Avatar answered Sep 23 '22 23:09

Amber