dgadiraju
11/8/2017 - 4:03 PM

python-get-revenue-for-order-id-mapreduce.py

path = "/Users/itversity/Research/data/retail_db/order_items/part-00000"
orderItems = open(path).read().splitlines()

def getOrderRevenueMR(orderItems, orderId):
    orderItemsFiltered = filter(lambda o: int(o.split(",")[1]) == orderId, orderItems)
    orderItemsMap = map(lambda o: float(o.split(",")[4]), orderItemsFiltered)
    orderRevenue = reduce(lambda total, revenue: total + revenue, orderItemsMap)
    return orderRevenue

print(getOrderRevenueMR(orderItems, 2))