Write a Word Count program using Scala language (Don't use Spark Core or SQL)

Live instructor-led & Self-paced Online Certification Training Courses (Big Data, Hadoop, Spark) Forums Apache Spark Write a Word Count program using Scala language (Don't use Spark Core or SQL)

Viewing 1 reply thread
  • Author
    Posts
    • #6480
      DataFlair Team
      Moderator

      Write a Word Count program using Scala language (Don’t use Spark Core or SQL)

    • #6481
      DataFlair Team
      Moderator

      WordCount program using scala language (Without using Spark-Core and SQL)

      val list = List(“Anish is working on BigData Technologies”,”Hello Anish”,”BigData”)
      val words = list.flatMap(line => line.split(” “))
      val keyData = words.map(word => (word,1))
      val groupedData = keyData.groupBy(_._1)
      val result = groupedData.mapValues(list=>{
      list.map(_._2).sum
      })
      result.foreach(println)

      Output:
      scala> result.foreach(println)
      (working,1)
      (BigData,2)
      (is,1)
      (Technologies,1)
      (Anish,2)
      (on,1)
      (Hello,1)

Viewing 1 reply thread
  • You must be logged in to reply to this topic.