Create a scala program
- Right click on scala -> new -> scala class
- Choose scala object and give the object name and hit enter
- Copy the code which we have seen earlier
- Pass the arguments as mentioned in the video
- Run the program
Example
import scala.io.Source object OrderRevenue { def main(args: Array[String]) = { val orderId = args(0).toInt val orderItems = Source.fromFile("/home/dgadiraju/data/retail_db/order_items/part-00000").getLines val orderRevenue = orderItems.filter(oi => oi.split(",")(1).toInt == orderId). map(oi => oi.split(",")(4).toFloat). reduce((t, v) => t + v) println(orderRevenue) } }