forked from P7h/IntroToHadoopAndMR__Udacity_Course
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP1Q2_Reducer.py
More file actions
33 lines (23 loc) · 739 Bytes
/
P1Q2_Reducer.py
File metadata and controls
33 lines (23 loc) · 739 Bytes
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
#!/usr/bin/python
# Find the monetary value for the highest individual sale for each separate store.
import sys
highestSale = 0
oldKey = None
# It will be in the format key\tval
# Where key is the store name, val is the sale amount
for line in sys.stdin:
data_mapped = line.strip().split("\t")
if len(data_mapped) != 2:
# Something has gone wrong. Skip this line.
continue
thisKey, thisSale = data_mapped
thisSale = float(thisSale)
if thisSale > highestSale:
highestSale = thisSale
if oldKey and oldKey != thisKey:
print oldKey, "\t", highestSale
oldKey = thisKey;
highestSale = 0
oldKey = thisKey
if oldKey != None:
print oldKey, "\t", highestSale