-
Notifications
You must be signed in to change notification settings - Fork 0
/
join.py
38 lines (30 loc) · 883 Bytes
/
join.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import MapReduce
import sys
import copy
"""
Word Count Example in the Simple Python MapReduce Framework
"""
mr = MapReduce.MapReduce()
# =============================
# Do not modify above this line
def mapper(record):
# key: document identifier
# value: document contents
record_type = record[0]
order_id = record[1]
mr.emit_intermediate(order_id, record)
def reducer(key, list_of_values):
# key: word
# value: list of occurrence
values = [] #need to first grab order, then for each of the remaining, emit
for l in list_of_values:
if l[0] == 'order':
order = l
for l in list_of_values:
if l[0] == 'line_item':
mr.emit(copy.deepcopy(order)+l)
# Do not modify below this line
# =============================
if __name__ == '__main__':
inputdata = open(sys.argv[1])
mr.execute(inputdata, mapper, reducer)