Lesson 2 / Map/Reduce Examples and Principles : Assignment: Joining Data

Find below the file results for this assignment + Python mapper.

 [premium_content]

Click here : reducerResult

Rename it to result.txt

For your records here is the mapper

for line in sys.stdin:
    line       = line.strip()   #strip out carriage return
    key_value  = line.split(“,”)   #split line, into key and value, returns a list
    key_in     = key_value[0]   #key is first item in list
    value_in   = key_value[1]   #value is 2nd item

    #print key_in
    if value_in[0:3]==’ABC’:           #if this entry has ABC
        print( ‘%s\t%s’ % (key_in, value_in  ) ) #print a string, tab, and string
 
#Note that Hadoop expects a tab to separate key value
#but this program assumes the input file has a ‘,’ separating key value

 

 [/premium_content]

 

 

Post Tagged with

Leave a Reply