Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
A technique for storing a JSON-serializable datetime as a computed property so that mapreduce can filter against it.
class UserData(db.Model):
birthdate = db.DateProperty(indexed=False)
def compute_birthdate_str(self):
if self.birthdate:
return self.birthdate.isoformat()
return self.birthdate
# You will probably need to add this to index.yaml
# - kind: UserData
# properties:
# - name: birthdate_str
# - name: __scatter__
birthdate_str = db.ComputedProperty(compute_birthdate_str, indexed=True)
@staticmethod
def run_mapreduce():
mapreduce_id = mapreduce.control.start_map(
name="SendParentEmails",
handler_spec="emails.handlers.send_parent_email",
reader_spec=(
"third_party.mapreduce.input_readers.DatastoreInputReader"),
mapper_parameters={
"input_reader": {
"entity_kind": "UserData",
# NOTE: You can only use "=" as the second argument
"filters": [("birthdate_str", "=", "2013-05-16")]
},
},
mapreduce_parameters={},
shard_count=32)
return "MapReduce job launched: %s" % mapreduce_id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment