Created
October 7, 2013 18:22
-
-
Save MattFaus/6872577 to your computer and use it in GitHub Desktop.
A technique for storing a JSON-serializable datetime as a computed property so that mapreduce can filter against it.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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