[ Skip to the content ]

Institute of Formal and Applied Linguistics Wiki


[ Back to the navigation ]

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision Both sides next revision
spark:spark-introduction [2022/12/14 12:34]
straka [Word Count Example]
spark:spark-introduction [2022/12/14 12:36]
straka [Word Count Example]
Line 43: Line 43:
 The output of 'saveAsTextFile' is the directory ''output'' -- because the RDD can be distributed on several computers, the output is a directory containing possibly multiple files. The output of 'saveAsTextFile' is the directory ''output'' -- because the RDD can be distributed on several computers, the output is a directory containing possibly multiple files.
  
-Note that 'map' and 'reduceByKey' operations exist, allowing any Hadoop MapReduce operation to be implemented. On the other hand, several operations like 'join', 'sortBy', 'cogroup' are available, which are not available in Hadoop (or at least not directly), making Spark computational model a strict superset of Hadoop computational model.+Note that ''flatMap'' and ''reduceByKey'' operations exist, allowing any Hadoop MapReduce operation to be implemented. On the other hand, several operations like ''join'', ''sortBy'', ''cogroup'' are available, which are not available in Hadoop (or at least not directly), making Spark computational model a strict superset of Hadoop computational model.
  
 The Scala versions is quite similar: The Scala versions is quite similar:
 <file scala> <file scala>
-val wiki = sc.textFile("/net/projects/spark-example-data/wiki-cs")+val wiki = sc.textFile("/lnet/troja/data/npfl118/wiki/cs/wiki.txt")
 val words = wiki.flatMap(line => line.split("\\s")) val words = wiki.flatMap(line => line.split("\\s"))
-val counts = words.map(word => (word,1)).reduceByKey((c1,c2) => c1+c2)+val counts = words.map(word => (word, 1)).reduceByKey((c1, c2) => c1+c2)
 val sorted = counts.sortBy({case (word, count) => count}, ascending=false) val sorted = counts.sortBy({case (word, count) => count}, ascending=false)
 sorted.saveAsTextFile("output") sorted.saveAsTextFile("output")
  
 // Alternatively without variables and using placeholders in lambda parameters: // Alternatively without variables and using placeholders in lambda parameters:
-(sc.textFile("/net/projects/spark-example-data/wiki-cs")+(sc.textFile("/lnet/troja/data/npfl118/wiki/cs/wiki.txt")
    .flatMap(_.split("\\s"))    .flatMap(_.split("\\s"))
    .map((_,1)).reduceByKey(_+_)    .map((_,1)).reduceByKey(_+_)

[ Back to the navigation ] [ Back to the content ]