I need to run word count on an input file of upto a million lines in scala. Each line is very long (>150K characters) too. The following is the standard program that works:
val wordCount = scala.io.Source.fromFile("sample.dat")
.getLines
.flatMap(_.split("\\W+"))
.foldLeft(Map.empty[String, Int]){
(count, word) => count + (word -> (count.getOrElse(word, 0) + 1))
}
The below modification fails with the error, value par is not a member of Iterator[String]
val wordCount = scala.io.Source.fromFile("sample.dat")
.getLines
.flatMap(_.split("\\W+"))
.par
.foldLeft(Map.empty[String, Int]){
(count, word) => count + (word -> (count.getOrElse(word, 0) + 1))
}
I am surprised with this as similar programs seem to work.
Further, I am wondering if par.reduce would be a faster and more efficient than a working par.foldLeft.
Would be grateful for any help or leads on this issue.
TIA