Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from mrjob.job import MRJob
- class TotalAmountCust(MRJob):
- def mapper(self, _, line):
- (customerid, idno, amount) = line.split(',')
- yield customerid, float(amount)
- def reducer(self, customerid, amount):
- yield customerid, sum(amount)
- if __name__ == '__main__':
- TotalAmountCust.run()
- from mrjob.job import MRJob
- from mrjob.step import MRStep
- class TotalAmountCustSort(MRJob):
- def steps(self):
- return [ MRStep(mapper = self.map_by, reducer = self.red_by),
- MRStep(mapper = self.map_sort, reducer = self.red_sort) ]
- def map_by(self, _, line):
- (customerid, idno, amount) = line.split(',')
- yield customerid.zfill(2), float(amount)
- def red_by(self, customerid, amount):
- yield customerid, '%04.02f' % sum(amount)
- def map_sort(self, customerid, total):
- yield float(total), customerid
- def red_sort(self, total, customerid):
- yield total, customerid
- if __name__ == '__main__':
- TotalAmountCustSort.run()
Add Comment
Please, Sign In to add comment