Skip to content

Instantly share code, notes, and snippets.

@dgadiraju
Last active September 5, 2019 00:52
Show Gist options
  • Save dgadiraju/a3dfeeb6787354035a4e2cff7815bce4 to your computer and use it in GitHub Desktop.
Save dgadiraju/a3dfeeb6787354035a4e2cff7815bce4 to your computer and use it in GitHub Desktop.
val orders = sc.textFile("/public/retail_db/orders")
val orderItems = sc.textFile("/public/retail_db/order_items")
val ordersCompleted = orders.
filter(o => List("COMPLETE", "CLOSED").contains(o.split(",")(3)))
val ordersCompletedMap = ordersCompleted.
map(o =>(o.split(",")(0).toInt, o.split(",")(1)))
val orderItemsMap = orderItems.
map(o =>(o.split(",")(1).toInt, o.split(",")(4).toFloat))
val ordersJoin = ordersCompletedMap.
join(orderItemsMap)
val ordersJoinMap = ordersJoin.
map(o => o._2)
val dailyRevenue = ordersJoinMap.
reduceByKey((agg, rev) => agg + rev)
val dailyRevenueSorted = dailyRevenue.
sortByKey()
val dailyRevenueSortedMap = dailyRevenueSorted.
map(o => o.productIterator.mkString(","))
dailyRevenueSortedMap.
saveAsTextFile("/user/training/daily_revenue")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment