Having recently read about appengine-mapreduce I decided I would write a simple Mapper that looks for and fixes missing property values and invalid ReferenceProperty keys. You can find the ModelHygienceMapper (as I call it) at he3-appengine-lib in the new mappers.py file (some simple documentation coming soon).
The code for the ModelHygieneMapper that does the work very simple, and mostly worth listing in the event that someone can suggest an improved approach.
@staticmethod |
def process(entity): |
'''Checks and repairs model integrity of the passed entity |
1. Removes dangling references |
2. Sets undefined datastore values to the default |
''' |
props = [x for x in entity.__class__.__dict__.values()\ |
if isinstance(x, db.Property)] |
changed = False |
for prop in props: |
if not prop.get_value_for_datastore(entity): |
prop.__set__(entity, prop.default_value()) |
changed = True |
elif isinstance(prop, db.ReferenceProperty): |
if not db.get(prop.get_value_for_datastore(entity)): |
prop.__set__(entity, None) |
changed = True |
if changed: yield op.db.Put(entity) |
The concept of Map Reduce and the App engine project is more interesting than my simple mapper. The Map Reduce is a framework for breaking up large problems into small parts that can be run in parallel (as I read on Wikipedia). Appengine-mapreduce is a project that has begun the task of implementing this concept on Google App Engine for Python and Java.
The work of using Map Reduce is in defining the mappers and reducers. Mappers perform work on the problem data in parallel, while Reducers (from what I understand), recombinate the outputs based on information in the original dataset. If you can structure a solution to your problem using this paradigm it becomes easier to distribute the work between computers and datacenters. For App Engine developers, Map Reduce is a way to traverse the datastore or other collection of data (for example, lines in a file) effectively without re-engineering the plumbing that allows you to do this.
Using appengine-mapreduce in your application, like I did with ModelHygieneMapper, is easy. Include the source code for the library in your application and add a URL mapping to your app.yaml file. Create a Mapper.yaml file which contains the configuration for the mapper or mappers you wish to use. If you haven't already, write or include the mapper. The getting started guide for python explains this pretty well.
I will be keeping an eye on appengine-mapreduce in the future for other tasks it will be appropriate for. In the meantime, I am happy that I had a way to implement ModelHygienceMapper without worrying about the plumbing. If you have any feedback about my mapper, please let me know.
Nice! The list comprehension at the start isn't necessary, though: The class method .properties() returns a dict mapping property names to property classes.
ReplyDeleteHi Nick - thanks for the tip!
ReplyDeleteHadoop is one of the best cloud based tool for analysisng the big data. With the increase in the usage of big data there is a quite a demand for hadoop professionals.
ReplyDeleteBig data training in Chennai | Hadoop training Chennai | Hadoop training in Chennai
This is an awesome post.Really very informative and creative contents. These concept is a good way to enhance the knowledge.I like it and help me to development very well.Thank you for this brief explanation and very nice information.Well, got a good knowledge.
ReplyDeleteBig Data Analytics Courses in Chennai
Big Data Analytics Training in Chennai
Big Data Training in Chennai
Advanced Java Training in Chennai
German Language Classes in Chennai
Big Data Analytics Training in Annanagar
Big Data Analytics Training in Chennai
It is an informative post.
ReplyDeleteI wanted to thank you for this great blog! I really enjoying every little bit of it and I have you bookmarked to check out new stuff you post.
ReplyDeleteDigital Marketing Training in Coimbatore
Digital Marketing Course in Coimbatore
Android course in coimbatore
CCNA Training in Coimbatore
cloud computing training in coimbatore
embedded training in coimbatore
ethical hacking course in coimbatore
German Language course in Coimbatore
Great post and informative blog.it was awesome to read, thanks for sharing this great content to my vision.
ReplyDeleteGood discussion.
German Classes in Chennai
German Language Course in Chennai
german classes in bangalore
german classes in marathahalli
german language course in bangalore
german classes in coimbatore
german language course in coimbatore
german classes in madurai
german language course in hyderabad
Your article is very informative. Thanks for sharing the valuable information.
ReplyDeleteData Science Course in Chennai
Data Science Courses in Bangalore
Data Science Course in Marathahalli
Best Data Science Training in Marathahalli
Data Science Institute in Marathahalli
AWS Training in Bangalore
Data Science Training in Bangalore
Data Science Institute in Bangalore
Spoken English Classes in Bangalore
DevOps Training in Bangalore
Pretty blog, so many ideas in a single site, thanks for the informative article, keep updating more article.
ReplyDeleteJAVA Training in Chennai
JAVA Course in Chennai
Java Training Institute in Chennai
Best JAVA Training Institute in Chennai
Java Classes in Chennai
There is plenty of Information available in this post,so that the readers would be energized and get extra knowledge.By this blog iam interested in reading more blogs.
ReplyDeleteIELTS Coaching in chennai
German Classes in Chennai
GRE Coaching Classes in Chennai
TOEFL Coaching in Chennai
spoken english classes in chennai | Communication training
Mua vé máy bay tại Aivivu, tham khảo
ReplyDeletegiá vé máy bay hàn quốc về việt nam
vé máy bay daklak đi sài gòn
vé máy bay từ phú quốc đi hà nội
vé máy bay đi đà lạt bao nhiêu tiền
vé máy bay từ los về việt nam
taxi sân bay nội bài
I feel so happy to read this blog..Thanks for sharing this informative blog..Nice post... Best English Tutoring in Bahrain: We are renowned for delivering top-quality English tutoring, ensuring you reach your language goals efficiently.
ReplyDeleteBook a free demo today. English language tutor in bahrain