Guest User

Untitled

a guest
Jan 29th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. from mrjob.job import MRJob
  2.  
  3. class TotalAmountCust(MRJob):
  4.  
  5. def mapper(self, _, line):
  6. (customerid, idno, amount) = line.split(',')
  7. yield customerid, float(amount)
  8.  
  9. def reducer(self, customerid, amount):
  10. yield customerid, sum(amount)
  11.  
  12. if __name__ == '__main__':
  13. TotalAmountCust.run()
  14.  
  15. from mrjob.job import MRJob
  16. from mrjob.step import MRStep
  17.  
  18. class TotalAmountCustSort(MRJob):
  19. def steps(self):
  20. return [ MRStep(mapper = self.map_by, reducer = self.red_by),
  21. MRStep(mapper = self.map_sort, reducer = self.red_sort) ]
  22. def map_by(self, _, line):
  23. (customerid, idno, amount) = line.split(',')
  24. yield customerid.zfill(2), float(amount)
  25. def red_by(self, customerid, amount):
  26. yield customerid, '%04.02f' % sum(amount)
  27. def map_sort(self, customerid, total):
  28. yield float(total), customerid
  29. def red_sort(self, total, customerid):
  30. yield total, customerid
  31. if __name__ == '__main__':
  32. TotalAmountCustSort.run()
Add Comment
Please, Sign In to add comment