-
Notifications
You must be signed in to change notification settings - Fork 0
/
join.py
42 lines (34 loc) · 964 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
39
40
41
42
import MapReduce
import sys
import os
import json
import string
"""
Word Count Example in the Simple Python MapReduce Framework
"""
os.getcwd()
mr = MapReduce.MapReduce()
# =============================
# Do not modify above this line
def mapper(record):
# key: document identifier
# value: document contents
key = record[1]
value = record
mr.emit_intermediate(key, value)
#mapper(d[0])
#only show records in line items
def reducer(key, list_of_values):
# key: order id
# value: order, and line items
order=list_of_values[0]
items=list_of_values[1:]
for v in items:
mr.emit((order+v))
#one order has many different line items, the unique order needs to combine
#with different line items one by one, instead of order+all the items (mroe than 27)
# Do not modify below this line
# =============================
if __name__ == '__main__':
inputdata = open(sys.argv[1])
mr.execute(inputdata, mapper, reducer)