Hope you are doing well.


It was great speaking to you.


Below is the code for word count.


CODE:

   

    import org.apache.spark.SparkContext
    import org.apache.spark.SparkConf

 

  object WordCount extends App{


   val sparkConf = new SparkConf().setAppName("NetworkWordCount").setMaster("local[2]")

   val lines= sc.textFile("file:///home/edureka/Desktop/file")

   val words = lines.flatMap(_.split(" "))
   val wordCounts = words.map(x => (x, 1)).reduceByKey(_ + _)

   wordCounts.print()

}


BUILD.sbt:


name := "WordCount"

version := "1.0"

scalaVersion := "2.11.7"

libraryDependencies += "org.apache.spark" %% "spark-core" % "1.5.2"

libraryDependencies += "org.apache.spark" %% "spark-sql" % "1.5.2"



Please try once on your side and let us know, if you face any further issue.


We will be glad assisting you.


 

Please share your feedback by clicking any of the below smileys.



Regards,

Kamini at Edureka

edureka! Support Team