Last active
September 5, 2019 00:52
-
-
Save dgadiraju/a3dfeeb6787354035a4e2cff7815bce4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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