Created
May 26, 2017 05:15
-
-
Save dgadiraju/4f9c1c6860e9a123b2b1b24d4313c415 to your computer and use it in GitHub Desktop.
This file contains 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 path = "/public/retail_db" | |
val products = sc.textFile(path + "/products") | |
val minPricedProductsByCategory = products. | |
filter(product => product.split(",")(4) != ""). | |
map(product => { | |
val p = product.split(",") | |
(p(1).toInt, product) | |
}). | |
reduceByKey((agg, product) => { | |
if(agg.split(",")(4).toFloat < product.split(",")(4).toFloat) | |
agg | |
else | |
product | |
}). | |
map(rec => rec._2) | |
minPricedProductsByCategory.collect.foreach(println) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment