Advertisement
Guest User

Untitled

a guest
Mar 17th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. package spark;
  2.  
  3. import java.util.Arrays;
  4.  
  5. import org.apache.spark.SparkConf;
  6. import org.apache.spark.api.java.JavaSparkContext;
  7.  
  8. import scala.Tuple2;
  9.  
  10. public class WordCount_v0 {
  11.  
  12. public static void main(String[] args) {
  13. JavaSparkContext sc = new JavaSparkContext(new SparkConf().setAppName("WordCount-v0"));
  14. sc.textFile(args[0])
  15. .flatMap(s -> Arrays.asList(s.split(" ")))
  16. .mapToPair(s -> new Tuple2<String, Integer>(s, 1))
  17. .reduceByKey((x, y) -> x + y)
  18. .saveAsTextFile(args[1]);
  19. sc.close();
  20. }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement